0
0
Selenium Pythontesting~20 mins

Reading test data from JSON in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSON Test Data Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of reading JSON test data in Selenium Python
What will be the output of the following code snippet that reads test data from a JSON file and prints the username?
Selenium Python
import json
with open('testdata.json', 'r') as file:
    data = json.load(file)
print(data['user']['username'])
Aadmin_user
BKeyError
CTypeError
DFileNotFoundError
Attempts:
2 left
💡 Hint
Check the JSON structure and the key used to access the username.
assertion
intermediate
2:00remaining
Correct assertion for JSON test data in Selenium Python
Which assertion correctly verifies that the password read from JSON test data equals 'pass123'?
Selenium Python
import json
with open('testdata.json', 'r') as file:
    data = json.load(file)
password = data['user']['password']
Aassert password = 'pass123'
BassertEqual(password, 'pass123')
Cassert password == 'pass123'
Dassert password != 'pass123'
Attempts:
2 left
💡 Hint
Remember the correct syntax for assertions in Python.
locator
advanced
2:00remaining
Best locator to use with JSON test data for Selenium Python
Given JSON test data contains a field 'login_button_id' with value 'btnLogin'. Which locator is best to find the login button in Selenium Python?
Selenium Python
login_button_id = data['login_button_id']
Adriver.find_element(By.NAME, login_button_id)
Bdriver.find_element(By.CLASS_NAME, login_button_id)
Cdriver.find_element(By.XPATH, login_button_id)
Ddriver.find_element(By.ID, login_button_id)
Attempts:
2 left
💡 Hint
Consider the type of locator that matches an element's id attribute.
🔧 Debug
advanced
2:00remaining
Identify the error when reading JSON test data
What error will this code raise if the JSON file is empty or malformed? import json with open('testdata.json', 'r') as file: data = json.load(file) print(data)
AFileNotFoundError
Bjson.decoder.JSONDecodeError
CKeyError
DTypeError
Attempts:
2 left
💡 Hint
Think about what happens when json.load tries to parse invalid JSON.
framework
expert
3:00remaining
Best practice for integrating JSON test data in Selenium Python tests
Which approach best integrates JSON test data into Selenium Python tests for maintainability and reusability?
ALoad JSON data once in a fixture or setup method and pass it to test functions
BRead the JSON file inside every test function separately
CUse global variables to store JSON data and access them anywhere
DHardcode test data inside test functions instead of JSON
Attempts:
2 left
💡 Hint
Think about avoiding repeated file reads and keeping tests clean.