0
0
Selenium Pythontesting~10 mins

Cloud testing platforms (BrowserStack, Sauce Labs) in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web page using BrowserStack cloud platform with Selenium in Python. It verifies the page title to confirm the correct page loaded.

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
import unittest

class BrowserStackTest(unittest.TestCase):
    def setUp(self):
        desired_cap = {
            'browserName': 'Chrome',
            'browserVersion': 'latest',
            'bstack:options': {
                'os': 'Windows',
                'osVersion': '11',
                'local': False,
                'seleniumVersion': '4.8.0'
            }
        }
        self.driver = webdriver.Remote(
            command_executor='https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub',
            desired_capabilities=desired_cap
        )

    def test_page_title(self):
        self.driver.get('https://example.com')
        WebDriverWait(self.driver, 10).until(
            EC.title_contains('Example Domain')
        )
        self.assertEqual(self.driver.title, 'Example Domain')

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and sets up remote WebDriver with BrowserStack capabilitiesRemote WebDriver session is created on BrowserStack cloud with Windows 11 and Chrome latest-PASS
2Browser opens and navigates to 'https://example.com'Browser window on cloud platform loads the Example Domain page-PASS
3Waits until page title contains 'Example Domain'Page title is 'Example Domain'Title contains 'Example Domain'PASS
4Asserts that page title equals 'Example Domain'Page title is exactly 'Example Domain'self.assertEqual(driver.title, 'Example Domain')PASS
5Test tears down and closes the remote browser sessionBrowser session on BrowserStack is closed-PASS
Failure Scenario
Failing Condition: If the page title does not match 'Example Domain' within 10 seconds
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after opening the page on BrowserStack?
AThe page title is 'Example Domain'
BThe page URL contains 'browserstack'
CThe browser version is Chrome 90
DThe page has a login form
Key Result
Using cloud testing platforms like BrowserStack allows running tests on real browsers and OS combinations remotely, ensuring wider coverage without managing local infrastructure.