Can anyone please demonstrate to me how assertTrue() or assertFalse() methods work in Selenium?

0 votes
I am new to Selenium and trying to understand the concept of Assertions. So can anyone explain how assertTrue() or assertFalse() methods work for any web element?
May 15 in Selenium by Priyank

edited May 17 43 views

1 answer to this question.

0 votes

Hey Priyank, to understand how assertFalse() or assertTrue() works, please refer to the following code snippet:

package co.edureka.selenium.assertions;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;

public class AssertTrueFalse {

 public static void main(String[] args) {

  System.setProperty("webdriver.chrome.driver","C:\\\\Users\\\\Abha_Rathour\\\\Downloads\\\\ExtractedFiles\\\\chromedriver_win32\\\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.navigate().to("https://www.spicejet.com/");
        Assert.assertFalse(driver.findElement(By.cssSelector("input[id*='SeniorCitizenDiscount']")).isSelected());
        System.out.println(driver.findElement(By.cssSelector("input[id*='SeniorCitizenDiscount']")).isSelected());
}

}

Here, assertFalse() will check the isSelected() methods output and if the output will be False, then only it will pass the test.

answered May 17 by Anvi
• 10,670 points

Related Questions In Selenium

0 votes
1 answer

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

Download the executable driver from: ChromeDriver Download Before ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,050 points
180 views
0 votes
1 answer

What is the role of TestNG & JUnit frameworks in Selenium?

Well TestNG and JUnit are test frameworks ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,590 points
193 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
270 views
0 votes
1 answer

Diff between WebDriver listeners and TestNG listeners?

This is not a very important concept ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,590 points
1,429 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How selenium can be used in devops lifecycle?

Hey Catherine, as we know that a ...READ MORE

answered May 8 in Selenium by Anvi
• 10,670 points
33 views