Advanced web testing
In this chapter, we’ll cover some advanced topics regarding web testing.
Use the Wait for action to wait until an element has loaded
Loading times that take longer than usual are a common issue in web tests. They can cause tests to fail and can get quite annoying, as they are often outside of the tester’s control. One way to work around these loading times is by instructing the test to wait until a certain element has loaded. In Ranorex Studio, you can easily do so with the Wait for action.
In the action table, add a Wait for action after an action that loads a web page and before an action that manipulates an element on the loaded page.
The repository item that the action waits for to exist.
Instead of the Wait for action, you can also use the Delay action to pause your test run.
However, the Delay action always pauses the test run for the specified time, regardless of an element existing or not. This is why you should use the Wait for action if there is a repository item you can sensibly link it to. This way, your test won’t idle unnecessarily.
Use the Invoke action to wait until entire pages have loaded (Make this a h2 again if we reuse it)
The action Invoke action has a property called WaitForDocumentLoaded that can be linked to repository items representing web pages. This will cause Ranorex Studio to wait until the entire web page has loaded with a timeout as specified in the action’s properties.
First you need to…
Use the Set value action to enter values more robustly
Entering values like text strings in web forms is a common scenario in web tests. This can either be accomplished by simulating the keypresses on a keyboard (Key sequence action) or by directly setting the form to a specific value. The latter is usually more robust because no mouse clicks or similar are required, so there is less potential for failure. Conversely, this can cause the test to miss certain defects because you deviate farther from a true user experience.
In our example, we’ll enter a name in the sample form on the Ranorex test website. The process is as follows:
Enter the name in the text field of the form.
Click Submit to submit the name.
The page that appears as a result.
What it looks like in the action table
Repository item Testname that represents the text field.
The value is set directly in the form without any mouse clicks or typing.
Use the Get value action to read out values for use in the test
It’s often useful or necessary to read out values on websites (numbers, strings, etc.) and use them further along in the test. The simplest way to do this is with the Get value action.
In our example, we’ll read out a list value to reuse it in the sample form on the Ranorex test website.
With the default values selected, clicking the Submit button produces the following result:
Colors/testmultiple is set to green and yellow.
- get the value blue from the testmultiple parameter and
- set the testcolor parameter to this read-out value.
What it looks like in the action table
The Set value action uses the value of the variable $Color and sets the field Color/testcolor to it.
The resulting page will look like this:
The field testcolor now has the value blue, as set by the Set value action.
The testmultiple field is still set to the default values. The Get value action only reads out the value blue.
The WebDocument Adapter creates a representation of the complete website including all tags (e.g. the header tag, body tag, etc.). Furthermore it offers useful ways to make your test scripts more effective.
The following sample shows how to use these features:
Find or filter web elements
The Ranorex Framework offers a wide range of adapters for each HTML tag elements (e.g.: ATag adapter for <a> tags). Each adapter has specific methods and attributes; the link tag (<a>) for example has additional attributes like HREF, TARGET and REL.
Repositories and the WebDocument
The following example shows how to access the methods of the WebDocument using a repository: