Run Appium scripts remotely using StormRunner Functional

This article describes how to set up your Appium environment and run tests remotely in the SRF environment lab.

Prepare your Appium environment

To prepare your environment to run an automated Appium test, you must first configure your working environment, such as Visual Studio or Eclipse, to recognize the Appium project.

Prepare your Appium test

Do the following to prepare your Appium test to run remotely in SRF:

1. In the code the starts the session, replace the Appium server URL and port with the SRF URL and port.

Use the following syntax:

driver = new AndroidDriver(new URL("https://ftaas.saas.hpe.com:443" + "/wd/hub"), capabilities);
driver = new IOSDriver(new URL("https://ftaas.saas.hpe.com:443" + "/wd/hub"), capabilities);

2. In the code that starts the session, add your SRF client ID and secret as capability code.

3. capabilities.SetCapability("SRF_CLIENT_ID", "<placeholder>");
capabilities.SetCapability("SRF_CLIENT_SECRET", "<placeholder>");

3. Make your apps available for the test by uploading them to SRF.

4. Modify your code for deprecated elements and methods

Beginning with version 1.6.3, Appium deprecated the following items:

By.name element for findElement. Make sure to modify your code accordingly.
scrollTo and scrollToExactmethods. Instead, use a driver. execute command, for example,
driver.execute('mobile: scroll', {element: el, toVisible: true})

5. Continue with Run your test.

Run your test

Run your test using the relevant steps for your testing tool:

Run your Appium test in Eclipse

To run your Appium test in Eclipse:

1. Open your project in Eclipse. Set the Appium capabilities as needed, including the server and device information.

2. Launch the test. Check the Eclipse console to ensure that your test is running properly.

Run your Appium test with Apache Ant

To run your Appium test with Ant:

1. Download and install Apache Ant, and set the required environment variables.

2. Open a command dialog box and navigate to your Appium workspace path.

3. Run the command ant <test_name>.java to start running your test.

Check the Ant console to ensure that your test is running properly.

Run a single job project in Jenkins

To run your Appium test as a Jenkins job: (Terminology refers to Jenkins 2.00 and higher):

1. Download and install Apache Ant, and set the relevant environment variables.

2. Open the Jenkins dashboard and click New item.

3. Specify an Item name and click Freestyle project.

4. In the General tab, click Advanced.

5. Select Use custom workspace and enter your Appium workspace path.

6. In the Build section, select Invoke ant.

7. Click the Advanced button. Provide a target name and the full path to the build.xml file in the Build Filefield.

8. Click Save.

9. On the project page, click Build Now.

Run a MultiJob project in Jenkins

To run multiple Appium tests as a Jenkins job: (Terminology refers to Jenkins 2.00 and higher):

1. Prepare several single job freestyle jobs.

2. Click New item and specify a MultiJob project.

3. In the Build section, select MultiJob Phase from the Add build step drop down. Enter a phase name.

4. Click Add jobs and select the first job you want to add. Repeat this step for all of the jobs you want to include in this phase.

5. Select an option from the Job execution type drop down: sequentially or in parallel.

If you are executing multiple jobs, but only have one device, the jobs will be executed sequentially—not in parallel.

6. Optionally, select a continuation condition, for example: Always, Successful, or Completed.

7. On the project page, click Build Now.

Tip: The udid, name, and platformVersion capabilities are optional. You can use the platformNamecapability alone, to instruct the Appium test to look for the next available device.

As your test runs, the device is locked and reserved by you in the SRF mobile lab.

The running tests icon in the upper right corner of SRF indicates that your test is running.

Retrieve Appium logs

A log file is generated while your Appium test runs.

To retrieve the log, use the mc-wd:downloadLogs script and specify the encoding.

When the connector receives this command, it retrieves the contents of the Appium log file for the current testing session, as a string. Attach the string to the response body.

The Appium user’s test code uses the string from the response body and processes it accordingly.

For example:

HashMap<String, String> encoding= new HashMap<String, String>();

encoding.put(“encoding”, “UTF-8”);

String logFileContents = (String) wd.executeScript(“mc-wd: downloadLogs”, encoding);

Advertisements

Run Selenium tests remotely using StormRunner Functional

This article describes how to run Selenium tests in SRF, remotely from your remote web driver.

SRF supports remote testing from Selenium in all languages supported by Selenium, including Java, C#, JavaScript, Python, Ruby, and more.

Run Selenium tests remotely: basic steps

Run your Selenium tests from your remote web driver as follows:

1. Add code to your tests to access SRF and to define your environment.

2. Add capability code to your tests to define SRF such as test tags, or the names displayed in test results, as well as environment settings.

3. Run your Selenium tests remotely in SRF using your remote web driver as you would other Selenium tests.

Run Selenium jUnit tests in Firefox

If you are running your jUnit test in Firefox, remotely in SRF, use the following firefox profile API:

FirefoxProfile firefoxProfile = new FirefoxProfile();

Run Selenium tests with enhanced reports

SRF reporters are available for several types of Selenium tests.

Select an option to modify the information displayed on this page:

Run JavaScript Selenium tests with enhanced reports

To run a JavaScript Selenium test with enhanced reports using SRF’s reporter, do the following:

a. Install the reporter: https://www.npmjs.com/package/srf.reporter.mocha

b. Add the SRF_REPORTER_URL environment variable, and its value with the URL to your SRF tenant.

For example, https://ftaas.saas.hpe.com, or https://ftaas-eu1.saas.hpe.com, depending on your tenant region.

Tip: Alternately, pass the srfUrl reporter option from the command line.

3. Add and define the following environment variables:

SRF client ID and secret o SRF_CLIENT_ID

o SRF_CLIENT_SECRET

Proxy server If you are running the reporter from behind a firewall, define the following:

o HTTP_PROXY

o HTTPS_PROXY

Note: When running your test, be sure to assign the client secret value to the SRF_CLIENT_SECRETenvironment variable.

4. Use one of the following commands when running your test:

Using the SRF_REPORTER_URL environment variable

For example:

mocha test-name.js –reporter srf.reporter.mocha

Using the srfURL reporter option

For example:

mocha test-name.js –reporter srf.reporter.mocha –reporter-options srfUrl=https://ftaas.saas.hpe.com

Run Ruby tests remotely with enhanced reports

To use this feature, contact customer support to obtain the Ruby Selenium reporter.

Then, do the following to run a Ruby Selenium tests with enhanced reports:

1. Install the SRF reporter by running the following command:

gem install srfrubyreporter

2. Open and edit your Gemfile, and add the following line:

gem ‘srfreport’

3. Open and edit your *.rb file, and add the following line:

require ‘srfreport’

4. Continue with one of the following options:

o Run your Ruby test remotely from the command line

o Run your Ruby test using a remote driver

Run your Ruby test remotely from the command line

a. Add the following line to your *.rb file:

Capybara.default_driver = :srf_driver

b. Run your test from the command line with the following parameters, or define these as environment variables on your machine.

Name Value
SRF_REPORTER_URL The URL to your SRF tenant.

For example: https://ftaas.hpe.com or https://ftaas-eu1.saas.hpe.com/wd/hub, depending on your region.

SRF_CLIENT_ID

SRF_CLIENT_SECRET

Your SRF client ID and secret values.
TEST_NAME The path to your test and your test name.

For example: “MyAdvantageRubyTest”

OS_NAME The operating system you want to use to run your test.
OS_VERSION The operating system version you want to use to run your test.
BROWSER_NAME The name of the browser you want to use to run your test.
BROWSER_VERSION The browser version you want to use to run your test.

c. For example:

d. bundle exec cucumber SRF_REPORTER_URL= https://ftaas.saas.hpe.com SRF_CLIENT_ID=<placeholder> SRF_CLIENT_SECRET=<placeholder> TEST_NAME=”MyAdvantageRubyTest” BROWSER_NAME=chrome BROWSER_VERSION=65 OS_NAME=Windows OS_VERSION=10

Run your Ruby test using a remote driver

Run your Ruby test remotely using your own remote driver as follows:

1. Edit your test to include the following:

o Capability code as needed.

o The SRF_CLIENT_ID and SRF_CLIENT_SECRET values as environment variables.

For example:

Capybara.register_driver :my_driver do |app|
 caps = Selenium::WebDriver::Remote::Capabilities.chrome(
 :platform => "Windows 10",
 :testName => "MyAdvantageRubyTest",
 :browser_name =>"chrome",
 :version => "65",
 :SRF_CLIENT_SECRET => ENV['<placeholder>'],
 :SRF_CLIENT_ID => ENV['<placeholder>']
 )
 driver = Capybara::Selenium::Driver.new(app, :browser => :remote, :url => ENV['SRF_REPORTER_URL'] + "/wd/hub", :desired_capabilities => caps)
 driver
end
Capybara.default_driver = :my_driver

2. Run your test from the command line, including the following parameters:

SRF_REPORTER_URL The URL to your SRF tenant.

For example: https://ftaas.hpe.com or https://ftaas-eu1.saas.hpe.com, depending on your tenant region.

SRF_CLIENT_ID

SRF_CLIENT_SECRET

Your SRF client ID and secret values.

3. For example:

4. bundle exec cucumber SRF_REPORTER_URL= https://ftaas.saas.hpe.com SRF_CLIENT_ID=YOUR_CLIENT_ID SRF_CLIENT_SECRET=YOUR_CLIENT_SECRET

Run Java tests remotely with enhanced reports

To use this feature, contact customer support to obtain the Java Selenium reporter (srfRunner.jar).

Then, do the following to run a Java Selenium tests with enhanced reports:

1. Save the srfRunner.jar file on the computer where you are running your test.

o Use the file with dependencies if you want all libraries downloaded together.

o Use the file without dependencies if you already have required libraries stored locally, or can access them ad-hoc when running your test.

2. Update your test to define the relevant classes, options, and variables.

3. Run your Java test as you would otherwise.

Selenium code samples for remote testing

Selenium Java code sample

Prerequisites. Before running these code samples, replace the sample SRF_CLIENT_ID and SRF_CLIENT_SECRET values with your own SRF client secret values. If needed, update the SRF URL value to match that of your tenant region.

Sample without proxy

package DEMO.Selenium;
import static org.junit.Assert.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
publicclassOnlineShopping
{
 private static RemoteWebDriver driver;
 static DesiredCapabilities capabilities = DesiredCapabilities.chrome();

@BeforeClass
public static void openBrowser() throws MalformedURLException{
 capabilities.setVersion("latest");
 capabilities.setCapability("platform", "Windows 8.1");
 capabilities.setCapability("testName","Selenium Burst JAVA - Online Shopping");
 capabilities.setCapability("SRF_CLIENT_ID", "<placeholder>");
 capabilities.setCapability("SRF_CLIENT_SECRET", System.getenv("SRF CLIENT SECRET"));
 capabilities.setCapability("resolution", "800x600");

 driver = new RemoteWebDriver(
 new URL("https://ftaas.saas.hpe.com/wd/hub/"), capabilities);
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);}

@Test
public void OnlineShoppingE2E() throws InterruptedException{
 Actions builder = new Actions(driver);
 driver.get("http://advantageonlineshopping.com/#");
 driver.findElement(By.xpath("//DIV[@id=\"mobileSearch\"]/INPUT[1]")).sendKeys("speakers"); //Search edit
 driver.findElement(By.cssSelector("#mobileSearch > #Layer_1")).click(); //Search button
 WebElement addToCartElement = driver.findElement(By.linkText("Bose Soundlink Bluetooth Speaker III"));
 builder.click(addToCartElement).build().perform();
 driver.findElement(By.xpath("//DIV[@id=\"productProperties\"]/DIV/BUTTON[normalize-space()=\"ADD TO CART\"]")).click(); //Add to cart button
 driver.findElement(By.xpath("//HEADER[1]/NAV[1]/UL[1]/LI[1]/A[1]")).click(); //Cart Icon
 assertEquals(driver.findElement(By.cssSelector("div#shoppingCart > table > tfoot > tr:nth-child(1) > td:nth-child(2) > span:nth-child(2)")).getText(), "$269.99"); //Checking item price
}

@AfterClass
public static void closeBrowser(){
 driver.quit();
}
}

Sample with proxy

package com.microfocus.srf.pock;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.internal.ApacheHttpClient;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
importjava.util.HashMap;

public class FinalDocumentationExample
 {private WebDriver driver;
 @Before
 public void openBrowser() throws MalformedURLException {
DesiredCapabilities capability = DesiredCapabilities.chrome();
 capability.setCapability("version","latest");
 capability.setCapability("SRF_CLIENT_ID","<placeholder>");
 capability.setCapability("SRF_CLIENT_SECRET", System.getenv("SRF CLIENT SECRET"));
 capability.setCapability("platform","windows 7");
 URL srfUrl =new URL("https","ftaas.saas.hpe.com",443,"/wd/hub/");

 System.out.println("Creating remote web driver with address: "+ srfUrl);

 HttpCommandExecutor executor =new HttpCommandExecutor(new HashMap<String, CommandInfo>(), srfUrl,new HttpClient.Factory()
 public HttpClient createClient(URL url){
 HttpClientBuilder builder = HttpClientBuilder.create();
 HttpHost driverProxy =new HttpHost("<proxy host placeholder>",<proxy port placeholder>);
 builder.setProxy(driverProxy);
 return new ApacheHttpClient(builder.build(), url);
 }
 });
 driver =new RemoteWebDriver(executor, capability);
}
@After
public void closeBrowser() throws IOException {
 driver.quit();
}
@Test
public void pageTitleAfterSearchShouldBeginWithDrupal() throws IOException, InterruptedException {
 driver.manage().window().maximize();
 driver.get("http://www.google.com/");//type search query
 driver.findElement(By.name("q")).sendKeys("qa automation\n");// click search
 driver.findElement(By.name("btnG")).click();}}

Selenium JavaScript code sample

Prerequisites. Before running this code sample:

1. Install the following components on your machine:

o Node JS (https://nodejs.org)

o Mocha (https://www.npmjs.com/package/mocha)

· Selenium-webdriver (https://www.npmjs.com/package/selenium-webdriver)

2. Replace the sample SRF_CLIENT_ID and SRF_CLIENT_SECRET values with your own SRF client values.

3. If needed, update the SRF URL value to match that of your tenant region.

4. If you are working behind a firewall, uncomment the proxy code and add your proxy access details.

var webdriver = require('selenium-webdriver'),
proxy = require('selenium-webdriver/proxy');
By = webdriver.By,
until = webdriver.until;
var assert = require('selenium-webdriver/testing/assert');
var driver;
describe('DEMO Online Shopping Selenium', function () {
 this.timeout(60000);
 before(function(done){
 var capabilities = {
 platform: "Windows 8.1",
 browserName: "chrome",
 //version: "58",//Instead of specific version number you can specify latest version:
 version: "latest",
 testName: "Demo_Burst_Test_Selenium_JS",
 resolution: "800x600",
 //NOTE: Web AUT which is tested in this test changes it's UI elements dependents on resolution, in case if you will use higher resolution test will fail//Supported resolutions are: 800x600; 1024X768; 1280X1024
 SRF_CLIENT_ID: "<placeholder>",
 SRF_CLIENT_SECRET: process.env.SRF_CLIENT_SECRET
 };
 driver = new webdriver
 .Builder()
 .withCapabilities(capabilities)
 .usingServer("https://ftaas.saas.hpe.com/wd/hub/")
 //.setProxy(proxy.manual({""}))
 .build();
 driver.get('http://advantageonlineshopping.com/#').then(function() {
 console.log("open Online Shopping web page");
 done();
 });
 });

 it('should search required category', function (done) {
 driver
 .wait(until.elementLocated(By.xpath("//DIV[@id=\"mobileSearch\"]/INPUT[1]"), 5000))
 .then(function(searchFieldElement){
 searchFieldElement.sendKeys("speakers");
 })
 .then(()=>driver.findElement(By.css("#mobileSearch > #Layer_1")).click())
 .then(done);
});

it('should click on "Bose Soundlink Bluetooth Speaker III" in list of founded items', function (done) {
 var element = driver.findElement({partialLinkText:"Bose Soundlink Bluetooth Speaker III", tagName:'LI'});
 driver
 .actions()
 .click(element)
 .perform();
 done();
});

it('should add item into the cart',function(done){
 driver
 .wait(until.elementLocated(By.xpath("//DIV[@id=\"productProperties\"]/DIV/BUTTON[normalize-space()=\"ADD TO CART\"]"), 5000))
 .then(function(){
 driver
 .findElement(By.xpath("//DIV[@id=\"productProperties\"]/DIV/BUTTON[normalize-space()=\"ADD TO CART\"]"))
 .click()
 .then(done);
 });
});

it('should click on cart icon',function(done){
 driver
 .findElement(By.xpath("//HEADER[1]/NAV[1]/UL[1]/LI[1]/A[1]"))
 .click()
 .then(done);
 });

 it('should check item price',function(done){
 var itemPrice = driver.findElement(By.css("div#shoppingCart > table > tfoot > tr:nth-child(1) > td:nth-child(2) > span:nth-child(2)"));
 itemPrice
 .getText()
 .then(function(elementText){
 assert(elementText).equals("$269.99");
 })
 .then(done);
 });

 it('should click on checkout button',function(done){
 driver
 .findElement(By.xpath("//DIV[@id=\"shoppingCart\"]/TABLE[1]/TFOOT[1]/TR[2]/TD[1]/BUTTON[1]"))
 .click()
 .then(done);
 });

 it('should fill existing user details',function(done){
 driver
 .findElement(By.xpath("//DIV[@id=\"orderPayment\"]/DIV[1]/DIV[1]/DIV[1]/SEC-FORM[1]/SEC-VIEW[1]/DIV[1]/LABEL[1]"))
 .click()
 .then(
 driver
 .findElement(By.xpath("//DIV[@id=\"orderPayment\"]/DIV[1]/DIV[1]/DIV[1]/SEC-FORM[1]/SEC-VIEW[1]/DIV[1]/INPUT[1]"))
 .sendKeys("SRF_DEMO")
 .then(
 driver
 .findElement(By.xpath("//DIV[@id=\"orderPayment\"]/DIV[1]/DIV[1]/DIV[1]/SEC-FORM[1]/SEC-VIEW[2]/DIV[1]/LABEL[1]"))
 .click()
 .then(
 driver
 .findElement(By.xpath("//DIV[@id=\"orderPayment\"]/DIV[1]/DIV[1]/DIV[1]/SEC-FORM[1]/SEC-VIEW[2]/DIV[1]/INPUT[1]"))
 .sendKeys("<password>")
 .then(done)
 )));
 });

 it('should click login button',function(done){
 driver
 .findElement(By.xpath("//DIV[@id=\"orderPayment\"]/DIV[1]/DIV[1]/DIV[1]/SEC-FORM[1]/SEC-SENDER[1]/A[1]"))
 .click()
 .then(done);
 });

 it('should check total price',function(done){
 var totalPrice = driver.findElement(By.css("div#userCart > div:nth-child(5) > label:nth-child(2) > span"));
 totalPrice
 .getText()
 .then(function(elementText){
 assert(elementText).equals("$269.99");
 })
 .then(done);
 });

 it('should click next button',function(done){
 driver
 .findElement(By.xpath("//DIV[@id=\"userSection\"]/DIV/DIV/BUTTON[normalize-space()=\"NEXT\"]"))
 .click()
 .then(done);
 });

 it('should specify user details for buying items',function(done){

 driver
 .findElement(By.xpath("//DIV/SEC-FORM/SEC-VIEW/DIV/LABEL[normalize-space()=\"SafePay username\"]"))
 .click()
 .then(
 driver
 .findElement(By.css("div#paymentMethod > div > div:nth-child(3) > sec-form > sec-view:nth-child(1) > div > input"))
 .sendKeys('testTest')
 .then(
 driver
 .findElement(By.xpath("//DIV/SEC-FORM/SEC-VIEW/DIV/LABEL[normalize-space()=\"SafePay password\"]"))
 .click()
 .then(
 driver
 .findElement(By.css("div#paymentMethod > div > div:nth-child(3) > sec-form > sec-view:nth-child(2) > div > input"))
 .sendKeys('testTEST1234')
 .then(done)
 )));
 });

 it('should uncheck checkbox "save cahnges to profile"',function(done){
 driver
 .findElement(By.xpath("//DIV[2]/SEC-FORM[1]/DIV[1]/INPUT[1]"))
 .isSelected()
 .then(function(elementSelectedState){
 if (elementSelectedState)
 driver
 .findElement(By.xpath("//DIV[2]/SEC-FORM[1]/DIV[1]/INPUT[1]"))
 .click()
 .then(done);
 });
 });

 it('should click on "Pay now" button',function(done){
 driver
 .findElement(By.xpath("//DIV[2]/SEC-FORM[1]/DIV[2]/LABEL[1]/SEC-SENDER[1]/A[1]"))
 .click()
 .then(done);
 });

 it('should check price in order details',function(done){

 var totalPrice = driver.findElement(By.css("div#orderPaymentSuccess > div > div:nth-child(3) > div:nth-child(4) > label > a"));
 totalPrice
 .getText()
 .then(function(elementText){
 assert(elementText).equals("$269.99");
 })
 .then(done);
 });

 after(function(done){
 driver.quit().then(done);
 });
});

Selenium C# code sample

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Configuration;
using System;
using OpenQA.Selenium.Remote;
using System.Threading;
using OpenQA.Selenium.Interactions;
using NUnit.Framework;
namespace SeleniumExample
{
 public static class WebElementExtensions
 {
 public static bool ElementIsPresent(this IWebDriver driver, By by)
 {
 var present = false;
 try
 {
 present = driver.FindElement(by).Displayed;
 }
 catch (NoSuchElementException)
 {
 }
 return present;
 }
 }
 [TestFixture, Category("Selenium_C#")]public class DEMO_Online_Shopping
 {
 DesiredCapabilities dc;
 RemoteWebDriver driver;
 [OneTimeSetUp]
 public void Init()
 {
 dc = DesiredCapabilities.Chrome();
 dc.SetCapability("platform", "Windows 8.1");
 dc.SetCapability("testName", "Selenium Burst C# - Online Shopping");
 dc.SetCapability(CapabilityType.Version, Environment.GetEnvironmentVariable("SRF_Browser_Version"));
 dc.SetCapability("resolution", "800x600");
 dc.SetCapability("SRF_CLIENT_ID", "<placeholder>");
 dc.SetCapability("SRF_CLIENT_SECRET", "<placeholder>");
 driver = new RemoteWebDriver(new Uri("https://ftaas.saas.hpe.com/wd/hub/"), dc);
  //driver = new ChromeDriver();
 }
 [Test]public void Demo_Online_Shopping()
 {
 Actions builder = new Actions(driver);
 driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 0, 10)); // 10 seconds for searching objects
 driver.Navigate().GoToUrl("http://advantageonlineshopping.com/#");
 driver.FindElement(By.XPath("//DIV[@id=\"mobileSearch\"]/INPUT[1]")).SendKeys("speakers");  //Search edit
 driver.FindElement(By.CssSelector("#mobileSearch > #Layer_1")).Click(); //Search button
 IWebElement addToCartElement = driver.FindElement(By.LinkText("Bose Soundlink Bluetooth Speaker III"));
 builder.Click(addToCartElement).Build().Perform();
 driver.FindElement(By.XPath("//DIV[@id=\"productProperties\"]/DIV/BUTTON[normalize-space()=\"ADD TO CART\"]")).Click(); //Add to cart button
 driver.FindElement(By.XPath("//HEADER[1]/NAV[1]/UL[1]/LI[1]/A[1]")).Click(); //Cart Icon
 Assert.AreEqual(driver.FindElement(By.CssSelector("div#shoppingCart > table > tfoot > tr:nth-child(1) > td:nth-child(2) > span:nth-child(2)")).Text, "$269.99"); //Checking item price
 }
 [OneTimeTearDown]public void TearDown()
 {
 driver.Quit();
 }
 }
}

Record and run LeanFT tests remotely using StormRunner Functional

This article describes how to record and run your LeanFT test remotely in your SRF lab.

Configure the connection to SRF

To configure the connection from LeanFT to SRF:

1. On the SRF settings page, generate a client ID and secret to use when accessing SRF.

2. In LeanFT, open your LeanFT Runtime Engine Settings dialog box, and select the Labs tab.

Define your SRF settings under StormRunner Functional Settings.

 

Define your settings as follows:

Server address The URL of your SRF tenant.

For example: https://ftaas.saas.hpe.com

Client ID / Client secret The client ID and secret you generated to connect to SRF.
Use proxy Select to use a proxy to access SRF, and then also define your proxy settings in the fields below.
Do not validate certificate By default, LeanFT employs Full SSL (Strict). Select this option to ignore certificate errors.
Show remote access window when a mobile test runs Select to enable watching your test runs on the mobile devices in the SRF remote access window.

Note: If you select this option, and your device connector uses a self-signed certificate, then the first time a test runs you will receive the following certificate message:

The attempt to connect to <connector URL> has failed

To fix this issue, add the connector’s self-sign certificate to your machines trusted certificate storage.

After configuring your certificate you should restart the LeanFT engine.

Click Verify to check your connection.

Edit your LeanFT test

Edit your test to enable running it in SRF.

Specifically, modify your test script so that it launches browsers and locks mobile devices that are allocated by SRF in the cloud, rather than local browsers and devices.

Use the following when editing your test:

SrfLab class

Use the SrfLab class to launch your browser or lock a mobile device in SRF.

Provide the SrfLab class with description objects for your browser or device, defining the capabilities you would like to use as your test environment.

LeanFT SDKs

Use the LeanFT SDKs to define your test object and write your script, just as you would when running a test locally.

Supported capabilities for LeanFT

Use capability code to define SRF feature values, such as test tags, or the names displayed in test results, as well as environment settings.

Releasing SRF environments

We recommend calling the releaseEnvironment method of the SrfLab class at the end of your test to unlock a device and release the browser environment.

Add visual testing steps

Integrate your LeanFT test with both SRF and Applitools.

To do this, add code as needed to define your Applitools visual testing steps and environment variables.

Design mobile tests on SRF mobile devices

Use LeanFT’s Test Recorder and Object Identification Center on mobile apps, on SRF-provisioned mobile devices.

Make sure that the connection between LeanFT and SRF is configured.

1. From your IDE menu, click LeanFT > Launch a StormRunner Functional Device.

The SRF Mobile Lab window opens.

2. Select the device on which you want to spy or record.

Once selected, the device will be locked.

3. To spy, open the required app on the device (or install it if it is not already installed). You can start recording either before or after you open the app.

4. From your IDE menu, open the Object Identification Center or Test Recorder and use them as you would typically.

5. When you are done using the device, close the Mobile Lab window to release the device.

While the device is locked, you can run your test on it for debugging purposes. A run report will be created in LeanFT, but will not be created in SRF.

Run your test and view results

Run your test in SRF just as you would locally.

Snapshots in run results are affected by snapshot levels set in the script, as for other LeanFT tests.

Test results are displayed both in the LeanFT run report, and in SRF.

LeanFT code samples for remote testing

LeanFT Java code samples

Launch the latest version of Chrome in a Windows 7 machine

Browser browser = SrfLab.launchBrowser(BrowserType.CHROME);

Launch IE 11 on a Windows 10 machine and set the SRF test name to be shown in the RESULTS tab

· Provide a predefined object:

BrowserDescription bd = new BrowserDescription();

bd.setType(BrowserType.INTERNET_EXPLORER); //or: bd.set(“type”, BrowserType.INTERNET_EXPLORER) or: bd.set(“type”, “INTERNET_EXPLORER”)

bd.set(“version”, “11”);

bd.set(“osType”, “Windows”);

bd.set(“osVersion”, “10”);

bd.set(“testName”, “My LeanFT web test”);

Browser browser = SrfLab.launchBrowser(bd);

· Define capabilities using the Builder syntax:

Browser browser = SrfLab.launchBrowser(new BrowserDescription.Builder().type(BrowserType.INTERNET_EXPLORER).set(“version”, “11”).set(“osType”, “Windows”).set(“osVersion”,”10″).set(“testName”, “My LeanFT web test”).build());

Lock a device in SRF

· Provide a predefined object:

DeviceDescription dd = new DeviceDescription();

dd.setOsType(“Android”); //or: dd.set(“osType”, “Android”)

dd.setOsVersion(“5.02”); //or: dd.set(“osVersion”, “5.02”)

dd.set(“testName”, “My LeanFT mobile test”);

Device device = SrfLab.lockDevice(dd);

· Define capabilities using the Builder syntax:

Device device = SrfLab.lockDevice(new DeviceDescription.Builder().osType(“Android”).osVersion(“4”).set(“testName”,” My LeanFT mobile test”).build());

· Define capabilities in the SrfLab class, calling previously mapped properties:

Map<String, Object> props = new HashMap<>();

props.put(“osType”, “Android”);

props.put(“osVersion”, “5.02”);

props.put(“testName”, ” My LeanFT mobile test “);

Device device = SrfLab.lockDevice(DeviceDescription.fromMap(props));

Launch a browser in an SRF mobile device

First, lock an SRF device, and then launch your browser by passing the device object to theBrowserFactory.launch method.

Browser browser = BrowserFactory.launch(BrowserType.Chrome, device);

Release the SRF environment at the end of your test

· Release a web environment

SrfLab.releaseEnvironment(browser);

· Unlock a device

SrfLab.releaseEnvironment(device);

LeanFT JavaScript code samples

Launch the latest version of Chrome in a Windows 7 machine

LFT.SrfLab.launchBrowser(“Chrome”).then(function (b) { //or: Web.BrowserType.Chrome instead of “Chrome”

browser = b;

});

Launch IE 11 on a Windows 10 machine and set the SRF test name to be shown in the RESULTS tab

LFT.SrfLab.launchBrowser({

type: Web.BrowserType.IE, //or: type: “IE”

version: “11”,

osType: “Windows”,

osVersion: “10”,

testName: “My LeanFT web test”

}).then(function (b) {

browser = b;

});

Lock a device in SRF

LFT.SrfLab.lockDevice({

osType: “Android”,

osVersion: “5.02”,

testName: “My LeanFT mobile test”

}).then(function(d) {

device = d;

});

Release the SRF environment at the end of your test

· Release a web environment

LFT.SrfLab.releaseEnvironment(browser);

· Unlock a device

LFT.SrfLab.releaseEnvironment(device);

Full test – Advantage Online Shopping

The following example tests the Advantage Online Shopping site.

var LFT = require('leanft');
var SDK = LFT.SDK;
var Web = LFT.Web;
var whenDone = LFT.whenDone;
var expect = require('leanft/expect');
describe('Example of LeanFT execution burst test in SRF', function () {
 this.timeout(120000);
 var browser;
 before(function (done) {
 LFT.init({});
 whenDone(done);
 });
 beforeEach(function (done) {
 LFT.beforeTest();
 //The following are examples of available capabilities when launching a browser in SRF.
 LFT.SrfLab.launchBrowser({
 osType: "windows",
 osVersion: "8.1",
 type: "chrome",
 //version: "58",//Specify a specific number or define as the latest version, as follows:
 version: "latest",
 release: "0.95",
 build: "1234",
 screenResolution: "800x600",
 testName: "Demo_Burst_Test_LeanFT_JS"
 })
 .then(function (b) {
 browser = b;
 });
 whenDone(done);
 });
 it('should validate the price of the chosen item', function (done) {
 browser.navigate("http://advantageonlineshopping.com/");
 var searchAdvantageonlineshopping = browser.$(Web.Edit({
 name: "WebEdit",
 tagName: "INPUT",
 type: "text"
 }));
 searchAdvantageonlineshopping.setValue("speakers");
 var boseSoundlinkBluetooth = browser.$(Web.Link({
 innerText: "BOSE SOUNDLINK BLUETOOTH SPEAKER III $269.99 ",
 tagName: "A"
 }));
 boseSoundlinkBluetooth.click();
 var itemPrice = browser.$(Web.Element({ xpath: "//DIV[@id="Description"]/H2[1]", className: "roboto-thin screen768 ng-binding", tagName: "H2" }));
 //Sample checkpoint (expects) validation:
 expect(itemPrice.outerText()).toEqual("$269.99");
 whenDone(done);
 });
 afterEach(function (done) {
 LFT.afterTest();
 if (browser) {
 browser.close();
 }
 whenDone(done);
 });
 after(function (done) {
 LFT.cleanup();
 whenDone(done);
 });
});

LeanFT C# code samples

Release the SRF environment at the end of your test

· Release a web environment

SrfLab.ReleaseEnvironment(browser);

· Unlock a device

SrfLab.ReleaseEnvironment(device);

Full test – Advantage Online Shopping

The following example tests the Advantage Online Shopping site using the LeanFT NUnit3 template.

using System;
using NUnit.Framework;
using HP.LFT.SDK;
using HP.LFT.Verifications;
using HP.LFT.SDK.Web;
using System.Text.RegularExpressions;
namespace LeanFtTestProject1
{
 [TestFixture]
 public class LeanFtTest : UnitTestClassBase
 {
 static BrowserDescription brDesc;
 static IBrowser browser;
 String categoryToFind = "speakers";
 String itemToFind = "Bose Soundlink Bluetooth Speaker III";
 String expectedPrice = "$269.99";
 static String userName = "<username>";
 static String userPassword = "<password>";
 [OneTimeSetUp]public void TestFixtureSetUp()
 {
 var brDesc = new BrowserDescription();
 //example of the different capabilities that can be used when launching a browser in SRF.
 brDesc.Type = BrowserType.Chrome;
 brDesc.Set("version", "58");
 brDesc.Set("osType", "windows");
 brDesc.Set("osVersion", "8.1");
 brDesc.Set("release", "0.95");
 brDesc.Set("build", "1024");
 brDesc.Set("testName", "LeanFT Burst C# Online Shopping");
 brDesc.Set("resolution", "800x600");

 browser = SrfLab.LaunchBrowser(brDesc);
 }
 [SetUp]public void SetUp()
 {
 // Before each test
 }
 [Test]public void ValidatePriceOfChosenItem()
 {
 browser.Navigate("http://advantageonlineshopping.com/#/");

 browser.Describe<IEditField>(new EditFieldDescription
 {
 Type = @"text",
 Placeholder = @"Search",
 TagName = @"INPUT",
 Name = @"WebEdit"
 }).SetValue("speakers");

 browser.Describe<IWebElement>(new WebElementDescription
 {
 AccessibilityName = string.Empty,
 TagName = @"svg",
 InnerText = string.Empty,
 Index = 10
 }).Click();

 browser.Describe<IWebElement>(new WebElementDescription
 {
 TagName = @"A",
 InnerText = "Bose Soundlink Bluetooth Speaker III"
 }).Click();

 String itemPrice = browser.Describe<IWebElement>(new WebElementDescription
 {
 XPath = @"//DIV[@id=""mobileDescription""]/H2[1]",
 ClassName = @"roboto-thin ng-binding",
 TagName = @"H2"
 }).OuterText;

 Assert.AreEqual("$269.99", itemPrice);
 }
 [TearDown]
 public void TearDown()
 {
 // Clean up after each test
 }
 [OneTimeTearDown]public void TestFixtureTearDown()
 {
 // Clean up once per fixture
 }
 }
}

Record and run UFT tests remotely using StormRunner Functional

This article describes how to record and run your UFT test remotely using your SRF lab.

Configure the connection to SRF

Ensure that you have a valid connection to the SRF lab before running your Web or Mobile tests remotely.

Do the following:

1. On the SRF settings page, generate a client ID and secret to use when accessing SRF.

2. In UFT, browse to the StormRunner Functional pane in the Options dialog box (Tools > Options > GUI Testing > StormRunner Functional).

3. Enter the values for your SRF access, as well as proxy access as needed. Use the client ID and secret values you generated in SRF.

4. Click Test Connection to verify that your details are correct.

Define the Record and Run settings

Open your test, and define the Record and Run Settings on the Web or Mobile tabs.

Define settings to perform Web testing

1. On the Web tab, select Open the following when recording or running, and then select Use: Micro Focus SRF.

For example:

 

2. Define the URL you want to open in the SRF lab, the tunnel you want to use if needed, and your test environment.

3. (Optional) Data drive your tests during runtime by modifying browser and device values for each test iteration.

Define your settings to perform Mobile device testing

1. On the Mobile tab, select Use StormRunner Functional.

For example:

 

2. Define your test device as follows:

o Under Device Capabilities, define the capabilities you require so that SRF can find a device for you.

o Under Specific Device, select a specific device from the SRF lab.

3. Under App Settings, do the following:

o Select the apps you need for your test.

o Define whether you want the selected apps to be installed and restarted before each test run, and uninstalled at the end.

· Define which app you want to launch at the start of your test.

4. If you are testing on a web browser, define additional settings on the Web tab, including a URL to open at the start of your test, and any parameterization details needed.

Record a UFT mobile test remotely

Remote recording is supported for mobile devices only. To record your mobile test, do the following:

1. Configure your Record and Run Settings for mobile testing in SRF.

2. Click Record on the UFT toolbar to start recording.

A mobile device from the SRF mobile lab is shown in the remote access window.

3. Perform actions on the mobile device to record your test.

4. Click Stop when you’re done to stop recording. Your test is saved in UFT.

The remote access window remains open after you finish recording so that you can continue to spy and add objects to your test’s object repository. The remote access window will lose connectivity with the device after 15 minutes of inactivity.

Note: If you update your Record and Run Settings and start recording on a second device, the remote access window with the first device is closed, and then device is released.

Run UFT tests remotely

After configuring your Record and Run Settings, run your tests as you would otherwise.

Data drive your tests during runtime

Data drive your tests during runtime by modifying browser and device values for each test iteration.

In the Web tab of the Record and Run Settings dialog:

1. Select Parameterize runtime web settings using.

2. Define your parameter value location:

o GlobalData Table. For global parameters, defined in the Data table.

o Test Parameter. For test parameters, defined in the Properties pane.

3. Define the name of the parameter used to define the browser. (Default = Browser)

4. Prepare the parameter values in your selected location.

Note: Some mobile testing and device parameters may not be pre-defined in your data table.

In such cases, add these parameter columns manually.

SRF parameter values

The following table describes the supported parameters used when data driving your test remotely in SRF.

Browser Mandatory. One of the following:

· CHROME

· FIREFOX

· IE

· MOBILE_CHROME for the native Chrome browser on Android.

· MOBILE_SAFARI for the native browser on iOS.

browser_identifier One of the following:

· com.hp.mobileweb. Uses the Mobile Web app

· Leave this value blank to use a native mobile browser, and then also set the device_ostype parameter.

This enables Mobile Center to automatically define the browser identifier.

Browser_version N/A for mobile devices.

For desktop browsers, one of the following:

· A browser version number.

· latest, or leave this value blank to use the latest version available.

device_manufacturer Defines the device manufacturer.

Enter a value only when testing on mobile devices. Leave this value blank to use any device available.

device_model Defines a device name, and must be one of those listed in the Device dropdown list in the Record and Run Settings dialog box.

Enter a value only when testing on mobile devices. Leave this value blank to use any device available.

device_ostype One of the following:

· Android

· iOS

Mandatory if the Browser value is set to MOBILE_HPEWEB.

Enter a value only when testing on mobile devices. Leave this value blank to use any device type available.

device_osversion Defines the device’s operating system version. Leave this value blank to use any device OS version available.
host Defines the device ID, as defined in Mobile Center. Required for running the test on mobile devices (as opposed to on the Chrome emulator).
OS Mandatory for desktop web testing, N/A for mobile devices.

One of the following:

· Windows 7

· Windows 10

· Windows 8.1

· Ubuntu 16.04

Resolution N/A for mobile devices.

One of the following:

· 1024×768

· 800×600

· 1280×1024

· 1366×768

· 1600×900

· 1920×1080

Leave this value blank to use the default resolution (1024×768).

Target Enter SRF to use StormRunner Functional when you run your test.

Leave this value blank to run your test locally or using Mobile Center.

Tunnel_name If you need a tunnel to connect to your application from SRF, enter the tunnel name as shown in SRF.

Note: Use only one tunnel per test. Switching tunnels between iterations in the same test may cause unexpected behavior.

Record Scripts using StormRunner Functional

This article describes how to record new scripts in SRF to use in your modular automation tests.

Record Script

If you are starting from the AUTOMATION tab, first create a test, and click the SCRIPTS tab on the right.

Then, do the following:

1. Click RECORD.

If you’ve started from the SCRIPTS tab, select WEB or MOBILE APPS.

Tip: To record a web script on a mobile device, select WEB.

This enables you to record and run on both desktop and mobile device browsers.

A remote access window opens for your recording session, with a popup to show the environment.

In the popup, click EDIT to change your environment settings.

2. Click to start your session. Use the toolbar buttons to manage your recording and add testing elements.

Tip: If you are testing a mobile device, use the CONTROL PANEL options on the left to interact with your device.

For example, change your orientation, zoom in and out of your device, or send text to your device.

3. When you’re finished recording, click STOP .

4. Enter your script name and save your script.

SRF displays your script, where you can make edits or return to recording.

5. To complete your recording session, click EXIT, and save your script with a meaningful name.

Recording toolbar reference

Use the toolbar buttons to do the following:

Pause your session if you need to take a break or make changes in your application that you do not want recorded.

Click to start recording again.

Stop your recording to fully stop and switch to the code view of your recorded test.

Click to start recording again.

Add checkpoints.
Add an Applitools visual testing step.
Display the recorded code.
Toggle the SRF clipboard on or off.

Use the SRF clipboard when you want to copy text from outside your recording to inside the remote viewer, or from inside the remote viewer to a local file.

For example, to copy your website URL to the browser window SRF, do the following:

1. Copy the URL from your local desktop.

2. In SRF, click the Toggle Clipboard button.

3. Paste the URL into the SRF clipboard field that appears.

4. Click the browser in the recording window to ensure that it’s in focus.

5. Click the Copy to clipboard button to paste it into the address bar.

Introducing StormRunner Functional 1.61

Micro Focus StormRunner Functional (SRF)1.61

This version of SRF is packed with new features and integrations, enabling you to simplify and streamline your testing processes, validate your applications on newly supported cloud environments, and better analyze your test results.

This blog post provides a short overview of the main enhancements included in the latest SRF release.

What’s new in SRF 1.61?
SRF 1.61 introduces the following new features and capabilities:

Mac Support
SRF’s virtual lab now provides you with access to Mac testing environments in the cloud!

Now you can test your web apps on Mac environments provided for you by SRF in the cloud, saving the cost and hassle of procuring, setting up, and maintaining your own local Mac machines.

Video Reporting
SRF run results now include video recordings of your test runs.

Starting in version 1.61, SRF’s comprehensive run reports include video recordings for executed tests, both manual and automated. These videos improve your ability to analyze the root cause of any testing failures, and accelerate resolution.

License Segregation by Workspace
SRF Enterprise customers with multiple SRF workspaces can now segregate license concurrency, reserving specific amounts for each workspace.

Segregating license concurrency per workspace allows you to optimize and manage your license usage across your tenant.

Environment Sets
SRF now supports the ability to create sets of environments and reuse them across different SRF tests. These environment sets speed up and streamline the test design process.

You can create various environment sets for different test cases, and then associate the sets to your tests rather than manually adding each environment separately to each test.

For example: create an environment set that includes all the browsers used most by your users. Associate the set with each of your “sanity” tests.

Submit Defects to ALM
Submit defects for your test runs from SRF into Micro Focus Application Lifecycle Management (ALM).

ALM customers can now submit defects directly from SRF into their ALM server, for both manual and automated runs. The submitted defects automatically include useful information about your tests, enabling an easy reproduction of the defect, and saving both time and effort.

Bamboo Integration
The Micro Focus Application Automation Tools Bamboo plugin now supports SRF.

You can now run your SRF tests from your Bamboo server, as part of your continuous testing process. This integration with Bamboo joins the Jenkins integration that is already available, and extends SRF’s support in the CI/CD stack.

Reset User Settings on ALM Octane

On some scenarios user might report that they cannot access certain modules or perform certain actions they were able to do before. Most of the times the issue is related to a corrupted user profile in ALM Octane. To clean the settings you need to follow these steps:

1. Logon with the user credentials to the correct workspace

2. Paste the following url to the browser’s address bar after verifying that the sharedspace id and workspace id are correct:

https://<Octane Server>.<domain>.com/ui/?p=<sharedspace>/<workspace>#/clear-settings