Using Native Object properties and methods in LeanFT

Below example illustrates how to access native object properties in LeanFT. In below example, we have set the value in edit box using native value property. We have also used native click method to click on Home link.

package leanft;

import com.hp.lft.report.Reporter;
import com.hp.lft.report.Status;
import com.hp.lft.sdk.NativeObject;
import com.hp.lft.sdk.web.*;
import org.junit.Test;

import java.util.List;

public class ChromeNativeObjectTest 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");


            //get native object
            NativeObject obj = browser.describe(EditField.class,new EditFieldDescription.Builder()
                    .id("fn").build()).getNativeObject();

            //list native members of the object
            List<String> list = obj.getMembers();

            for (String  s : list  ) {
                System.out.println(s);
            }

            obj.setProperty("value","Native");

            Thread.sleep(3000);

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

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

You may also like...