Setting up IntelliJ Project in leanft in Java

In this topic, we will see how to set up a LeanFT project in IntelliJ IDEA. We can create a new LeanFT project in 2 ways.
  • Using LeanFT templates
  • Custom framework
If you have installed the LeanFT plugin for IntelliJ IDEA, you can create new project from templates as shown in below image. Note that we can create a project based on 4 types of templates.To create your own custom framework, you will have to initialize and clean up SDK as shown in below example. Note that in all upcoming examples, we have inherited BaseTest class.
 
package leanft;

import com.hp.lft.report.Reporter;
import com.hp.lft.sdk.ModifiableSDKConfiguration;
import com.hp.lft.sdk.SDK;
import org.junit.After;
import org.junit.Before;

import java.net.URI;

public class BaseTest {

    @Before
    public void test() throws Exception{
        ModifiableSDKConfiguration config = new ModifiableSDKConfiguration();
        config.setServerAddress(new URI("ws://localhost:5095"));
        SDK.init(config);
        Reporter.init();
    }

    @After
    public void clean() throws Exception{
        Reporter.generateReport();
        SDK.cleanup();
    }
}

Then we can write test methods as shown in below example.
 
package leanft;

import com.hp.lft.report.Reporter;
import com.hp.lft.report.Status;
import com.hp.lft.sdk.ModifiableSDKConfiguration;
import com.hp.lft.sdk.SDK;
import com.hp.lft.sdk.web.*;
import com.hp.lft.sdk.web.EditField;
import com.hp.lft.sdk.web.EditFieldDescription;
import org.junit.Test;

import java.net.URI;

import static org.junit.Assert.assertEquals;

public class ChromeTest extends BaseTest {

    @Test
    public void test() throws Exception{

        Browser browser = BrowserFactory.launch(BrowserType.CHROME);
        try{
            //Navigate to https://www.softpost.org/selenium-test-page/
            browser.navigate("https://www.softpost.org/selenium-test-page/");
            browser.sync();

        }
        catch(AssertionError ex){
           //Report the Exception
           Reporter.reportEvent("Exception","Test failed", Status.Failed, ex);
           throw ex;
        }
        finally{
            //Close the browser
            browser.close();
        }
    }
}      

Web development and Automation testing

solutions delivered!!