0
0
Selenium Pythontesting~10 mins

Running tests on Grid in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test runs a simple Selenium test on a Selenium Grid. It opens a browser on a remote node, navigates to a page, clicks a button, and verifies the result.

Test Code - Selenium
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Setup remote WebDriver to connect to Selenium Grid hub
remote_url = "http://localhost:4444/wd/hub"
capabilities = {
    "browserName": "chrome",
    "platformName": "ANY"
}
driver = webdriver.Remote(command_executor=remote_url, desired_capabilities=capabilities)

try:
    driver.get("https://example.com")
    
    # Wait until the button is clickable
    wait = WebDriverWait(driver, 10)
    button = wait.until(EC.element_to_be_clickable((By.ID, "start-button")))
    button.click()

    # Verify the result text appears
    result = wait.until(EC.visibility_of_element_located((By.ID, "result-text")))
    assert result.text == "Test Passed", f"Expected 'Test Passed' but got '{result.text}'"

finally:
    driver.quit()
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Create Remote WebDriver session connecting to Selenium Grid hub at http://localhost:4444/wd/hub with Chrome capabilitiesRemote browser node is allocated and ready-PASS
2Navigate browser to https://example.comBrowser displays the example.com homepage-PASS
3Wait up to 10 seconds for button with ID 'start-button' to be clickableButton is visible and enabled on the pageButton is clickablePASS
4Click the 'start-button'Button click triggers page update-PASS
5Wait up to 10 seconds for element with ID 'result-text' to be visibleResult text appears on the pageResult text is visiblePASS
6Assert that the result text equals 'Test Passed'Text content is 'Test Passed'result.text == 'Test Passed'PASS
7Quit the remote WebDriver sessionBrowser session closed on remote node-PASS
Failure Scenario
Failing Condition: The button with ID 'start-button' is not found or not clickable within 10 seconds
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test do first after creating the Remote WebDriver session?
ANavigate to https://example.com
BClick the start button
CAssert the result text
DQuit the browser session
Key Result
When running tests on Selenium Grid, always use explicit waits like WebDriverWait to handle dynamic page elements on remote browsers. This ensures your test is stable and does not fail due to timing issues.