But the screenshot file is not saved. What is the likely problem?
medium
A. The capture option value is incorrect; it should be 'runner'.
B. The capture option 'viewport' is valid; the problem is elsewhere.
C. The cy.screenshot command must be chained after cy.get().
D. The file name must not have a dash ('-').
Solution
Step 1: Check the capture option values
Cypress supports 'viewport', 'runner', and 'fullPage' as valid values for capture. 'viewport' is valid.
Step 2: Review other options
File names can include dashes. cy.screenshot does not require chaining after cy.get(). So these are not issues.
Final Answer:
The capture option 'viewport' is valid; the problem is elsewhere. -> Option B
Quick Check:
Valid options mean issue is not in syntax [OK]
Hint: Check option values; 'viewport' is valid for capture [OK]
Common Mistakes:
Assuming 'viewport' is invalid
Thinking file names cannot have dashes
Believing chaining is mandatory
5. You want to take a screenshot only of a specific element with class .profile-pic and save it as 'profile.png'. Which code snippet correctly does this?
hard
A. cy.get('.profile-pic').screenshot('profile');
B. cy.screenshot('.profile-pic', { capture: 'element', fileName: 'profile.png' });
C. cy.get('.profile-pic').screenshot('profile.png.png');
D. cy.screenshot('profile.png', { element: '.profile-pic' });
Solution
Step 1: Understand element screenshot syntax
To screenshot a specific element, first select it with cy.get(), then call .screenshot() on that element. The argument is the file name without extension.
Step 2: Evaluate each option
cy.get('.profile-pic').screenshot('profile.png.png'); uses file name with extension, which is incorrect; Cypress adds extension automatically. cy.screenshot('.profile-pic', { capture: 'element', fileName: 'profile.png' }); uses invalid syntax; cy.screenshot does not accept selector as first argument. cy.get('.profile-pic').screenshot('profile'); correctly selects element and calls .screenshot('profile'). cy.screenshot('profile.png', { element: '.profile-pic' }); uses invalid options.
Final Answer:
cy.get('.profile-pic').screenshot('profile'); -> Option A
Quick Check:
Element screenshot = get element then .screenshot(name) [OK]
Hint: Select element first, then call .screenshot with name (no extension) [OK]
Common Mistakes:
Passing file extension in screenshot name
Calling cy.screenshot with selector argument
Using invalid options for element capture
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.