LeanFT C# Tutorial Part 4 – Application Models

There are two ways in which we can specify the properties of the objects that will be used in our script:-

1. Descriptive Programming – This is the approach that was demonstrated in the previous tutorial where we specified the object’s properties in the TestMethod itself(by copying the object properties on the clipboard).

2. Application Model – Application Model is to LeanFT, what object repository is to UFT. Simply put together, its a collection of Test objects that we can use in our scripts. It acts as a centralized repository which can be shared across different scripts.

Which approach is better is a very subjective question and I will leave that to you to figure out which suits you best. Here is how we can create Application Models in LeanFT:-

1. Either create a completely new LeanFT Application Model Project(by going to File-> New Project-> Test) or Add a new Application Model Project to your solution(right click on Project in Solution explorer and add LeanFT-> Application Model).

2. Define the name of the model as well as a class name. Once the Application Model tsrx file is created, you can start adding objects to it.

3. There are two ways in which we can add the objects:-

a) Specify the object type and properties explicitly by clicking on the + icon on the top left corner:-

AppModel1

b) Open the Object Identification center and after selecting the appropriate object, click on the add to App Model icon :-

AppModel3

After you have the required objects in the Application Model, you can refer to these objects using intelli-sense in the TestMethod code that you can write:-

AppModel4

So this is how you can add objects to the application model and use them in your scripts.

Happy Automating !
Harshit Kohli

Tagged with: , , , , , , , , , , , , ,
Posted in Tutorials

LeanFT C# Tutorial Part 3 – Object Identification Center

LeanFT’s object identification center offers features that can give UFT’s object spy a run for its money !

You can invoke it by clicking the “HAT” icon on the Visual Studio toolbar. After the Spy has opened, you can click on the Start Spying button to spy on a particular object.

In the below example, I spied on the Google search button on the google homepage and it shows all the properties of the button:-

Object Identification Center

 

After I click on the Sort by Recommended button as well as Edit Mode button, I will get check boxes in front of each property so that I can select which ones I will be using:-

Using Regular Expressions

As you can see above, clicking on the “STAR” icon on the right of a property will make it as a regular expression and we can use the standard ones like .* and others.

After we are done with the property selection, we can click on the highlight button to check whether the properties are fine or not. A New feature here is that if there are multiple objects matching the description, LeanFT will highlight all the objects rather than giving an error.

So now we have decided the properties and confirmed by highlighting, its time to click the Generate code button which will copy the C# equivalent of the code to our clipboard and we can readily use this in the test.

The code will be something like:-


browser.Describe<IButton>(new ButtonDescription
{
ButtonType = "submit",
TagName = "INPUT",
Name = As.RegExp(".*Search.*")
});

Note: In case you are using Java as your preferred language, then you can change the settings to Java and the generated code will be in Java.

LeanFT C# Tutorial Part 4 – Application Models

Happy Automating !

Harshit Kohli

Tagged with: , , , , , , , , , , ,
Posted in Tutorials

LeanFT C# Tutorial Part 2 – Create First Test

In case you missed on part 1, check it out here.

Now that we are familiar with the code skeleton, we can start writing our first test. I’m taking a basic scenario where we are searching for leanft on my blog. For doing this, I have placed the browser initiation code in the TestInitialize method so that before execution of each test, a new instance of the browser is launched:-


[TestInitialize]
public void TestInitialize()
{
browser = BrowserFactory.Launch(BrowserType.InternetExplorer);
}

Here, BrowserFactory is a namespace provided by LeanFT’s SDK. The Launch method can be used to launch either IE, Chrome or Firefox. For version support, you can have a look at the availability matrix here (you will need an HP Passport for this).

Here’s the code for the test method:-


[TestMethod]
 public void TestMethod1()
 {
 try
 {
 //Set reporter to take all snapshots
 Reporter.SnapshotCaptureLevel = HP.LFT.Report.CaptureLevel.All;

 //Navigate to Search Engine
 browser.Navigate("www.duckduckgo.com");

 //Search for Learn2Automate blog
 IEditField txtSearch = browser.Describe<IEditField>(new EditFieldDescription
 {
 Type = "text",
 TagName = "INPUT",
 Name = "q"
 });
 txtSearch.SetValue("learn2automate");

 IButton btnSearch = browser.Describe<IButton>(new ButtonDescription
 {
 ButtonType = "submit",
 TagName = "INPUT",
 Name = "S"
 });
 btnSearch.Click();


 //Select the first search result
 ILink firstResult=browser.Describe<ILink>(new LinkDescription
 {
 TagName ="A",
 InnerText = As.RegExp(".*learn2automate.*"),
 Index = 0
 });

 Assert.IsTrue(firstResult.Exists(10));

 firstResult.Click();

 //Search for LeanFT if the blog opens
 IEditField searchBox = browser.Describe<IEditField>(new EditFieldDescription
 {
 Type = "text",
 TagName = "INPUT",
 Name = "s"
 });

 Assert.IsTrue(searchBox.Exists(10));

 searchBox.SetValue("leanft");

 IButton goButton=browser.Describe<IButton>(new ButtonDescription
 {
 ButtonType = "submit",
 TagName = "INPUT",
 Name = "Go"
 });

 goButton.Click();

 //Verify that the blog entry with title LeanFT opens
 ILink blogResult = browser.Describe<ILink>(new LinkDescription
 {
 TagName = "A",
 InnerText = As.RegExp(".*leanfT.*"),
 Index = 0
 });

 Assert.IsTrue(blogResult.Exists(10)); 
 blogResult.Highlight();

 
 }
 catch(Exception e)
 {
 Reporter.ReportEvent("Look for LeanFT on Lean2Automate", e.Message);
 }
 
 }

Lets understand it now. First of all we start with the try block. If you have been using UFT, you must be familiar with the pain of using the old school “On Error Resume Next”, so we can counter that here by using try catch block.

The first line of the code sets the SnapshotCaptureLevel to All, which essentially means that the HTML report generated at the end of the execution will have a corresponding snapshot for each operation(like click etc) that we perform in our test.

Then we are using the good old navigate function on the browser object that we created in the Test Initialize method. For this example, I have navigated to a search engine called Duck Duck Go.

After that, we create the edit box object where we will set the search term that we are looking for. In case you want to learn how we can create this statement. You should check out my post on using LFT’s Object Spy.

After setting the search term and clicking on the go button, I create the description for the result object and put in an assertion like this –  Assert.IsTrue(firstResult.Exists(10)). Please note that this assertion enables me to exit the test method if the firstResult object is not found in a matter of 10 seconds.

Similar to the above approach, upon clicking the first result, I look for the search button on my blog and look for the term leanFT and verify the search result similarly. You must have noticed that LFT does not have any explicit wait statement, but we have to use the exists method on an object to do the synchronization.

Lastly, I have closed the browser in the TestCleanUp method so that the browser gets closed after the test method finishes execution:-


[TestCleanup]
public void TestCleanup()
{
browser.Close();
}

I hope by now you are able to create a basic script in LeanFT. If you have doubts, feel free to comment !

LeanFT C# Tutorial Part 3 – Object Identification Center

Happy Automating,

Harshit Kohli

Tagged with: , , , , , , , , ,
Posted in Tutorials

LeanFT C# Tutorial Part 1 – Introduction

If you are looking for a basic overview of LeanFT, You can check out my post here.

This tutorial will basically get you started with the tool and further things will be covered after that. You will notice that LeanFT uses more or less the same concepts that UFT does but with a better IDE and a cleaner approach.

In case you don’t have LeanFT installed on your machine, you can either install a standalone version of LeanFT or use the bundled version which comes with UFT 12.5. While installing, please make sure you select Visual Studio 2012/2013 depending on which version of Visual Studio you have installed on your machine.

Once the installation is sorted, when you launch Visual Studio, and create a new project, you should see 3 types of LeanFT projects available to you under the Test projects section. These are :-

  1. LeanFT Application Model Project – An application model is LeanFT’s way of saying Object Repository(referring to UFT concept here). You should create this project if you want to create a collection of objects of your AUT (read Application under test).
  2. LeanFT MSTest Project – This is a Unit Test project based on MSTest. You can know more about MSTest from here.
  3. LeanFT NUnit Project – This is a Unit Test project based on NUnit. You can know more about NUnit from here.

Once you have made up your mind about which framework to use (MSTest vs NUnit), you can create your first LeanFT Project. I have used MSTest for the purpose of this tutorial.

Once you create a new project, it should be something like :-


using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;

namespace LeanFtTestProject1
{
[TestClass]
public class LeanFtTest : UnitTestClassBase<LeanFtTest>
{
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
GlobalSetup(context);
}

[TestInitialize]
public void TestInitialize()
{

}

[TestMethod]
public void TestMethod1()
{
}

[TestCleanup]
public void TestCleanup()
{
}

[ClassCleanup]
public static void ClassCleanup()
{
GlobalTearDown();
}
}
}

Lets look at the code line by line and understand it. Firstly we are importing the System namespace for obvious reasons. Then the Microsoft.VisualStudio.TestTools.UnitTesting namespace which gives us support for Unit Testing features offered by Visual Studio( like assertions, test methods etc). Then the HP.LFT.SDK which provides LeanFT’s sdk for Functional Testing.

[TestClass] – This attribute defines a Unit Test class which is a collection of [TestMethod] (s). Our LeanFTTest class is inherited from the UnitTestClassBase which is part of the LeanFT template and present in the UnitTestClassBase.cs file in the solution. It contains the definitions for the GlobalSetup and GlobalTeardown functions present in our Test class.

[ClassInitialize] – This attribute contains the method which gets executed when the class is instantiated.

[TestInitialize] – This attribute contains the method which gets executed before each [TestMethod].

[TestMethod] – This attribute contains the definition of a unit test method.

[TestCleanup] – This attribute contains the method which gets executed after each [TestMethod].

[ClassCleanup] –  This attribute contains the method which gets executed when the class is destroyed.

Now that we have the basic setup in place. Lets write our first test case using LeanFT in the next post :-

LeanFT C# Tutorial Part 2 – Create First Test

Happy Automating !

Harshit Kohli

 

Tagged with: , , , , , , , , ,
Posted in Tutorials

LeanFT – Lets call it “CleanFT” !

HP – Thank You ! From the bottom of my heart :) You have heard the cries of all QTP/UFT developers who demanded nothing but a clean IDE.

So Whats LeanFT ?

In simple words, its offering UFT’s capabilities in a different IDE( read Visual Studio/Eclipse)

Who is it for ?

Its mainly for Test Automation Engineers, Developers and Dev/Ops or Continous Testing teams. On the contrary, UFT’s intended audience comprises of Business Analysts, SME’s, Test Automation Engineers as well as Manual QA’s.

How does it help ?

As a UFT coder, I used to dream of working in a more structured environment because of my exposure to Visual Studio. The dream has become a reality ! Moving from a scripting to a programming language has its own advantages from the code stability standpoint. Moreover, its continuous integration features are a blessing for the agile world that we live in.

Is it a Selenium Killer ?

Its too early to comment on that but it can certainly give it a run for its money !

What are the key features ?

  1. Currently it supports standard Windows objects, .NET Windows Forms, WPF, Mobile objects, SiebelUI, Insight Image Recognition where HP UFT supports 20+ test platforms. So it doesn’t replace but compliment UFT.
  2. Supports MSTest & Nunit Frameworks for Visual Studio and JUnit for Eclipse.
  3. Compatible with Jenkins(continous integration) and Cucumber(BDD).
  4. Its object spy will make UFT’s spy a little jealous !
  5. Has some cool features inherited from UFT like Insight Object and Visual Relation Identifiers.
  6. The transition from UFT to LeanFT is not very bumpy as the core concepts remain same.

How can I get it ?

If you have a UFT license, you will have to upgrade to UFT 12.5 and LeanFT comes bundled with that. The standalone version can be downloaded from here.

Where can I learn it from ?

As of now there is very little information apart from the documentation

Check out my LeanFT C# Tutorial !

 

Happy Automating,

Harshit Kohli

Tagged with: , , , , , ,
Posted in Tutorials

Browser Functions not getting invoked in InPrivate Browsing Mode of IE?

Recently, I came across a situation in which I have to automate some scenario on private browsing mode of Internet Explorer (known as InPrivate Browsing). Although browser was getting identified in that mode, browser methods (like navigate,refresh etc) were not working (not throwing any error). After some searching, I came to know that in InPrivate Browsing Mode, all the extensions and add-ins are disabled due to which BHOManager Class Add-In is also disabled.

To enable browser methods in InPrivate mode of Internet Explorer, we need to enable add-ins. To do that, follow the below steps:

  • Go to Tools > Internet Options and click on Privacy tab.
  • Under the InPrivate section, uncheck the option that says ‘Disable toolbars and extensions when InPrivate Browsing starts’.
  • Click on OK button and start InPrivate session.

Image

Tagged with: , , , , , ,
Posted in Awesum Stuff

How to fix missing menu options in QTP

Many times menu items in QTP don’t show and appear blank (shown in below screenshot)

Image

Today, we’ll see how to fix this issue. To fix this issue:

  • Right click on the toolbar (where File, Edit, View etc menu is appearing) and click on Customize option

Image

  •  Click on Restore All in Toolbars tab:

Image

Isue will be fixed :)

Tagged with: , , , , , ,
Posted in Common Issues
Blog Stats
  • 74,404 hits
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 691 other followers

Follow

Get every new post delivered to your Inbox.

Join 691 other followers

%d bloggers like this: