Record and run LeanFT tests remotely

This topic 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.

    For details, see Manage remote access.

  2. In UFT Pro (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). However, you can select this option in order to ignore certificate errors.
    Show remote access window when the test runs

    Select to enable watching your test runs on the 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.

Back to top

Edit your UFT Pro (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.

For more details, see Capability reference and the UFT Pro (LeanFT) SDK references:

Java | JavaScript | C#

LeanFT SDKs

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

For details, see the UFT Pro (LeanFT) SDK references:

Java | JavaScript | C#

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.

For details, see the LeanFT code samples for remote testing:

Java | JavaScript | C#

Back to top

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.

For details, see Add Applitools code to your LeanFT script.

Back to top

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. For details, see Configure the connection to SRF.

  1. From your IDE menu, click LeanFTLaunch 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. For details, see Object Identification Center and Test Recorder.
  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.

Back to top

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. For more details, see the LeanFT Help Center.

Test results are displayed both in the LeanFT run report, and in SRF. For more details, see Run SRF tests and analyze results.

Back to top

LeanFT code samples for remote testing

Select the environment you want to view samples for:

JavaClosed

JavaScriptClosed

C#Closed

 

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 the BrowserFactory.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 UFT Pro (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
  }
 }
}				

Back to top

See also: