Assertions in leanft in Java

We can do assertions in LeanFT using Verify class in Validations namespace. This class allows you to put the assertions in the code. Here is the sample example showing usage of Verify class. Note that Verify class provides below methods.
  • areEqual , areNotEqual
  • isTrue, isFalse
  • startsWith, contains, endsWith
  • lessOrEqual, less, greater, greaterOrEqual
  • isMatch
  • isNullOrEmpty, isNotNullOrEmpty
 
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 com.hp.lft.verifications.Verify;
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();

            Verify.isTrue(browser.getTitle().toLowerCase().contains("tutorial"),"Verifying the title of Home page");

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

Here is the HTML report showing verification point.

Web development and Automation testing

solutions delivered!!