Course Content
Selenium Python First Script
Selenium Python First Script
0/2
HTML Form elements
HTML Form elements
0/1
Handle HTML Frames
Handle HTML Frames
0/2
Handling Dropdown Lists
Handling Dropdown Lists
0/2
Selenium Action class
Selenium Action class
0/1
Selenium Python for Beginners [ 2024 ]
About Lesson

Running test on Selenium Grid

Now it’s time to write tests and run them on the Selenium Grid environment. Selenium Grid allows you to distribute your tests across multiple browsers and machines in parallel.

Test Code

# Google Homepage Test Example
# www.TestingDocs.com 

import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By


class GoogleTest(unittest.TestCase): 
    
    def setUp(self):
        remote_url = "http://localhost:4444/wd/hub"
        options=webdriver.ChromeOptions()
        options.set_capability("browserName", "chrome")

        self.driver = webdriver.Remote(command_executor=remote_url,
                          options=options)
        
        
    def test_title(self):
        driver=self.driver 
        driver.get("https://google.com")
        driver.implicitly_wait(60)
        search_box = driver.find_element(By.NAME, "q")
        search_box.send_keys("test")
        search_button = driver.find_element(By.NAME, "btnK")
        search_button.click()
        self.assertIn("test", driver.title)
        
    def tearDown(self):
        self.driver.quit()
        
            
if __name__ == '__main__': 
    unittest.main()

 

Run Test on Selenium Grid

Before running the remote test, ensure the hub and nodes are up and running without any issues.

Explanation

The script creates a Remote WebDriver capable of running tests on remote machines. It passes the details of the hub and the information of the node.

Execute your test script. The test request will be sent to the hub, which will then distribute it to the matched available node.

Join the conversation