LeanFT Java Tutorial Part 9 – Using LeanFT and Selenium Together !

I don’t want to debate which tool is better, of course both tools have their advantages and disadvantages. So lets use all the advantages together in a mega script which uses both technologies. For doing this, you have to:-

  1. Create a LeanFT JUnit Project in Eclipse.
  2. Download Selenium Libraries from here and extract to a desired location.
  3. In your Eclipse project, right click the Project name and goto Build Path -> Configure Build Path.
  4. Click on Add External Jars option and add the selenium-java-{version}.jar from the extracted location.
  5. Also add all the jars in the libs folder.
  6. If you are working with Chrome, you need to additionally download the chromedriver.exe from here.
  7. Now the setup is done, you can get your hands dirty with the following code:-

package l2a;
import static org.junit.Assert.*;
import java.io.File;
import org.junit.*;
import com.hp.lft.sdk.*;
import com.hp.lft.sdk.web.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import unittesting.*;

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 leanFTSelenium()
 {
 try
 {
 //Setting the Path for Chrome Driver
 System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
 
 //Adding the Chrome Extension for LeanFT
 ChromeOptions CO = new ChromeOptions();
 CO.addExtensions(new File("C:\\Program Files (x86)\\HP\\LeanFT\\Installations\\Chrome\\Agent.crx"));
 
 //Launching Chrome with Selenium 
 WebDriver driver = new ChromeDriver(CO);
 
 //Navigating to Google
 driver.navigate().to("https://www.google.com");
 
 //Attaching to the Browser with LeanFT
 Browser browser = BrowserFactory.attach(new BrowserDescription.Builder()
 .type(BrowserType.CHROME).build());
 
 //Navigating to Learn2Automate on the same browser instance
 browser.navigate("https://learn2automate.wordpress.com");
 
 }
 catch(Exception ex)
 {
 ex.printStackTrace();
 Assert.fail("Unexpected Error occurred - " + ex.getMessage());
 }
 }

 

After writing the above code, your “browser” and “chromeDriver” objects are pointing to the same browser instance. You can now use both objects interchangeably in your script, this essentially means you can write either Selenium or LeanFT code for performing an action on your browser. Talk about Flexibility !

For more information on using Selenium in Java, you can refer many blogs that write about it.

Happy Automating!
Harshit Kohli

Advertisements

Eat, Sleep, Automate. REPEAT !

Tagged with: , , , ,
Posted in LeanFT
12 comments on “LeanFT Java Tutorial Part 9 – Using LeanFT and Selenium Together !
  1. […] LeanFT Java Tutorial Part 9 – Using Selenium and LeanFT Together ! […]

  2. This is awesome. Great series of posts, I’ll start working on this pretty soon. Thank you!

  3. Ismail says:

    Hi,
    First of all,thanks for a good leanft blog. I’ve two question about leanFT, but not about this topic.

    1- How can I switch frame using LeanFT?
    2- How can I automated Oracle Forms applications?

    Thanks.

    • Hi Ismail,

      Following are the answers to your questions:-

      1. You don’t need to switch frame in LeanFT. What you need to do is call the command – BrowserFactory.attach() which takes the browser description and returns a Browser object that you can work with.

      2. You need to check the documentation whether LeanFT supports Oracle Forms applications. In case you have an HP license, you can log in to HP and see the Product Availability Matrix. FYI, latest version is 14. In case, it supports, you need to right click the LeanFT Runtime engine from the task bar(bottom right corner) and select Settings where you will be able to see the add-ins available. Select Oracle Forms and restart the engine.

      Happy Automating !
      Harshit Kohli

      • Ismail says:

        Hi,
        Thanks alot.

        1- I tried BrowserFactory, but not worked. What’s wrong?

        Browser customerFrame = BrowserFactory.attach(new BrowserDescription.Builder()
        .url(“http://asab-sb-test.xyz/ie/portlet/customerSearchCC.do?widgetNo=24”).build());

        System.out.println(“New Frame added”);

        EditField txtCustomerID = customerFrame.describe(EditField.class,
        new EditFieldDescription.Builder().id(“txtGlbCustomerSearch”).build());

      • Ismail says:

        Error Detail : com.hp.lft.sdk.ReplayObjectNotFoundException: attachApplication
        Done

      • It seems that the object properties are not correct. Can you try highlighting the browser once you attach ?

  4. Ismail says:

    Yes I tried it. In simple mode, I saw highlighting success; but when I switched from simple mode to Edit mode, highlighting not working. I changed properties and then tried again; but problem not resolved. And When I copied & paste code, IOC only generated “browser;”

  5. Daragh says:

    Hi there. Great tut !!!. I was wondering, is it possible to parallel test with the leanFT like we do with Selenium grid. Cheers

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

Blog Stats
  • 168,130 hits
Categories

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

Join 796 other followers

%d bloggers like this: