LeanFT

How to create Functional Mobile Test in LeanFT (UFT Pro) in Visual Studio Part II

This post is a part of our Mobile Testing series using HP Mobile Center. Please go to our previous articles in this series to learn about HP Mobile Center.

In this post, I will discuss how to create Functional Mobile Test in LeanFT (UFT Pro) in Visual Studio coding test objects manually. You can go to post detailing the process of connecting LeanFT (UFT Pro) to Mobile Center.

First of all, we have to connect to Mobile Center server to open application in device connected to Mobile Center to create Test Objects

Open Application Under Test (AUT) in Mobile Center 

  • To do that, click on Red Mobile Center Icon in Visual Studio Toolbar

MCIcon_LFT.png

  • If LeanFT is connected successfully to Mobile Center (as detailed in previous post), then the following box will appear:

MC_LFT.png

  • Then click on dotted button against Application and Device fields to choose Application and Device respectively
  • Select either Install Application OR Restart Application checkbox if selected application is not installed on the selected device and needs to be installed OR restarted

MC_LFT

  • Click on Launch button after selecting Device and Application. A window with selected device and application (AUT) opens for user to start capturing properties of the objects in the device

MC_App

Create Test Steps:

Now, we are ready to add/create objects of the Mobile Application in our LeanFT Test. We can do it in 2 ways:

  • Either adding test objects to Application Model
  • Capture Test Object properties using Object Identification Center (spy)

I have already covered creating Test Steps by adding Test Objects to Application Model in previous post. I will be covering creating Test Steps by coding Test Objects manually

  • Create new LeanFT MsTest Project
  • Add the following using statement
using HP.LFT.SDK.Mobile;
  • Click on Object Identification Center icon on the Visual Studio Toolbar

LFT_OIC

  • Using Object Identification Center, copy and paste the test objects description under Test Method section

MC_LFT_AM

  • Then, Code can be written using test objects description using the below hierarchy depending on the application type:

                       Native Application:
                       Device > Application > Test object

                       Mobile Web Application:
                       Device > Application > WebView > Page > Test object

  • First, the device should be locked using any of the methods (such as LockDeviceByName,LockDeviceById etc) of MobileLab class so that no other can use the device while test is getting executed
  • Device should be unlocked using unlock method of created device object so that it is free to use
//locking device
var device = MobileLab.LockDeviceByName("Vijay's Emulator");
//declaring test objects
IApplication app = device.Describe<IApplication>(new ApplicationDescription
{
 Identifier = @"com.hpswdemo.advantageinc",
 IsPackaged = false
});

IEditField usernameField = app.Describe<IEditField>(new EditFieldDescription
{
ClassName = @"Input",
ResourceId = @"com.hpswdemo.advantageinc:id/loginUserNameEditText",
MobileCenterIndex = 0
});

IEditField passwordField = app.Describe<IEditField>(new EditFieldDescription
{
ClassName = @"Input",
ResourceId = @"com.hpswdemo.advantageinc:id/loginPasswordEditText",
MobileCenterIndex = 1
});

IButton loginButton = app.Describe<IButton>(new ButtonDescription
{
Text = @"LOGIN",
ClassName = @"Button",
ResourceId = @"com.hpswdemo.advantageinc:id/loginButton",
MobileCenterIndex = 0
});
//Installing and Launching Application
app.Install();
app.Launch();

//Enter Username and Password
usernameField.SetFocus();
usernameField.Tap();
usernameField.SetText("testuser");
passwordField.Tap();
passwordField.SetSecure("password");

//Tap Login Button
loginButton.Highlight();
loginButton.Tap();

//Unlock Device
device.Unlock();

 

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s