How to upload Appium tests to StormRunner Functional

Before uploading a Appium test to SRF, ensure that you first define the following in your test:

  • The SRF server and port
  • The SRF client secret ID (app) and secret

Then, upload Appium tests to SRF from the SRF SCRIPTS tab.

Appium code samples for upload
The following code samples use the Advantage Online Shopping demo app. Use these samples as guides when preparing Appium tests for upload.

Appium JavaScript code sample

var wd = require(‘wd’);
var serverURL = process.env.SELENIUM_ADDRESS;
var b = require(‘wd’).promiseChainRemote(serverURL);

wd.configureHttp({
timeout: 60000,
retries: 3,
retryDelay: 100
});

b.on(‘status’, function (info) {
console.log(‘\x1b[36m%s\x1b[0m’, info);
});

b.on(‘command’, function (meth, path) {
console.log(‘ > \x1b[33m%s\x1b[0m: %s’, meth, path);
});

b.on(‘error’, function (meth, path) {
console.error(‘ > \x1b[33m%s\x1b[0m: %s’, meth, path);
});

describe(‘Selenium Test Case’, function () {
it(“should find an element”, function (done) {
console.error(‘before b.init’);
b.init({
SRF_CLIENT_ID: process.env.SRF_CLIENT_ID,
SRF_CLIENT_SECRET: process.env.SRF_CLIENT_SECRET

})
.elementByClassName(“android.widget.Button”)
.click()
.elementById(“up”)
.click()
.quit(() => { done(); })
.catch(err => {
console.error(err);
b.quit(() => { done(err); })
});
});
});

Appium Java code sample


prinimport io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.concurrent.TimeUnit;

import java.net.MalformedURLException;
import java.net.URL;

public class remoteSRF {

AndroidDriver wd = null;

public static final String SRF_SERVER = System.getenv(“SELENIUM_ADDRESS”);
public static final String SRF_CLIENT_SECRET = System.getenv(“SRF_CLIENT_SECRET”);

@Before
public void openMobile() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“SRF_CLIENT_SECRET”, SRF_CLIENT_SECRET);
wd = new AndroidDriver(new URL(SRF_SERVER), capabilities);
wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}

@After
public void closeMobile() throws MalformedURLException {
wd.closeApp();
}

@Test
public void login() throws MalformedURLException {
wd.findElement(By.id(“loginButton”)).click();
System.out.println(“Login Completed!”);

WebElement menu = wd.findElement(By.id(“up”));
menu.click(); //Expand menu
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
menu.click(); //Collapse menu
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
menu.click(); //Expand menu again
}
}

 

Advertisements

How to upload Selenium tests to StormRunner Functional

SRF enables you to upload Web Selenium tests as SRF assets.

Upload your Selenium test

Before uploading a Selenium test to SRF, ensure that you first define the SRF server, port, client ID, and client secret in your test.

Then, do any of the following, as needed:

Applitools If you want to add Applitools visual testing steps to your test, see Add Applitools code to your Selenium script post.
Ruby If you are uploading a Ruby script to SRF, continue with Prepare a Ruby .zip for upload post.
Packaging multiple scripts To package multiple scripts together, continue with Prepare a Selenium .jar file for upload post.
JUnit tests If your script includes multiple tests in a single JUnit class, SRF runs all tests of the defined class.

If you do not want all of these tests to be run in SRF, comment out the relevant lines as needed before uploading.

When you’re done preparing your test, upload Selenium tests to SRF from the SRF SCRIPTS tab.

Prepare a Selenium .jar file for upload

Package your Selenium scripts as a .jar archive to upload to SRF.

Do the following:

1. Make sure you have the following prerequisites before you start:

Test script Ensure that your script can run remotely in SRF.

Note: We recommend making a copy of your original script in the same location for reference.

Maven Make sure you have Maven installed, and that your project is a maven project.
Descriptor file Add a descriptor.json file in your project’s resources folder.

In this file, define the runnableClass value as the path to the class you want to run, including the fully-qualified class name.

2. descriptor.json file with runnableClass example

2. In your Selenium script, replace your Client ID and Secret values with the following static code. You can comment out the CLIENT_ID property.

capabilities.setCapability("SRF_CLIENT_ID", System.getenv("SRF_CLIENT_ID"));
capabilities.setCapability("SRF_CLIENT_SECRET", System.getenv("SRF_CLIENT_SECRET"));

3. Add the RemoteWebDriver location as follows:

RemoteWebDriver driver = new RemoteWebDriver(new URL(System.getenv("SELENIUM_ADDRESS")), capabilities);

4. Compile your code, including any dependencies, and make sure the hierarchy remains stable.

Example: Compiling a .jar file with dependencies

5. From your IDE or the command line, run a maven clean install command.

Your compiled .jar file will be available for upload in your /target folder.

Continue with Basic upload steps to upload your .jar file to SRF.

Prepare a Ruby .zip for upload

To upload your Ruby test to SRF, you must first package the test as a .zip file.

Do the following:

· Include a Rakefile in your zip, including a default task that describes your test. SRF runs the default task when running your uploaded test.

The Rakefile filename is case-sensitive.

· Optionally, define parameters in your script to test different features in each test run.

For example, if you have a parameter named FEATURE_PATH, add the following code to your test:

t.cucumber_opts = '--format pretty ".\' + ENV["FEATURE_PATH"] + '"'

Then, continue with Basic upload steps to upload your .zip file to SRF.

Note: SRF supports specific frameworks out of the box. If your test requires additional components, they must be included in the zip file you upload.

For example, use the –install-dir flag of a gem command to install the component locally.

Selenium code samples for upload

Use the following code as samples when preparing Selenium tests for upload.

Selenium Java code sample

package com.microfocus.srf;

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.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;

/** 
 * Micro Focus StormRunner Functional Selenium Java upload example
 */
public class SeleniumUpload
 {private static RemoteWebDriver driver;
 @BeforeClasspublic static void configToSRF()throws MalformedURLException{
 DesiredCapabilities capabilities = DesiredCapabilities.chrome();
 capabilities.setCapability("SRF_CLIENT_SECRET", System.getenv("SRF_CLIENT_SECRET"));
 capabilities.setCapability("name","My Uploaded Selenium Example");

 URL SRF_URL = new URL( System.getenv("SELENIUM_ADDRESS"));
 driver = new RemoteWebDriver(SRF_URL, capabilities);
 }

 @Testpublic void test() {
 driver.get("http://www.google.com");// Find the text input element by its name
 WebElement element = driver.findElement(By.name("q"));// Enter something to search for
 element.sendKeys("StormRunner Functional");// Now submit the form. WebDriver will find the form for us from the element
 element.submit();

 }

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

Selenium JavaScript code sample

This example opens the Advantage Online Shopping site and performs a search. It then checks a price and adds an item to the cart, checks out and pays for the item. During payment phase, the example checks the total cost against the verified price.

This example also verifies specific parameter values as defined in SRF, or uses a defined set of default values.

var webdriver = require('selenium-webdriver'),
 By = webdriver.By,
 until = webdriver.until;
var assert = require('selenium-webdriver/testing/assert');

//This example specifies values for input parameters in SRF
//Parameter names should be as shown below

var categoryToFind = process.env.categoryToFind;
var itemToFind = process.env.itemToFind;
var expectedPrice = process.env.expectedPrice;
var driver;

//In case input parameters were not specified in SRF, default values will be used:
 if (categoryToFind==undefined)
 categoryToFind="speakers";
 if (itemToFind==undefined)
 itemToFind="Bose Soundlink Bluetooth Speaker III";

 if (expectedPrice==undefined)
 expectedPrice="$269.99";
describe('DEMO Online Shopping Selenium', function () {
 before(function(done){
 var capabilities = {
 browserName: 'chrome',
 SRF_CLIENT_ID: process.env.SRF_CLIENT_ID,
 SRF_CLIENT_SECRET: process.env.SRF_CLIENT_SECRET
 };
 driver = new webdriver
 .Builder()
 .withCapabilities(capabilities)
 .usingServer(process.env.SELENIUM_ADDRESS)
 .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(categoryToFind);
 })
 .then(()=>driver.findElement(By.css("#mobileSearch > #Layer_1")).click())
 .then(done);
 });

it('should click on ' + itemToFind + ' in list of founded items', function (done) {
 var element = driver.findElement({partialLinkText:itemToFind, 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(expectedPrice);
 })
 .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('SRFdemo1234')
 .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(expectedPrice);
})
 .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(expectedPrice);
 })
 .then(done);
 });

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

Sample Ruby .zip file

The following is an example of the contents of a zip file containing a Ruby test ready for upload:

The files in this example include the following code:

your.feature file

In this example, the your.feature file includes a cucumber test:

Feature: Bing can search
Background:
 Given I am on http://bing.com
Scenario: Search for a term
 Then I will search for "SRF"
 And click the MagnifyGlass
 Then I should see "SRF"

steps.rb file

In this example, the steps.rb file contains the step definitions for the cucumber test:

require "capybara/cucumber"
Given /^I am on (.+)$/ do |url|
 visit (url)
end
Then /^I will search for "(.*?)"$/ do |searchText|
 fill_in 'q', :with => searchText
end
And /^click the MagnifyGlass$/ do
 find(:css,'input[type=submit]').click
end
Then /^I should see "(.*?)"$/ do |searchText|
 expect(page).to have_content(searchText)
end

Rakefile file

In this example, the Rakefile contains a default task, which is executed by SRF when running your test.

require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:default) do |t|
 t.cucumber_opts = '--format pretty ".\features\your.feature"'
end

How to Upload UFT tests to StormRunner Functional

Upload a Web or Mobile test from UFT to SRF to use it in modular automation tests in the cloud.

Upload tests from UFT

If you already have the test opened in UFT, or the test is conveniently accessible from UFT, use the SRFbutton in the UFT toolbar to upload your test.

1. Verify that you have a valid connection to the SRF lab.

Connect to SRF

2. In the UFT toolbar, click the Upload to StormRunner Functional button arrow.

Select one of the following:

Upload From File System Drag and drop the test in the upload box, or browse to the test you want to upload.
Upload Active Test Select to upload the test that’s currently active in UFT.

3. Optionally, enter a new name for your test in SRF.

4. Select your test type:

o Select Mobile only if you are testing mobile apps on mobile devices.

o Select Web if you are testing browsers, whether they are mobile or desktop browsers.

Note: Cross browser testing defined by browser parameters in UFT is ignored by SRF.

Define your testing environment in SRF before running your test.

5. Click Upload. Your test is zipped, together with any relevant external resources, and uploaded to SRF.

When the upload is complete, UFT displays a link to the test in SRF. Your test remains open in UFT.

Data tables in uploaded tests

Content in data tables in uploaded UFT tests ignored, although the rows are kept, and use values defined in SRF.

For example, if your data table includes rows for Chrome and Android, the values in the data table are ignored, but the test is run in two iterations for the environments defined in SRF.

Upload tests from SRF

Upload UFT tests from within SRF from the SCRIPTS page.

How to upload LeanFT tests in StormRunner Functional

StormRunner Functional enables you to upload Web and Mobile tests from LeanFT as SRF assets.

Edit your LeanFT test before uploading

You may need to edit your test before uploading it to SRF. Only .js scripts are editable in SRF. All other file types are read-only.

Before uploading a LeanFT test to SRF, modify your code as needed in the following scenarios:

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.

JavaScript: Nest multiple describe code

If your JavaScript test has multiple describes, nest these using a single set of initialization and cleanup lines.

Remove any LFT.init() and LFT.cleanup() operations from the nested describe code. These lines should appear only once per test.

Ensure that these operations are included in the top-level describe code. If they’re missing:

· Add LFT.init() to the before() function

· Add LFT.cleanup() to the after() function

Note: For Java and C# tests, use LeanFT templates to ensure this code is organized correctly.

Multiple tests in JUnit classes

If your script includes multiple tests in a single JUnit class, SRF runs all tests of the defined class.

If you do not want all of these tests to be run in SRF, comment out the relevant lines as needed before uploading.

Preparing JAR files for upload

When preparing your JAR file for upload, ensure that you do not include JUnit and LeanFT Java SDK dependencies.

For example, in IntelliJ, do the following:

1. Create your JAR as empty, with no dependencies.

2. Then, add the project’s compile output to the JAR file, as well as any other dependencies required for your test run.

Note: Do not add the LeanFT, JUnit, and Hamcrest dependencies.

LeanFT 14.03 Java

If you are working in Java with LeanFT version 14.03 or lower, ensure the following:

· That the following line is uncommented in the leanft.properties file

· The autoLaunch value is false, as defined by default.

autoLaunch=false

When you’re done preparing your test, upload LeanFT tests to SRF from the SRF SCRIPTS tab.

Run results for uploaded LeanFT tests

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

LeanFT code samples for upload

Use the following code samples when creating LeanFT tests to upload to SRF.

LeanFT Java code sample for upload (Web)

The following code sample browses to the Advantage Online Shopping site, waits for the page to load, and then closes the browser.

Note: The Chrome browser defined in this sample will be overridden by any browser selected in SRF for a specific test run.

package com.company;

import com.hp.lft.sdk.web.Browser;
import com.hp.lft.sdk.web.BrowserDescription;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.hp.lft.sdk.*;
import com.hp.lft.sdk.web.*;
import com.hp.lft.verifications.*;
import unittesting.*;
import static org.junit.Assert.assertTrue;

public class LeanFtTest extends UnitTestClassBase
 {public LeanFtTest()
 {//Change this constructor to private if you supply your own public constructor
 }

 @BeforeClass
 public static void setUpBeforeClass() throws Exception
{
 instance = new LeanFtTest();
 globalSetup(LeanFtTest.class);
 }
 @AfterClass
 public static void tearDownAfterClass() throws Exception {
 globalTearDown();
}
 @Before
 public void setUp() throws Exception {
 }
 @After
 public void tearDown() throws Exception{
 }
 @Test
 public void test() throws GeneralLeanFtException {
 BrowserDescription bd = new BrowserDescription();
 bd.set("type", "Chrome");
 Browser browser = SrfLab.launchBrowser(bd);
 browser.navigate("http://www.advantageonlineshopping.com");
 browser.sync();

 browser.close();
}

LeanFT JavaScript code sample for upload (Web)

This example opens the Advantage Online Shopping site and performs a search. It then checks a price and adds an item to the cart, checks out and pays for the item. During payment phase, the example checks the total cost against the verified price.

This example also verifies specific parameter values as defined in SRF, or uses a defined set of default values.

var LFT = require('leanft');
var SDK = LFT.SDK;
var Web = LFT.Web;
var whenDone = LFT.whenDone;
var expect = require('leanft/expect');
describe('SRF uploaded LeanFT test example with input parameters',function(){
 var browser
 before(function(done){
 SDK.init({});

 whenDone(done);
 });
 beforeEach(function(done){
 LFT.beforeTest();
 Web.Browser.launch('chrome').then(function(b){
 browser = b;
 });
 whenDone(done);
 });
 it('should validate the price of the chosen item',function(done){
 //Example for specifying values for input parameters from SRF UI
 //Parameter names should be same as below (with default values in case they are not set)
 var categoryToFind = process.env.categoryToFind || "speakers";
 var itemToFind = process.env.itemToFind || "Bose Soundlink Bluetooth Speaker III";
 var expectedPrice = process.env.expectedPrice || "$269.99";

 browser.navigate("http://advantageonlineshopping.com/");
 var searchEdit = browser.$(Web.Edit({type:"text", placeholder:"Search", tagName:"INPUT", name:"WebEdit"}));
 searchEdit.setValue(categoryToFind);
 var layer1 = browser.$(Web.Element({accessibilityName: '', innerText: '', tagName: 'svg', index: 10}));
 layer1.click();

 var itemInList = browser.$(Web.Element({tagName:"A", innerText:itemToFind}));
 itemInList.click();

 var itemPrice = browser.$(Web.Element({xpath:"//DIV[@id="Description"]/H2[1]",className:"roboto-thin screen768 ng-binding",tagName:"H2"}));

 //Example of checkpoints(expects) validation:
 expect(itemPrice.outerText()).toEqual(expectedPrice);
 whenDone(done);
 });

 afterEach(function(done){
 LFT.afterTest();
 if(browser){
 browser.close();
 }
 whenDone(done);
 });
 after(function(done){
 SDK.cleanup();
 whenDone(done);
 });
});

LeanFT JavaScript code sample for upload (Mobile)

This example opens the Advantage Online Shopping app on the Mobile Center device named srf-device. The script then logs in and logs out again.

var LFT = require("leanft");
var SDK = LFT.SDK;
var Mobile = LFT.Mobile;
var whenDone = LFT.whenDone;
var LFTexpect = require("leanft/expect");
var SwipeDirection = Mobile.SwipeDirection;
var argv = require('yargs').argv;
 describe("Advantage App upload script Demo",function(){
 var app;
 this.timeout(2400000);
 beforeEach(function(done){
 SDK.init();
 LFT.SrfLab.lockDevice({
 name:'srf-device'
 }).then(function(d){
 device = d;
 app = device.$(Mobile.Application({
 identifier:"com.hpswdemo.advantageinc",
 name:"Advantage",
 version:"38",
 isPackaged :true
 }
 ));
 app.install();
 app.restart();
 }
 );

 whenDone(done);
 });
 it("Advantage",function(done){
 var userName = app.$(Mobile.Edit({
 hint:"User name",
 className:"Input",
 resourceId:"loginUserNameEditText",
 mobileCenterIndex:0
 }
 ));
 var password = app.$(Mobile.Edit({
 hint:"Password",
 className:"Input",
 resourceId:"loginPasswordEditText",
 mobileCenterIndex:1
 }
 ));
 var login = app.$(Mobile.Button({
 text:"LOGIN",
 className:"Button",
 resourceId:"loginButton",
 mobileCenterIndex:0
 }
 ));

 var menu = app.$(Mobile.UiObject({
 className:"ImageView",
 resourceId:"up",
 mobileCenterIndex:12
 }
 ));

 var account = app.$(Mobile.Label({
 text:"ACCOUNTS",
 className:"Label",
 container:"Table[0][0][0]",
 resourceId:"menuItemTextView",
 mobileCenterIndex:0
 }
 ));

 var savings = app.$(Mobile.Label({
 text:"Savings",
 className:"Label",
 container:"Table[1][0][0]",
 resourceId:"accountNameTextView",
 mobileCenterIndex:3
 }
 ));

 var logOut = app.$(Mobile.Label({
 text:"LOGOUT",
 className:"Label",
 container:"Table[0][7][0]",
 resourceId:"menuItemTextView",
 mobileCenterIndex:0
 }
 ));

 var yesLogOut = app.$(Mobile.Button({
 text:"Yes",
 className:"Button",
 resourceId:"button1",
 mobileCenterIndex:0
 }
 ));
 userName.setText("SRFTest");
 LFTexpect(userName.text()).toBe("SRFTest");
 password.setText("SRF123456");

 login.tap();

 menu.tap();

 account.tap();

 menu.tap();

 logOut.tap();

 yesLogOut.tap();
 whenDone(done);
 });
 afterEach(function(done){
 LFT.SDK.cleanup();
 whenDone(done);
 });
});

JavaScript test with multiple describes

var LFT = require('leanft');
var SDK = LFT.SDK;
var Web = LFT.Web;
var SAPUI5 = LFT.SAPUI5;
var whenDone = LFT.whenDone;
var verify = require('leanft/verify');
describe('Upper describe',function(){
before(function(done){
 LFT.init({});
 whenDone(done);
});
describe('1st Inner describe ',function(){
 var browser;
 before(function(done){
 whenDone(done);
 });
 beforeEach(function(done){
 LFT.beforeTest();
 LFT.SrfLab.launchBrowser({
 type: "Chrome",
 version: "60",
 platform: "Ubuntu 16.04"
 }).then(function(b) {
 browser = b;
 });
 whenDone(done);
 });
 it('tablet link should work',function(done){
 browser.navigate("http://www.advantageonlineshopping.com/#/ ");
 var tablets = browser.$(Web.Link({
 tagName: "DIV",
 innerText: "TABLETS Shop Now "
 }));
 tablets.click();
 var tablet2 = browser.$(Web.Image({
 alt: "",
 type: "normal",
 tagName: "IMG",
 index: 2
 }
 ));
 tablet2.click();
 whenDone(done);
 });

 afterEach(function(done){
 LFT.afterTest();
 whenDone(done);
 });
 after(function(done){
 whenDone(done);
 });
});

describe('2nd Inner describe',function(){
 var browser;
 before(function(done){
 whenDone(done);
 });
 beforeEach(function(done){
 LFT.beforeTest();
 LFT.SrfLab.launchBrowser({
 type: "Chrome",
 version: "60",
 osType: "Windows",
 osVersion: "10"
 }).then(function(b) {
 browser = b;
 });
 whenDone(done);
 });
 it('mice link should work',function(done){
 browser.navigate("http://www.advantageonlineshopping.com/#/ ");
 var mice = browser.$(Web.Link({
 tagName: "DIV",
 innerText: "MICE Shop Now "
 }));
 mice.click();
 var mice2 = browser.$(Web.Image({
 alt: "",
 type: "normal",
 tagName: "IMG",
 index: 1
 }
 ));
 mice2.click();
 whenDone(done);
 });
 afterEach(function(done){
 LFT.afterTest();
 whenDone(done);
 });
 after(function(done){
 whenDone(done);
 });
});
after(function(done){
 LFT.cleanup();
 whenDone(done);
});
});

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);

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
 }
 }
}