Cucumber in leanft in Java

We can integrate LeanFT tests with Cucumber BDD framework. If you know how to use JUnit with Cucumber, you will find it very easier to integrate LeanFT with Cucumber. Please follow below steps to integrate the LeanFT with Cucumber.
  • Create a maven project using LeanFT template
  • Add cucumber and selenium dependency in POM.xml
  • Write feature files and scenarios
  • Write the step definitions for steps in Scenario
  • Execute feature file
Here is the dependency that you will have to add for cucumber.
 
        <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.4</version>
        <scope>test</scope>
    </dependency>
Then you have to create a feature file as shown in below example.
 
Feature: My feature

Scenario: My Scenario
  Given I am on www.softpost.org page
  Then I verify that title contains tutorial word
After that you can create step definitions as shown in below example.
 
package org.softpost;

import com.hp.lft.report.Reporter;
import com.hp.lft.sdk.ModifiableSDKConfiguration;
import com.hp.lft.sdk.SDK;
import com.hp.lft.sdk.web.Browser;
import com.hp.lft.sdk.web.BrowserFactory;
import com.hp.lft.sdk.web.BrowserType;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import org.junit.Assert;

import java.net.URI;

/**
 * Created by Sagar on 23-07-2016.
 */
public class Steps {
    Browser browser;
    @Before
    public void init() throws Exception{
        ModifiableSDKConfiguration config = new ModifiableSDKConfiguration();
        config.setServerAddress(new URI("ws://localhost:5095"));
        SDK.init(config);
        Reporter.init();
    }

    @Given("^I am on www\.softpost\.org page$")
    public void i_am_on_www_softpost_org_page() throws Throwable {
        browser = BrowserFactory.launch(BrowserType.CHROME);
        browser.navigate("https://www.softpost.org");
    }

    @Then("^I verify that title contains tutorial word$")
    public void i_verify_that_title_contains_tutorial_word() throws Throwable {
        Assert.assertTrue(browser.getTitle().toLowerCase().contains("tutorial"));
    }

    @After
    public void clean() throws Exception{
        browser.close();
       SDK.cleanup();
    }
}                   

Complex problems, Simple Solutions