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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s