In this section:

Introduction

The Selenium Executor tool enables you to execute Selenium tests in conjunction with the various other types of tests you can run with SOAtest. It automatically sets up the dependencies required for the test by providing JUnit the necessary WebDriver libraries. This enables you to design and execute a single test scenario that orchestrates Selenium tests as part of a broader sequence of events, such as setting up a test environment or test data, running unit tests via this tool, then executing mobile tests.

Requirements

  • Selenium 2.44 is supported
  • JUnit 3.8.x or JUnit 4
  • This tool requires SOAtest 9.8.1 or later

Installation

You can install this tool from the UI or from the command line.

UI Installation

  1. Choose Parasoft> Preferences from the main menu.
  2. Choose the Syster Properties tab and click Add JARs.
  3. Brows for the seleniumexecutor.jar file and click Apply.
  4. Restart SOAtest.

Command Line Installation

Add the seleniumexecutor.jar file to the system.properties.classpath property in your settings.properties file. For example:

system.properties.classpath=<path to jar>/seleniumexecutor.jar 

Usage

Selenium Executor tools can be added as standalone tools via the Add Test wizard. The test's class folder or jar file must contain the JUnit that you want executed. Other dependencies can be included in the jar/folder, added to the system properties, or both. The tool looks at the jar/folder first, then the system properties (if needed).

Configuration

The tool uses a system property to provide the path to the IEDriverServer.exe and chromedriver.exe shipped with SOAtest. By default, Selenium will automatically read and use this system property. Alternatively, the JUnit tests can manually override these settings using the following system properties:

  • webdriver.ie.driver - path to IEDriverServer.exe
  • webdriver.chrome.driver - path to chromedriver.exe

You can configure the following tool fields:

FieldDescriptionRequired
Jar or Class Folder

Specify the test's class folder or jar file. 

Required
ClassSpecify which Selenium class from the given jar or class folder to run.Optional
MethodSpecify which Selenium method to run. Leave this empty if you want to run all test methods in the specified class.Optional
Data

Specify any data values you want to dynamically change in the JUnit. The field supports semicolon-separated key/value pairs, e.g.:

firstName=John;lastName=Doe 

These variables can be accessed from within your JUnit source code using Java's System Properties object, for example:

string lastName = System.getProperty("lastName") 

Optional

Example

The following example demonstrates how to configure the tool to run all tests methods in a class:

Viewing Results

Execution details and results will be reported in the Console view. Additionally, any test failures detected will be reported in the Quality Tasks view:

Reporting Messages from JUnit Test to Console

Import the com.parasoft.api package into your project to access the Application Context, which enables SOAtest to report messages from your Selenium test execution to the console:

Application.showMessage("this displays in the console");

  Add <SOATEST_INSTALL>/plugins/com.parasoft.ptest.libs.web_<version>/root/com.parasoft.api.jar to your Java project classpath to import the resource.

Retrieving Data from a JUnit Test

You can attach a SOAtest output to the Selenium Executor to retrieve data from your Selenium JUnit test output so that the data can be used in other tests. You need to configure the Selenium to indicate which values you want stored, and then attach an appropriate tool to the Selenium Output of the executor tool. The data will be passed to the attached tool in XML format. For example, you could send the data to a Diff tool, XML Assertor, or XML Data Bank tool.

Configuring the JUnit Output

Your JUnit must access the application context and store the desired values in a standard Java Map under the custom_tool_junit_output key. The Selenium Executor tool will check the application context for the stored map and convert it to XML that gets passed to the tool's "JUnit Output" output. The map's keys and values must be strings.

Import the com.parasoft.api package into your Selenium as described in Reporting Messages from Selenium Test to Console to access the Application Context.

Sending the Data to Another Tool

To send the output data from your JUnit test to a tool that processes XML data:

  1. Right-click the Selenium Executor and choose Add Output.
  2. Choose a tool for receiving the output and click Finish.

Example

In this example, we will store the account balance in an XML Data Bank so that the values can be used in a subsequent test. The following procedure will occur:

  1. The JUnit test constructs a map containing the values
  2. The map is placed into the application context.
  3. The values in the map will be converted into an XML document that is passed to any tools attached to the Selenium Output
public void testParabank() throws Exception {
	driver = new FirefoxDriver();
	
	// Navigate and log in to page
	driver.get("http://parabank.parasoft.com");
	driver.findElements(By.className("input")).get(0).sendKeys("john");
	driver.findElements(By.className("input")).get(1).sendKeys("demo");
	driver.findElements(By.className("login")).get(2).submit();

	// Extract desired value
	String accountBalance = driver.findElementByXPath("//*[@id=\"accountTable\"]/tbody/tr[1]/td[2]").getText();

	// Create map representing name-value pairs for XML
	Map<String, String> map = new HashMap<String, String>();

	// Place extracted value into map
	map.put("accountBalance", accountBalance);

	// Get the Parasoft Scripting Context
	ScriptingContext context = Application.getContext();

	// Place the map in the context with the custom_tool_junit_output
	context.put("custom_tool_junit_output", map);
	}

Add a Selenium Executor tool configured to run this test and add an XML Data Bank tool to the Selenium output.

Specify which values to extract and use in other tools. The content of the map appears below the <root> element within the XML document that is passed to the tools attached to the Selenium output. In this example, a value assertion tool was added.

Third-party Content

This plug-in includes items that have been sourced from third parties as outlined below.

Additional license details are available in this plugin's licenses folder.


  • No labels