Skip to main content

selenium-python examples

References:

1. https://selenium-python.readthedocs.io/getting-started.html
2. https://github.com/hossainmtuhin/selenium-python
3.


** seleniumExample.py **

from selenium import webdriver
from selenium.webdriver.common.keys import Keys


driver = webdriver.Chrome("D://Tuhin_Backup//software_//automation_//selenium webdriver tools//chromedriver_win32//chromedriver.exe")

driver.get("https://google.com")

assert "Google" in driver.title

element = driver.find_element_by_name('q')

element.clear()

element.send_keys('test')

element.send_keys(Keys.RETURN)

assert "No results found." not in driver.page_source

driver.close()



** seleniumExampleWithUnittest.py **

import unittest

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class GoogleSearch(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome("D://Tuhin_Backup//software_//automation_//selenium webdriver tools//chromedriver_win32//chromedriver.exe")


    def test_search_in_googl(self):
        driver = self.driver
        driver.get("https://google.com") 
        self.assertIn("Google", driver.title)
        element = driver.find_element_by_name("q")
        element.send_keys("test")
        element.send_keys(Keys.RETURN)
     
        assert "No results found." not in driver.page_source


    def tearDown(self):
        self.driver.close()


if __name__ == "__main__":
    unittest.main(verbosity=2)







Comments

Popular posts from this blog

Usages of TestNG Annotations on the Automation Framework

Before explaining the difference, first this is some testing terminologies Test suite – Consists of one or more test tags. Test tag - Consists of one or more test classes. Test class – Consists of one or more methods. for examble: <suite name="suit1"> <test name="TestTag1"> <classes> <class name="TestClass1"/> </classes> </test> <test name="TestTag2"> <classes> <class name="TestClass2"/> <class name="TestClass3"/> </classes> </test> </suite> @BeforeTest : It will be called Only one time before any test tag, no matter how many test classes inside that tag or how many method annotated with @Test , it will be called only one time for each test tag,in the previous XML example @BeforeTest will be called twice, one time before TestTag1 the second time before TestTag2 so it can be used to in...

Install and configure WSL2 (ubuntu distro), npm, git and project on Windows

  For Installation information please visit:  https://docs.microsoft.com/en-us/windows/wsl/install-win10 1.Configure WSL 2  After installation search for %UserProfile% in the local machine. check if there is any .wslconfig file. If there is no .wslconfig file create one with this content depends on the available resource. [wsl2] memory=8GB swap=0 processors=4 Install windows Terminal Application and check if everything is configured properly. 2.Configuring NodeJS on WSL npm install 3.Configuring Git and project  To install git, in a wsl terminal, we run sudo apt update && sudo apt upgrade   sudo apt install git To set up your Git config file, open a command line for the distribution you're working in and set your name with this command (replacing "Your Name" with your Git username): git config --global user.name "Your Name" Set your email with this command (replacing "youremail@ domain.com " wi...

Maven integration for Eclipse + Creating simple maven project in eclipse

Note: In updated eclipse, maven is installed automatically. So, at first, try the "Finally" section at the bottom of this post. maven is the build tool for web application automation testing. It helps to get the dependencies we need, at the same time, build the project using a continuous Integration (CI) server.  Use jenkins as CI server.  Use cucumber use java Use Test Driven Development (TDD) https://www.youtube.com/watch?v=8bZvevzeq-o&index=6&list=PLTgRMOcmRb3OHE_z8n9uCpROTaynNcv1u Maven Eclipse plugin installation step by step: Open Eclipse IDE Click Help -> Install New Software... Click Add button at top right corner At pop up: fill up Name as "M2Eclipse" and Location as " http://download.eclipse.org/technology/m2e/releases " Now click OK After that installation would be started. # Another way to install Maven plug-in for Eclipse: (easiest one) Open Eclipse Go to Help -> Eclipse Marketplace Se...