Welcome to the new Ranorex Support Portal

Advanced web testing

In this chapter, we’ll cover some advanced topics regarding web testing.

In this chapter

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.

  1. 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.

  1. Wait for action with 10s waiting time. The action waits until the linked repository item exists. This should be the repository item that is manipulated in the following action.

  2. The repository item that the action waits for to exist.

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.

Test situation

In our example, we’ll enter a name in the sample form on the Ranorex test website. The process is as follows:

  1. Enter the name in the text field of the form.

  2. Click Submit to submit the name.

  3. The page that appears as a result.

     

What it looks like in the action table

  1. Set value action that enters the name in the text field.

  2. Repository item Testname that represents the text field.

Result

The value is set directly in the form without any mouse clicks or typing.

Download

Reference


For more details on the Set value action, refer to

Ranorex Studio fundamentals > Actions > ⇢ Action properties.

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.

Test situation

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:

  1. Color/testcolor is set to green.

  2. Colors/testmultiple is set to green and yellow.

We’ll now

  • 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

  1. The Get value action reads out the value blue from the Colors field and passes it to the variable $Color.

  2. The Set value action uses the value of the variable $Color and sets the field Color/testcolor to it.

Result

The resulting page will look like this:

  1. The field testcolor now has the value blue, as set by the Set value action.

  2. The testmultiple field is still set to the default values. The Get value action only reads out the value blue.

Download

Reference


For more details on the Get value action, refer to

Ranorex Studio fundamentals > Actions > ⇢ Action properties.

WebDocument Adapter


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:

C#

// Identify a web document by its title
WebDocument webDocument = "/dom[@caption='Ranorex Test Page']";
// Open a website
webDocument.Navigate("https://support.ranorex.com");
// Wait until the document is loaded
webDocument.WaitForDocumentLoaded();
// Execute a javascript code
webDocument.ExecuteScript("history.back();");

VB.NET

' Identify a web document by its title
Dim webDocument As WebDocument = "/dom[@caption='Ranorex Test Page']"
' Open a website
webDocument.Navigate("https://support.ranorex.com")
' Wait until the document is loaded
webDocument.WaitForDocumentLoaded()
' Execute a javascript code
webDocument.ExecuteScript("history.back();")

Find or filter web elements


The Ranorex Framework offers a wide range of adapters for each HTML tag elements (e.g.: ATag adapter for tags). Each adapter has specific methods and attributes; the link tag () for example has additional attributes like HREF, TARGET and REL.

C#

// Start IE with a specific website
System.Diagnostics.Process.Start("iexplore.exe", "/web-testing-examples");
// Identify the webdocument by its title
WebDocument webDocument = "/dom[@caption='Ranorex Test Page']";
// Find a link by its link text (innertext)
ATag link = webDocument.FindSingle(".//a[@innertext='simple link']");
link.Click();

VB.NET

' Start IE with a specific website
System.Diagnostics.Process.Start("iexplore.exe", "/web-testing-examples")
' Identify the webdocument by its title
Dim webDocument As WebDocument = "/dom[@caption='Ranorex Test Page']"
' Find a link by its link text (innertext)
Dim link As ATag = webDocument.FindSingle(".//a[@innertext='simple link']")
link.Click()

Repositories and the WebDocument


The following example shows how to access the methods of the WebDocument using a repository:

C#

// Load repository
ProjectRepository repo = ProjectRepository.Instance;
// Open a website
repo.WebPage.Self.Navigate("https://support.ranorex.com");
// Wait until the document is loaded
repo.WebPage.Self.WaitForDocumentLoaded();

VB.NET

' Load repository
Dim repo As ProjectRepository = ProjectRepository.Instance
' Open a website
repo.WebPage.Self.Navigate("https://support.ranorex.com")
' Wait until the document is loaded
repo.WebPage.Self.WaitForDocumentLoaded()

USERS LOVE US

SUBSCRIBE TO OUR NEWSLETTER

Get the latest test automation information right in your mailbox.

FOLLOW US

© 2024 Ranorex GmbH. All Rights Reserved