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()
Â
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.