Executing test cases on several operating systems and several browsers is a major requirement for an effective UI test. To ensure that the objects are identified correctly on different browser and OS versions, it is necessary that the UI object identification is accurate. The RanoreXPath enables accurate recognition and filtering of UI elements.

execution-parameter-console

The source directory of the application under test, or the web application URL for a web test, may change on test machines and servers. For that reason, it is helpful to set execution parameters before starting test scripts on the test machine.

In this article I would like to show how to add parameters for the following scenarios:

Setting source directory parameter for application under test

I am going to define my application under test with the “aut” parameter for my test case. After deploying my test case executable (generated with Ranorex Studio) onto the test machine, I would like to start my test case as follows:

myTest.exe /aut "C:Program Files (x86)My ApplicationAUT.exe"

Add code snippet to your Main method in Program.cs file of your project

Following code snippet enables you to read arguments from the command line:

// Set default source file
string aut = @"C:Program FilesMy ApplicationAUT.exe";

for (int i = 0; i < args.Length-1; i++)
{
	if (args[i] == "/aut")
		aut = args[i+1];
}

Since it is possible to define multiple parameters, I use a for loop to search for the “aut” argument. The variable “aut” is set to the string specified as the next argument. We can now use “aut” string to start our application under test:

System.Diagnostics.Process.Start(aut);

Setting URL for web applications

The location of a web application may change on test environments (e.g. localhost). Depending on the identification of your web application in the repository, you may also also have to adopt the RanoreXPath for the DOM object.

myTest.exe /url "http://www.ranorex.com/web-testing-examples/"

As described in the previous example, the following snippet will enable you to read the parameter in your test script:

// Set default web application URL
string url = "http://www.ranorex.com/web-testing-examples/";

for (int i = 0; i < args.Length-1; i++)
{
	if (args[i] == "/url")
		url = args[i+1];
}

If you identify your web application by the “@url” attribute in your RanoreXPath, you will need to update this attribute with the new URL, i.e. change the “BasePath” property of the corresponding Ranorex Repository entry. The following code will set the “BasePath” for the web application repository item named “WebPage” in the  “GlobalRepository” and start the browser with the specified URL:

try
{
	// Adopt the new URL for the DOM element
	GlobalRepository.Instance.WebPage.BasePath = "/dom[@pageurl='" + url + "']";

	// Start test in Internet Explorer with specified URL
	System.Diagnostics.Process.Start("iexplore.exe", url);
	StartTest();
	...
}

Conclusion

Defining execution parameters helps you to set attributes right on your test machine without having to open Ranorex Studio and regenerate your test case.

You might also like these articles