This guide describes how you can test a user interface (UI) using custom JavaScript in a browser test. JavaScript assertions support synchronous and asynchronous code.
To create an assertion using custom JavaScript:
Click Assertion and select Test custom JavaScript assertion.
Your browser test results include console.error logs, with a maximum of 4 logs allowed per JavaScript function. Consider combining the logs for improved clarity and efficiency.
Assert that a radio button is checked
To verify that a radio button is checked, use return document.querySelector("<SELECTORS>").checked === true; in the body assertion.
Set the value of a specified local storage item
To set the value of a specified local storage item, add the following in the body assertion:
localStorage.setItem(keyName,keyValue);returntrue
For example, to set the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC to “mytime”: