0
0
Testing Fundamentalstesting~10 mins

Request and response validation in Testing Fundamentals - Interactive Code Practice

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

Complete the code to check if the response status code is 200.

Testing Fundamentals
assert response.status_code == [1]
Drag options to blanks, or click blank then click option'
A302
B500
C404
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 instead of 200
Checking status_code as a string instead of integer
2fill in blank
medium

Complete the code to verify the response JSON contains the key 'success'.

Testing Fundamentals
assert 'success' [1] response.json()
Drag options to blanks, or click blank then click option'
Ain
B!=
Cnot in
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'in'
Using 'not in' which checks absence
3fill in blank
hard

Fix the error in the assertion to check the response time is less than 500 milliseconds.

Testing Fundamentals
assert response.elapsed.total_seconds() * 1000 [1] 500
Drag options to blanks, or click blank then click option'
A>
B<
C>=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which means greater than
Using '==' which checks equality
4fill in blank
hard

Complete the code to extract the 'data' field from the JSON response and check it is a list.

Testing Fundamentals
data = response.json()'data'
assert isinstance(data, [1])
Drag options to blanks, or click blank then click option'
A[
Blist
C]
Ddict
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of brackets
Checking type against 'dict' instead of 'list'
5fill in blank
hard

Fill all three blanks to create a test that asserts the response JSON has a 'status' key with value 'ok'.

Testing Fundamentals
json_data = response.json()
assert [1] and json_data[2] [3] 'ok'
Drag options to blanks, or click blank then click option'
A.get('status')
B'status' in json_data
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for value check
Not checking if key exists before accessing