Write tests for a LeanFT grid

This topic explains how to write tests that can run using a LeanFT grid. The tests specify the environment capabilities they require, and the grid finds a connected node that matches those requirements.

Note: Currently supported only for tests written in Java.

Overview

A LeanFT test that runs using a grid is made up of the following parts:

// Describe the environment on which to run

// Launch your application or launch a browser and navigate to the application

// Perform operations on your application

// Verify the operation results

Before performing any testing operations, a test must get an environment to run them on, and launch an application or browser. After that, performing operations and verifying their results is the same whether you use using a grid or not.

This section describes how to describe the environment on which to run and how to launch your application or browser on that environment.

Tip: You can design all of your tests with a statement that describes an environment. This way, you can run the tests in a grid setup whenever needed. If you want to run the same test on a standalone LeanFT instead of a grid, you can provide an EnvironmentDescription parameter that does not specify any requirements.

Describe an environment and launch your application

This section describes how to describe the environment on which to run and how to launch your application or browser on that environment.

  1. Start your test with a statement that describes the required environment specifications:

    DesktopEnvironment env = EnvironmentFactory.get(environmentDescription);

    In the EnvironmentDescription, describe the environment capabilities this test requires. For details, see Build an environment description.

    EnvironmentFactory.get places a lock on a node that matches the environmentDescription, and returns an object that represents the selected environment.

  2. Use the DesktopEnvironment object to launch your application on the node:

    • Desktop applications:

      Aut calc = env.launchAut("C:\\Windows\\System32\\calc.exe");

      Note: Make sure your node is configured to enable LeanFT tests to launch desktop applications. For details, see Run desktop applications using LeanFT SDK.

    • Web applications: Launch a browser and navigate to your application.

      Browser browser = BrowserFactory.launch(browserDesc, env);
      browser.navigate("https://www.online-calculator.com");
      

      Note: Make sure the Functional Testing Agent extension is enabled in the relevant browser. For details, see Set up web browsers and controls.

    • SAP GUI session:

      GuiSession guisession = GuiSessionFactory.launch(launchInfo, env)

    For details, see:

  3. After launching your application on the requested environment, perform operations directly on the application, using the handle returned by the launch method.

If your test includes only browser operations

You can use BrowserFactory.launch statements without first requesting an environment. You can describe your environment directly in this step.

Use one of the following statements:

  • Browser browser = BrowserFactory.launch(browserDescription);
  • Browser browser = BrowserFactory.launch(browserType);

Provide a browserType or a simple browserDescription, in which case the grid looks for a node that has the requested browser, without checking for any other environment capabilities. Alternatively, you can add environment capabilities inside the browserDescription, describing the details of the node you want the grid to use. For details on environment capabilities, see Build an environment description.

BrowserFactory.launch runs the requested browser on a relevant node, places a lock on the node, and returns an object that represents the selected browser. You can use this object to perform operations on the launched browser.

If your test also needs to perform non-browser operations on the node, use EnvironmentFactory.get to request an environment. Then, use the returned environment object to launch the browser and perform other steps on the same node.

Back to top

Perform desktop operations on the node

To perform desktop operations on the same node, use the DesktopEnvironment env object you obtained above:

Operations API
Access a top-level window or dialog box on the node.

env.describe(type, description)

Access the node's keyboard device to perform low-level operations. env.getKeyboard()
Access the node's mouse device to perform low-level operations. env.getMouse()

Back to top

Build an environment description

The LeanFT grid finds a node for a test based on the node's capabilities and the test's environment description.

A node's capabilities are made up of:

  • Operating system type and version, which LeanFT detects automatically.

  • Available browsers and versions, configured in the node settings. For details, see Add-ins.

  • The add-ins loaded on the node, configured in the node settings. For details, see Add-ins.

  • Additional capabilities provided by the node, that you describe in name-value pairs similar to the ones in a test's environment description. Describe these capabilities in the node settings. For details, see Custom Capabilities.

  • The node's name.

In your test's environment description, describe the capabilities required for this test run in name-value pairs. For operating systems and browsers, use the strings described below. For custom capabilities, use name-value pairs that match the ones you defined in the node settings (not case-sensitive).

Capability Name Value
Operating system type osType One of: Windows, Linux, OSX
Operating system version osVersion

The operating system version.

You can describe the version using Semantic Versioning, and include conditions, such as > or < to specify "later than" or "earlier than".

Note: The latest token is not supported.

Browser type type See com.hp.lft.sdk.web.BrowserType.
Browser version version

The version number defined node's runtime engine settings.

You can describe the version using Semantic Versioning, and include conditions, such as > or < to specify "later than" or "earlier than".

Note: The latest token is not supported.

Node name name The node name defined in the node's runtime engine settings.

Tip:  

  • Use the Grid Management Console to see the capabilities of all the nodes currently connected to the grid.
  • Use a parameterized approach for environment descriptions. This enables easier maintenance and enables each run to specify different environment requirements.

Back to top

Modify existing tests to run on a LeanFT grid

If you have existing tests that were not designed to run using a grid, update them to start with an environment description.

Call EnvironmentFactory.get with an environment description. The LeanFT grid finds a node with the required capabilities, locks it, and returns an environment object.

Replace the following statements in your test with new statements that use the environment object. This specifies the environment on which to perform the steps:

Operation Old statement New statement
Launch desktop application Desktop.launchAut env.launchAut(application, optional application arguments)
Launch browser BrowserFactory.launch(browserDescription) BrowserFactory.launch(browserDescription, env)
Launch SAP GUI session

GuiSessionFactory.launch(<launch info parameters>)

GuiSessionFactory.launch(launchInfo, env)

Access a top-level window or dialog box on the node. Desktop.describe(type, description)

env.describe(type, description)

Access the node's keyboard device to perform low-level operations. Keyboard env.getKeyboard()
Access the node's mouse device to perform low-level operations. Mouse env.getMouse()

Back to top

Code samples of tests for a LeanFT grid

Lock a node as part of the launch browser step.

Call BrowserFactory.launch with a browser description that includes environment capabilities. This call locks a node with the described environment, launches the browser on the node, and returns a browser handle.

@Test
public void grid_LaunchBrowser_BrowserDescWithEnvDesc () throws GeneralLeanFtException {

    final String nodeOsType = "Windows";		// set this to the node OS type
    final String nodeOsVersion = "7";		// set this to the node OS version
    final String browserType = BrowserType.CHROME;	// set this to the requested browser type
    final String browserVersion = ">57";		// set this to the requested browser version

    // create a browser description object that includes also the required environment 
    BrowserDescription browserDesc = new BrowserDescription.Builder().build();
    browserDesc.set("type", browserType);
    browserDesc.set("version", browserVersion);
    browserDesc.set("ostype", nodeOsType);
    browserDesc.set("osversion", nodeOsVersion);

    // launch the browser (the required DesktopEnvironment will be locked for you behind the scenes)
    Browser browser = BrowserFactory.launch(browserDesc);
    
    // your test code goes here 

    browser.close();
}	

Lock a node and then launch a browser on that node.

Call EnvironmentFactory.get with an environment description. This calls locks a node with the described environment and returns an environment handle.

Call BrowserFactory.launch with a browser description and the environment handle to launch the browser on the locked node.

@Test
public void grid_LaunchBrowser_OnSpecifiedEnv() throws GeneralLeanFtException {

    final String nodeOsType = "Windows";		// set this to the node OS type
    final String nodeOsVersion = "7";		// set this to the node OS version
    final String browserType = BrowserType.CHROME;	// set this to the requested browser type
    final String browserVersion = ">57";// set this to the requested browser version

    // create an environment description object that includes required environment capabilities
    EnvironmentDescription envDesc = new EnvironmentDescription.Builder().build();
    envDesc.set("ostype", nodeOsType);
    envDesc.set("osversion", nodeOsVersion);

    // lock a matching desktop environment
    DesktopEnvironment env = EnvironmentFactory.get(envDesc);

    // create a browser description object that includes only browser description 
    BrowserDescription browserDesc = new BrowserDescription.Builder().build();
    browserDesc.set("type", browserType);
    browserDesc.set("version", browserName);

    // launch the browser on the locked desktop environment 
    Browser browser = BrowserFactory.launch(browserDesc, env);

    // your test code goes here 

    browser.close();
}				

Lock a node and perform operations on a desktop application.

Call EnvironmentFactory.get with an environment description. This calls locks a node with the described environment and returns an environment handle (env).

Call env.describe to specify the calculator application on the node, and then press its buttons.

@Test
public void grid_Describe_ClickOnDescribedObject() throws GeneralLeanFtException {

    final String nodeOsType = "Windows";		// set this to the node OS type
    final String nodeOsVersion = "7";		// set this to the node OS version


    // create capabilities map, convert it to environment description and lock a matching desktop environment
    Map<String,Object> capabilities = new HashMap<>();
    capabilities.put("osType", nodeOsType);
    capabilities.put("osversion ", nodeOsVersion);
    DesktopEnvironment env = EnvironmentFactory.get(EnvironmentDescription.fromMap(capabilities));

    // describe a window hierarchy under the desktop environment
    Window calculator = env.describe(Window.class, new WindowDescription.Builder()
        .childWindow(false)
        .ownedWindow(false)
        .windowClassRegExp("CalcFrame")
        .windowTitleRegExp("Calculator").build());


     // your test code goes here.

     // e.g. this is how you click on a button in the desktop application:
     Button btn = calculator.describe(Button.class, new ButtonDescription.Builder()
         .nativeClass("Button")
         .text("")
         .windowId(135).build());
     // click 
     btn.click();
}				

Lock a node and perform operations using the node's mouse.

Call EnvironmentFactory.get with an environment description. This calls locks a node with the described environment and returns an environment handle (env).

Call env.getMouse to gain access to the node's mouse and use it for operations.

@Test
public void grid_DeviceReplay_Mouse () throws GeneralLeanFtException {

    final String nodeOsType = "Windows";		// set this to the node OS type
    final String nodeOsVersion = "7";		// set this to the node OS version

    // create capabilities map, convert it to environment description and lock a matching desktop environment   
    Map<String,Object> capabilities = new HashMap<>();
    capabilities.put("osType", nodeOsType);
    capabilities.put("osversion ", nodeOsVersion);
    DesktopEnvironment env = EnvironmentFactory.get(EnvironmentDescription.fromMap(capabilities));

    // get Mouse to perform low-level mouse actions
    MouseDevice mouse = env.getMouse(); 


    // your test code goes here.

    // e.g. this is how you right-click on point:
    mouse.click(new Point(80,80), MouseButton.RIGHT);
}				

Back to top

See also: