# Add SDK test object steps to your tests

To run steps on your application, create steps containing LeanFT test objects, methods, and properties.

In this topic:

## SDK test objects vs the Object Identification Center(OIC)/Application models

The Application Model editor and OIC enable you to generate test object description code automatically. Alternatively, you can write out your test object description code programmatically.

- After creating a programmatic description for a LeanFT test object, create steps that will perform operations or retrieve values from your application objects. Use IntelliSense (for C# or Java) to select the relevant test object methods or properties.
- You can check whether your application looks and acts as expected, using LeanFT Verification methods. For details, see Verifications.
- If the test object methods and properties for an object do not provide the functionality you need, you can access the native properties and methods of an object. For details, see Access native objects, methods, and properties.
- Make use of standard code and the capabilities provided by the testing framework you chose, together with LeanFT SDK code to create comprehensive tests that cover all aspects of your application.

Back to top

## Code programmatic test object descriptions

To create programmatic test object descriptions in your test, follow the steps below:

1. At the top of your test file, specify the SDK elements you plan to use by providing the required statements:

   Language | File | Statement
   --- | --- | ---
   C# | .cs | using
   Java | .java | import
   JavaScript | .js | var

   For example, if you want to create steps using the LeanFT core SDK as well as Web and Standard Windows technology objects, use the following:

   C#

       using HP.LFT.SDK;
       using HP.LFT.SDK.Web;
       using HP.LFT.SDK.StdWin;

   Java

       import com.hp.lft.sdk.*;
       import com.hp.lft.sdk.web.*;
       import com.hp.lft.sdk.stdwin.*

   If you prefer, you can specify each object you plan to use. For example:

       import com.hp.lft.sdk.WaitUntilTestObjectState.WaitUntilEvaluator;
       import com.hp.lft.sdk.stdwin.Window;
       import com.hp.lft.sdk.stdwin.WindowDescription;

   JavaScript

       var LFT = require("leanft");
       var SDK = LFT.SDK;
       var Web = LFT.Web;
       var expect = require("leanft/expect");
       var whenDone = LFT.whenDone;

   For more details, see Setting up and working with the JavaScript SDK.

2. Determine the top-level parent object for your test, depending on the application type:

   Web-based applications | The browser is the top-level parent test object. You use the BrowserFactory.Launch method to create to create a new instance of the Browser test object. Tip: You can alternatively use the BrowserFactory.Attach method to instruct LeanFT to run steps on an existing open browser. This also creates a Browser test object instance.
   Windows-based applications | A window or dialog box is the top-level test object. You use the Desktop.Describe method to create a Window or Dialog test object.
   Mobile applications | The device is the top-level test object. Use one of the MobileLab.LockDevice* methods to create an instance of the Device test object.
   SAP GUI for Windows applications | The SAP GUI session is the top-level test object. You use the GuiSessionFactory.Launch method to create a new instance of the GuiSession test object. Tip: You can alternatively use the GuiSessionFactory.Attach method to instruct LeanFT to run steps on an existing open SAP GUI session. This also creates a GuiSession test object instance.

3. Determine the test object hierarchy for the test object. Most objects will have a minimum of a two level hierarchy, but in some cases you may need to, or choose to, provide a deeper hierarchy.
   Possible hierarchies could be: `browser> page > edit` or `window > button`.

   You can use the OIC to view the recommended hierarchy for a specific object. For details, see Object Identification Center.

   Create each test object as a child of the relevant parent object.

4. Determine the set of properties you want to use to describe your object.

   Tip: Use the OIC to find the available test object properties and current values for the object in your application.

   From the OIC, you can also copy the code for a test object description to the clipboard and paste it into your test.

   For details, see Object Identification Center

5. Create a new child object using the Describe method (C#/Java) /.$ (JavaScript) and the corresponding `<TestObjType>Description` object (C#/Java) that provides access to the relevant identification properties. Then provide property-value pairs that uniquely identify the object.

   The basic syntax is as follows:

   C#

       var MyVar=ParentObject.Describe<ITestObjType>(new TestObjTypeDescription
       {
           Prop1=Value1,
           Prop2=Value2,
           Prop3=Value3,

       });

   For example:

       var keyboardLink = testBrowser.Describe<ILink>(new LinkDescription
       {
       TagName = "A",
       InnerText = "Computer Keyboards"
       });

   Java

       MyVar = parentObject.describe(TestObjType.class, new TestObjTypeDescription.Builder()
       .prop1(value1).prop2(value2).prop3(value3).build());

   For example:

       mylink = browser.describe(Link.class, new LinkDescription.Builder()
       .tagName("A").innerText("Business Travel @ About.com").build());

   JavaScript

   You can use the property bag or builder notation:

       parent.$(TestObjType({
           prop1:value1,
           prop2:value2,
           prop3:value3,
             }
             ));

   or

       parent.$(TestObjType().prop1(value1).prop2(value2).prop3(value3))

   For example:

       browser.$(Web.Edit({
             type:"text",
             tagName:"INPUT",
             name:"userName"
             }
             ));

   or

       browser.$(Web.Edit().type("text").tagName("INPUT").name("userName"))

   For more details, see Setting up and working with the JavaScript SDK.

   To specify a property value using a regular expression, use the following syntax:

   C# | `IDProp = As.RegExp(@"RegExpValue")`
   Java | `.idProp(new RegExpProperty("RegExpValue")`
   JavaScript | `idProp:/RegExpValue/`

Note: When comparing String values in a description with the property values in the application’s objects, LeanFT trims leading and trailing spaces from both values.

When comparing regular expressions in a description with String values in the applications objects’ properties, LeanFT trims leading and trailing spaces only from the value in the application.

Back to top

## Regular expression guidelines

When using regular expressions in test object descriptions, follow these guidelines :

- For C# and Java, specify regular expressions using VBScript regular expression syntax. For example, to indicate any number of characters in a string, use .* and not just the * expression.

- For JavaScript, use standard JavaScript syntax. However, option flags are not supported and will be ignored.

- By default, all regular expressions in descriptions are anchored to the beginning and end of the search string.

- Regular expressions are not supported for Mobile test objects.

Back to top

## Secure sensitive information

When a test must contain sensitive information, such as user names or passwords, to access the application being tested, you can use the LeanFT SDK to make this sensitive data harder to access.

1. Use the Password Encoder tool to generate an encoded string resembling a mix of jumbled characters. This prevents the password from appearing in cleartext.

   Caution: The Password Encoder tool does not use a global standard for encryption. It is not considered nor is it intended to be secure. Its only purpose is to ensure that passwords will not appear in cleartext while editing or running a test. The actual passwords and/or data are stored with your test's source code. If you are using real customer data or other sensitive information, you should take additional steps to ensure the security of that data.

   Run the Password Encoder tool as follows:

   Windows | From the LeanFT Start menu In your IDE after installing the LeanFT plugin: LeanFT > Tools menu
   Mac/Linux | In Terminal: Change to the <LeanFT installation>/Tools directory Run ./password-encoder <password-to-encode> [-me], where <password-to-encode> is the password you want to encode.

2. When entering a password into a password field, use the generated string as the argument for a <TestObject>.SetSecure step (instead of the normal Set method). This hides the password, preventing it from being displayed in cleartext, but does not fully secure the password.

   For usage details, see the relevant SDK Reference.

Back to top

## Run desktop applications using LeanFT SDK

You can write test code to launch a desktop application using the launchAut() method. This method is available in all LeanFT SDKs (.NET, Java, and JavaScript). For security reasons, in order to launch an application using this method, you must add the application and the format in which you are running it to a whitelist file.

If this is your first time using the launchAut() method, you need to create the whitelist file. If you have already created the file, add the new applications to the file. In either case, review the File format section for instructions.

Note: You must restart the LeanFT engine after you add an AUT to the autConfig.json file. For details, see Start/Stop the runtime engine.

To create a whitelist file

Create a file called autConfig.json in the following location:

Linux | ~/.leanft/config
Mac | ~/Library/Application Support/LeanFT/config
Windows | %localappdata%\LeanFT\config\

File format

The file is in JSON format.

Objects

allowedAuts | Includes the applications that you want to launch using the launchAut() method. If you want to launch the same application in different ways, make sure to add an entry for each way.
fileName | The application name. You can specify the name only, with or without the extension, the relative path or the full path.
args | An array of arguments. For example, command line arguments.
workingDirectory | The current working directory of the application.

The following is an example of an autConfig.json file. It demonstrates different ways for specifying a desktop application.

    {
        "allowedAuts": [
            {
                "fileName": "C:\\Windows\\System32\\calc.exe"
            },
            {
                "fileName": "mspaint.exe"
            },
            {
                "fileName": "mspaint",
                "args": ["C:\\devTools\\img\\2.png"]
            },
            {
                "fileName": "mspaint",
                "args": ["1.png"],
                "workingDirectory": "C:\\devTools\\img"
            }
        ]
    }

This file corresponds to the following launchAut() implementations:

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

    Aut mspaint1 = Desktop.launchAut("mspaint.exe");

    Aut mspaint2 = Desktop.launchAut("mspaint", "C:\\devTools\\img\\2.png");

    Aut mspaint3 = Desktop.launchAut("mspaint", new String[] {"1.png"}, "C:\\devTools\\img");

You can find launchAut() code samples here:

- .NET: Launch AUT code samples
- Java: Launch AUT code samples
- JavaScript: Launch AUT code samples

Back to top

See also:

- Device level operations
- Test object description examples
- Application models
- Setting up and working with the JavaScript SDK
- LeanFT .NET code samples
- LeanFT Java code samples
- LeanFT JavaScript code samples
- LeanFT for Selenium

https://admhelp.microfocus.com LeanFT 8942
Tips to improve your search results...TOC Lean Functional Testing Help Center LeanFT Help Center 14.50 - 14.53 All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version:(Undefined variable: _rscC_Basic_Variables.FloatingTocShow)