- Documentation
- Quick Start Guide
- Selenium Grid Configuration
- Auto Scaling
- Spot Instance Nodes
- Selenium Grid Integration
- Pre Launch API Integration
- Selenium V4 Grid Code Examples
- Selenium V2/V3 Grid Code Examples
- Performance Testing
Selenium Grid Python Code Example
Selenium Grid 4 Python code example
NOTE: To run these examples as is, get a free Gridlastic account and replace USERNAME:ACCESS_KEY@HUB_SUBDOMAIN and VIDEO_URL parameters with your own credentials found in your Gridlastic dashboard after launching your selenium grid.
Single Python test
from selenium import webdriver
import time
chrome_options = webdriver.ChromeOptions()
chrome_options.set_capability("browserVersion", "latest")
chrome_options.set_capability("platformName", "win10")
gridlastic_options = {}
gridlastic_options['video'] = 'true'
chrome_options.set_capability('gridlastic:options', gridlastic_options)
driver = webdriver.Remote(
command_executor='https://USERNAME:ACCESS_KEY@HUB_SUBDOMAIN.gridlastic.com/wd/hub',
options=chrome_options
)
print ("Video: " + "VIDEO_URL" + driver.session_id)
try:
driver.implicitly_wait(30)
driver.maximize_window()
driver.get("http://www.python.org")
assert "Python" in driver.title
time.sleep(5) # pause for demo purposes
finally:
driver.quit()
NOTE: Gridlastic auto scaling requires all 3 test environment parameters platform, browser and browser version to be specified in each request in order to launch test nodes to fulfill test demand. Video recording is optional. See test environments for capabilities options.
It is important to ensure that "driver.quit()" is always called for proper test execution and creation of video recordings of failed tests.
Try our
SELENIUM GRID DEMO