Based on various forum discussions, the TestCafe documentation, and trying it out to compare results, I am still not certain which is the correct (or best) way to assert that a page element is visible.
await t.expect(Selector('#elementId').visible).ok();
vs
await t.expect(await Selector('#elementId').visible).ok();
Or are these both incorrect and there is another way that is preferable? How does this compare to asserting that an element exists? Or other properties of the element, such as :checked?
Wait Mechanism for SelectorsWhen TestCafe executes a Selector query, it waits for the target element to appear in the DOM. The query fails if it cannot find the target within the Selector timeout. The target element doesn't have to be visible for the Selector to succeed.
To construct assertions, use the test controller's expect method. The t. expect method is followed by an assertion method that accepts an expected value and optional arguments.
If the DOM tab is active, the assertion examines a page element that corresponds to an element selector; If the fn tab is active, the assertion examines the return value of a client function. Pick the target element with the element picker. TestCafe Studio generates a set of selectors for the target element.
To check is element visible or not in Testcafe let’s try a below simple line of code. IsElementExist checks the elements are available or not into the dom object of the page. IsElementVisible Checks the elements are visible or on the web page.
TestCafe Studio generates a set of selectors for the target element. To view available selectors, click the button next to the Element Selector input field. The element picker is available only during recording. Use the element selector creation dialog. Select the property you want to include in the comparison from the Verified Property dropdown.
For example, the following assertion verifies if the number of label elements on a tested page is equal to 9: The Deep Equal assertion takes into account whitespace characters like newline symbols or tabulations when it compares strings.
Actually, both variants are possible. Nevertheless, it is better to use the first one because the second variant may raise errors at the stage of obtaining the Element State:
Smart Assertion Query Mechanism
Or other properties of the element, such as :checked
You can obtain the Element State and use its checked option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With