Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the file name.
Using variable names instead of string literals.
✗ Incorrect
The file name must be a string literal, so it needs quotes.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the key without quotes causing a compile error.
Using wrong key names.
✗ Incorrect
JSON keys must be passed as strings with quotes.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of string keys.
Missing quotes causing runtime errors.
✗ Incorrect
The key to get the JSON array must be a string literal with quotes.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for index.
Using incorrect or missing quotes for JSON keys.
✗ Incorrect
Use the loop index 'i' to get each JSONObject and the key "email" to get the email string.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing keys and values in wrong places.
Forgetting quotes around string keys and values.
✗ Incorrect
Use the key "username" for both put key and getString key, and assert the expected value "testUser".