0
0
Selenium Pythontesting~10 mins

Reading test data from JSON in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load JSON data from a file.

Selenium Python
import json
with open('data.json', '[1]') as file:
    data = json.load(file)
Drag options to blanks, or click blank then click option'
Aa
Bw
Cr
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using write mode ('w') instead of read mode.
Using append mode ('a') which is for adding data.
2fill in blank
medium

Complete the code to access the 'username' field from loaded JSON data.

Selenium Python
username = data[1]'username'
Drag options to blanks, or click blank then click option'
A<
B(
C{
D[
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets.
Using curly braces which define dictionaries, not access keys.
3fill in blank
hard

Fix the error in the code to correctly parse JSON string data.

Selenium Python
import json
json_string = '{"key": "value"}'
data = json.[1](json_string)
Drag options to blanks, or click blank then click option'
Adumps
Bloads
Cdump
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using json.load() on a string instead of a file.
Using json.dumps() which converts Python objects to JSON strings.
4fill in blank
hard

Fill both blanks to read JSON data and extract the 'password' field.

Selenium Python
with open('config.json', '[1]') as f:
    config = json.[2](f)
password = config['password']
Drag options to blanks, or click blank then click option'
Ar
Bw
Cload
Dloads
Attempts:
3 left
💡 Hint
Common Mistakes
Opening the file in write mode.
Using json.loads() on a file object.
5fill in blank
hard

Fill all three blanks to load JSON data, access 'email', and assert it equals expected value.

Selenium Python
with open('user.json', '[1]') as file:
    user_data = json.[2](file)
assert user_data['email'] [3] 'test@example.com'
Drag options to blanks, or click blank then click option'
Ar
Bload
C==
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Opening file in write mode.
Using json.loads() on a file object.
Using '=' instead of '==' in assert.