0
0
Selenium Pythontesting~20 mins

Cloud testing platforms (BrowserStack, Sauce Labs) in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cloud Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this BrowserStack Selenium test snippet?
Consider this Python Selenium code snippet configured to run on BrowserStack. What will be printed after execution?
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By

caps = {
    'browserName': 'Chrome',
    'browserVersion': 'latest',
    'bstack:options': {
        'os': 'Windows',
        'osVersion': '11',
        'projectName': 'Sample Project'
    }
}

url = 'https://hub-cloud.browserstack.com/wd/hub'

options = webdriver.ChromeOptions()
options.set_capability('bstack:options', caps['bstack:options'])
options.set_capability('browserName', caps['browserName'])
options.set_capability('browserVersion', caps['browserVersion'])

# Normally username and access key are required, but omitted here for simplicity

driver = webdriver.Remote(
    command_executor=url,
    options=options
)

driver.get('https://example.com')
heading = driver.find_element(By.TAG_NAME, 'h1').text
print(heading)
driver.quit()
AEmpty string
BNoSuchElementException error
CSyntaxError
DExample Domain
Attempts:
2 left
💡 Hint
Think about what the main heading on https://example.com is.
assertion
intermediate
2:00remaining
Which assertion correctly verifies Sauce Labs test status?
You want to assert that a Sauce Labs test session has passed by checking the session status via their REST API. Which Python assertion is correct?
Selenium Python
import requests

session_id = 'abc123'
url = f'https://saucelabs.com/rest/v1/user/jobs/{session_id}'
response = requests.get(url, auth=('username', 'access_key'))
data = response.json()

# Which assertion below correctly checks the test passed?
Aassert data['consolidated_status'] == 'passed'
Bassert data['status'] == 'passed'
Cassert data['passed'] is True
Dassert data['result'] == 'success'
Attempts:
2 left
💡 Hint
Check Sauce Labs API documentation for the correct status field name.
locator
advanced
2:00remaining
Which locator is best for cross-browser cloud testing?
When writing Selenium tests to run on cloud platforms like BrowserStack and Sauce Labs, which locator strategy is most reliable across different browsers and screen sizes?
ABy.CSS_SELECTOR with complex nested selectors
BBy.CLASS_NAME with common class names
CBy.ID with unique element IDs
DBy.XPATH with absolute paths starting from /html/body
Attempts:
2 left
💡 Hint
Think about stability and uniqueness of locators across browsers.
🔧 Debug
advanced
2:00remaining
Why does this BrowserStack test fail to start?
This Python Selenium code snippet fails with a timeout error when trying to start a BrowserStack session. What is the most likely cause?
Selenium Python
from selenium import webdriver

caps = {
    'browserName': 'Firefox',
    'browserVersion': 'latest',
    'bstack:options': {
        'os': 'OS X',
        'osVersion': 'Big Sur'
    }
}

url = 'https://hub-cloud.browserstack.com/wd/hub'

options = webdriver.FirefoxOptions()
options.set_capability('bstack:options', caps['bstack:options'])
options.set_capability('browserName', caps['browserName'])
options.set_capability('browserVersion', caps['browserVersion'])

driver = webdriver.Remote(
    command_executor=url,
    options=options
)

driver.get('https://example.com')
AIncorrect browser version string format
BMissing BrowserStack username and access key in the URL
CUsing FirefoxOptions instead of ChromeOptions
DInvalid OS version name
Attempts:
2 left
💡 Hint
Check how authentication is handled in BrowserStack remote URLs.
framework
expert
2:00remaining
Which test framework feature best supports parallel cloud testing?
You want to run Selenium tests in parallel on Sauce Labs to speed up execution. Which feature of pytest best supports this?
Apytest-xdist plugin with multiple workers
Bpytest-mock plugin for mocking web elements
Cpytest-html plugin for generating reports
Dpytest-cov plugin for measuring code coverage
Attempts:
2 left
💡 Hint
Think about running tests simultaneously.