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 in Selenium by Vinay
13 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 6 days ago 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 6 days ago in Selenium by Maria
17 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
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
135 views
0 votes
1 answer
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,130 points
527 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
129 views
+2 votes
2 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
• 56,140 points
44 views
0 votes
1 answer

What are some of the browser commands used in Selenium Webdriver?

Hi Nakul, some of the most frequently ...READ MORE

answered May 14 in Selenium by Abha
• 8,250 points
14 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.