Web Testing

The Ranorex Web Plugins (for Microsoft Internet Explorer and Mozilla Firefox) allow you to test the UI of web applications in the same way you would automate standard desktop applications.

Architecture of Websites in the Ranorex Framework

Ranorex is able to access the complete HTML architecture of a web document. Use the Ranorex Spy to analyze the structure and the content of a web application and to see which information is accessible during automation.

All open websites are shown as a single Dom node in the spy tree. In addition to standard browser hosted applications, Ranorex is able to see embedded browser objects too (e.g. compiled help files). Additional each tab item within a browser window is presented as a separate Dom node within the spy tree.

The web document and its HTML structure can be identified using RanoreXPath. Similar to XPath in HTML, the RanoreXPath provides a simple search mechanism for finding single or multiple web elements within a web page.

WebDocument Adapter

The WebDocument Adapter creates a representation of the complete web-site 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("http://www.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("http://www.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 <a> tags). Each adapter has specific methods and attributes; the link tag (<a>) for example has additional attributes like HREF, TARGET and REL.

C#

// Start IE with a specific website
System.Diagnostics.Process.Start("iexplore.exe",  "www.ranorex.com/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", "www.ranorex.com/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()

Testing within Mozilla Firefox

During the installation of Ranorex software the setup package automatically installs a Mozilla Firefox addin, which enables the communication between the Ranorex Firefox Plugin and the Firefox browser. If you install Mozilla Firefox after installing Ranorex, please run the Ranorex setup again; in the setup dialog choose "Change" and enable the "Ranorex Firefox Extension".

Creating tests for Firefox does not differ to creating tests for Internet Explorer. All web UI elements are specified through RanoreXPath, which uses HTML attributes and values for identification. For this reason a single web repository can be used for testing both types of web browsers. Learn more about how to test multiple browsers with a test case based on one single repository introduced by our web testing example project, which is part of the Ranorex setup package.

Automation of browser specific elements (e.g. Popup window)

Handling of browser specific UI controls requires a separate RanoreXPath for each browser specific element. That means if you would like to click on a Popup dialog in Internet Explorer and Firefox as well, you will have to add a separate repository item for each dialog.

The Ranorex Automation library provides you with a property called "BrowserName" which tells you the current browser of the web site under test:

C#

// Click on the OK button in the pop up dialog of the Internet Explorer or Firefox
// If the current browser is Internet Explorer
if(webDocument.BrowserName == "IE")
{
	Button okIE = "/form[@processname~'(iexplore|IEXPLORE)' and @class='#32770']/button[@text='OK']";
	okIE.Click();
}
// If the current browser is Mozilla Firefox
else if(webDocument.BrowserName == "Mozilla")
{
	Button okFF = "/form[@class='MozillaDialogClass']//button[@accessiblename='OK']";
	okFF.Click();
}

VB.NET

' Click on the OK button in the pop up dialog of the Internet Explorer or Firefox
' If the current browser is Internet Explorer
If webDocument.BrowserName = "IE" Then
	Dim okIE As Button = "/form[@processname~'(iexplore|IEXPLORE)' and @class='#32770']/button[@text='OK']"
	okIE.Click()
' If the current browser is Mozilla Firefox
ElseIf webDocument.BrowserName = "Mozilla" Then
	Dim okFF As Button = "/form[@class='MozillaDialogClass']//button[@accessiblename='OK']"
	okFF.Click()
End If

Recordings & Repositories

Ranorex Recorder provides the same capture and replay functionality, which is used for standard client desktop applications. The recorder automatically creates action items for each recorded user action within the Recorder's actions table. The corresponding repository contains all required UI web element objects for used within the actions table.

Repositories and the WebDocument

The following example shows hot to acces the methods of the WebDocument using a repository:

C#

// Load repository
ProjectRepository repo = ProjectRepository.Instance;
// Open a website
repo.WebPage.Self.Navigate("http://www.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("http://www.ranorex.com")
' Wait until the document is loaded  
repo.WebPage.Self.WaitForDocumentLoaded()