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
832 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 12, 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 12, 2019 in Selenium by Maria
1,103 views
0 votes
1 answer
0 votes
2 answers

What are the wait methods which can be used to handle AJAX calls?

Hi , for Ajax call better to use Explicit ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
1,597 views
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,150 points
1,482 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,500 points
13,673 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 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,910 points
7,221 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 3, 2020 in Selenium by Sri
• 3,190 points
7,874 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
• 58,020 points
1,476 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP