0
0
Selenium Javatesting~10 mins

JSON test data in Selenium Java - Interactive Code Practice

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

Complete the code to read JSON test data from a file.

Selenium Java
JSONObject jsonObject = new JSONObject(new JSONTokener(new FileReader([1])));
Drag options to blanks, or click blank then click option'
AjsonObject
Bdata.json
C"data.json"
DFileReader
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the file name.
Using variable names instead of string literals.
2fill in blank
medium

Complete the code to extract a value from JSON test data.

Selenium Java
String username = jsonObject.getString([1]);
Drag options to blanks, or click blank then click option'
A"username"
Busername
Cuser
DgetString
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the key without quotes causing a compile error.
Using wrong key names.
3fill in blank
hard

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

Selenium Java
JSONArray users = jsonObject.getJSONArray([1]);
Drag options to blanks, or click blank then click option'
Ausers
BgetJSONArray
CuserList
D"users"
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of string keys.
Missing quotes causing runtime errors.
4fill in blank
hard

Fill both blanks to loop through JSON array and get each user's email.

Selenium Java
for (int i = 0; i < users.length(); i++) {
    JSONObject user = users.getJSONObject([1]);
    String email = user.getString([2]);
}
Drag options to blanks, or click blank then click option'
Ai
B"email"
C"userEmail"
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for index.
Using incorrect or missing quotes for JSON keys.
5fill in blank
hard

Fill all three blanks to create a test data map from JSON keys and values.

Selenium Java
Map<String, String> testData = new HashMap<>();
testData.put([1], jsonObject.getString([2]));
assertEquals([3], testData.get("username"));
Drag options to blanks, or click blank then click option'
A"username"
C"testUser"
D"password"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing keys and values in wrong places.
Forgetting quotes around string keys and values.