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
30 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 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 in Selenium by Maria
38 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,090 points
592 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
901 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
578 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,520 points
64 views