Challenge - 5 Problems
JSON Test Data Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of parsing this JSON string in Java?
Given the following JSON string and Java code snippet using org.json library, what will be the output printed?
Selenium Java
String jsonString = "{\"name\": \"Alice\", \"age\": 30, \"active\": true}"; JSONObject obj = new JSONObject(jsonString); System.out.println(obj.getString("name") + ", " + obj.getInt("age") + ", " + obj.getBoolean("active"));
Attempts:
2 left
💡 Hint
Remember to match the JSON keys with the correct getter methods.
✗ Incorrect
The JSON string contains keys 'name', 'age', and 'active' with values 'Alice', 30, and true respectively. The code correctly retrieves these values and prints them in order.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the 'status' field in JSON response?
You receive a JSON response: {"status":"success","code":200}. Which JUnit assertion correctly checks that the 'status' field equals 'success'?
Attempts:
2 left
💡 Hint
Check the data type of the 'status' field in JSON.
✗ Incorrect
The 'status' field is a string with value 'success'. Option C correctly asserts this. Other options either use wrong data types or wrong assertions.
❓ locator
advanced2:00remaining
Identify the best locator to find a JSON data-driven test element
You have a web page that dynamically loads test data from JSON into elements with data-test-id attributes. Which Selenium locator is best to find the element with data-test-id='user-123'?
Attempts:
2 left
💡 Hint
Use attribute selectors for custom data attributes.
✗ Incorrect
The best locator uses CSS selector for the attribute data-test-id with value 'user-123'. Option D works but is less efficient. Options A and D do not match the attribute.
🔧 Debug
advanced2:00remaining
Why does this JSON parsing code throw an exception?
Consider this Java code snippet:
String jsonString = "{\"id\": 101, \"name\": null}";
JSONObject obj = new JSONObject(jsonString);
String name = obj.getString("name");
Why does obj.getString("name") throw an exception?
Selenium Java
String jsonString = "{\"id\": 101, \"name\": null}"; JSONObject obj = new JSONObject(jsonString); String name = obj.getString("name");
Attempts:
2 left
💡 Hint
Check how org.json handles null values in JSON objects.
✗ Incorrect
The 'name' key exists but its value is null. org.json's getString method throws JSONException if the value is null. To avoid this, use optString or check for null.
❓ framework
expert3:00remaining
How to integrate JSON test data with Selenium tests in Java?
Which approach best integrates external JSON test data into Selenium Java tests for data-driven testing?
Attempts:
2 left
💡 Hint
Consider maintainability and separation of test data from test code.
✗ Incorrect
Option B is best practice: external JSON files parsed by libraries like Jackson or Gson, then used with TestNG DataProvider for clean, maintainable data-driven tests. Other options are inefficient or error-prone.