What are the assertion methods used by JUnit to write Selenium scripts?

0 votes
What are the assertion methods used by JUnit to write Selenium scripts?
Jun 11, 2019 in Selenium by Vinay
123 views

1 answer to this question.

0 votes

@Vinay, JUnit provide these assertions to write Selenium Scripts:

1. assertEquals: Checks if the two values are equal and assertion fails if both values are not equal. This compares Boolean, int, String, float, long, char etc.

Syntax:

Assert.assertEqual(“excepted value”, ”actual value”);

Example:

Assert.assertEqual(“ABC”,”ABC”); // Assertion will pass.

2. assertTrue: Returns true if the condition is true and assertion fails if the condition is false.

Syntax:

Assert.assertTrue(“message”, condition);

Example:

Assert.assertTrue(“Both the strings are not equal”, (“HelloWorld”).equals(“HelloWorld”));

Here assertion will pass as both the strings match. It will print the message if the assertion fails.

3. JUnit assertFalse: Returns true if the condition is false and assertion fails if the condition is true.

Syntax:

Assert.assertFalse(“message”, condition);

Example:

Assert.assertFalse(“Both the strings are equal”, (“Hello”).equals(“HelloWorld”));

There will not be any assertion error as the condition is false.

answered Jun 11, 2019 by Zubin

Related Questions In Selenium

0 votes
1 answer

What are the Junit Annotations used in Selenium Scripts?

Hi Priyanka, there are many annotations available ...READ MORE

answered Jun 11, 2019 in Selenium by Maria
166 views
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

What are the commonly used Selenium Webdriver commands to manage cookies?

Hi Nisha, some of the most commonly ...READ MORE

answered Jun 19, 2019 in Selenium by Anvi
• 14,110 points
217 views
0 votes
2 answers

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,520 points
4,044 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,992 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,927 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,367 views
0 votes
1 answer
+2 votes
3 answers

What are the different Locators that can be used to access Web Elements?

@Nitesh, I would like to tell you ...READ MORE

answered Dec 12, 2018 in Selenium by Priyaj
• 57,700 points
170 views