Write a Test

This tutorial uses the same HTML and JSON as the Hello World tutorial to explain the basics of writing a test with UTAM code.

The UTAM compiler transforms the JSON page object into runnable code. The type declaration contains the methods you can call from test code. You can see this code in the top-right panel. In this case, the method is getWorld().

The test code in the bottom-left panel calls the method.

First, import a root page object using JavaScript module syntax. In this case, the page object is helloWorld.utam.json, and its namespace is tutorial: tutorial/helloWorld. You can use any name to refer to the default export from the module. This code uses HelloWorldRoot.

Then call utam.load() to load the page object.

Now you can call page object methods on helloWorldRoot.

The test calls getWorld() to get the element with the .world class. Right now, the element is a span, but if you changed it to a div, the code would still work.

From the element, the test calls getText(), which is a UTAM basic action. It then asserts that the element contains the three emojis that we expect.

Click Run Test.

Tip: You can write code directly in the Test Runner panel. Use any Node.js assertions. Add a debugger statement to invoke the Developer Tools debugger and step through your code. You can also call console.log() to output a message to the console.