Web app testing in leanft in Java

Here is the first web application test using LeanFT. In below code, we are launching the chrome browser and then navigating to https://www.softpost.org/selenium-test-page/. After that we are entering value in edit box and clicking on Home link. Same code will work on other browsers (Firefox, Internet Explorer, Edge) as well. To launch other browsers, you just need to change the browser type in launch method.
 
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();

            //set value in edit box
            browser.describe(EditField.class,new EditFieldDescription.Builder()
            .id("fn").build()).setValue("Sagar");

            //click on Home link
            browser.describe(Link.class, new LinkDescription.Builder()
                    .tagName("A").innerText("Home").build()).click();

            //Wait until page loads
            browser.sync();

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

Note that BaseTest class provides code to initialize and clean up the LeanFT SDK.
 
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 init(){
        try {
            ModifiableSDKConfiguration config = new ModifiableSDKConfiguration();
            config.setServerAddress(new URI("ws://localhost:5095"));
            SDK.init(config);
            Reporter.init();
        }catch (Exception ex){
            System.out.println("Exception occured " + ex.toString());
        }
    }

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

Web development and Automation testing

solutions delivered!!