Regular expressions in leanft in Java

To define the property values of a object, we can use the regular expressions. Below example shows how to use regular expressions to define the property values. Note that we are clicking on such a link with inner text matching regular expression .*Dev.*
 
package leanft;

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

public class RegularExpressionTest 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 link containing Dev substring
            browser.describe(Link.class, new LinkDescription.Builder()
                    .tagName("A").index(1).innerText(new RegExpProperty(".*Dev.*")).build()).click();

            //Wait until page loads
            Thread.sleep(3000);

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

We can also use regular expressions to specify values of object properties in Application Models.

Web development and Automation testing

solutions delivered!!