Monday, 1 December 2014

Hard Assertion - assertFalse(condition) Assertion in Selenium Webdriver



-> assertTrue assertion is generally used for when boolean condition false.

-> It will pass if condition returns "false". If it will return true then it will fail and skip test execution from that specific method.

-> Syntax for assertFalse assertion is as bellow.

Assert.assertFalse(condition);


Example:

Suppose you want to continue the process if checkbox Unchecked/unselect.



package TestNG_Package;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.testng.Assert;

public class TestNG_Test1 {

WebDriver driver1=new FirefoxDriver();
WebElement check1;

@BeforeMethod
public void OpenBrowser(){
driver1.get("http://google.com");
check1 = driver1.findElement(By.xpath("//input[@name='option1']"));
driver1.manage().window().maximize();
}

@AfterMethod
public void CloseBrowser(){
driver1.quit();
}


@Test
public void Assertion_method1() {
String title = driver1.getTitle();
Assert.assertFalse(check1.isSelected());
System.out.println("title"+title);
}


}


From above Example:

-> Assertion_method1 will get pass and complete all steps if select the check box and return the condition value as False .

-> Assertion_method1 will get fail and skip all steps if unselect the check box and return the condition value as True .

1 comment:

  1. Best place to learn Appium Android IOS Automation Testing Training in Chennai

    Go for Appium training in chennai for real time mobile automation testing training with real time project support.
    UI Automation Tools with real time scenarios You can contact 8122241286 for Best APPIUM and selenium Training in Chennai

    ReplyDelete