Appearance
I.see()
Asserts that a text or element is visible on the page.
I.see() automatically waits for up to 15 seconds for the target to appear and become visible. This timeout can be configured using TEST.commandTimeout. If the target is not visible by the end of the timeout, the assertion fails and the test is marked as failed.
Visibility checks ensure that the target is visible to the user, and not merely present in the DOM. A target is considered not visible if:
- its
displayCSS property is set tonone - its
visibilityCSS property is set tohidden - its
opacityCSS property is set to0 - its bounding box is completely offscreen
Usage
js
I.see(target: string)Parameters
| Parameter | Type | Description |
|---|---|---|
target | string | Text or element (by visible text, CSS selector, or XPath) to find |
Returns
Returns a boolean value indicating whether the target is found or not
Variants
I.see() also has the following variants:
I.must.see(): fails and stops the test immediately if the assertion failsI.see$(): returns a boolean result without failing the test (used for conditional flows)I.see.hint(): marks the matched target as a hint for resolving nearby elements in subsequent steps
Examples
Using I.see to assert visibility
js
I.click("Log in")
I.see("Dashboard")
I.see(".profile-picture")In the example above, the test asserts that the text "Dashboard" and the ".profile-picture" element appears after a successful login.
Using I.must.see to stop tests early
js
I.click("Log in")
I.must.see("Dashboard") // stops the test if it fails
I.see(".profile-picture")In the example above, the test asserts that the text "Dashboard" after a successful login. If the text is not visible after the timeout, the assertion fails and the test is stopped, skipping the subsequent steps.
Using I.see$ for conditional flows
js
if (I.see$("Out of stock")) {
TEST.stop()
}
I.click("Add to cart")In the example above, the test checks if the text "Out of stock" appears on the page and stops the test if so.
Using I.see.hint for targeting
js
I.see.hint("Cherry Tomatoes")
// This clicks the "Add to cart" nearest to "Cherry Tomatoes"
I.click("Add to Cart")In the example above, the test clicks the "Add to Cart" button that is nearest to the text occurrence of "Cherry Tomatoes".