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 72 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
• 13,400 points

Related Questions In Selenium

0 votes
2 answers

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

You first need to download chrome driver ...READ MORE

answered Aug 26 in Selenium by Abha
• 24,400 points
281 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,650 points
301 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,090 points
754 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,650 points
1,714 views
0 votes
1 answer
0 votes
1 answer