0% found this document useful (0 votes)
2 views10 pages

Assertions: Results Verification: Test Automation Basics With Selenium & Java

The document discusses assertions in test automation using Selenium and Java, focusing on comparing expected and actual results. It covers various assertion methods, including TestNG asserts, Fluent asserts, and libraries like AssertJ and Hamcrest matchers. Additionally, it provides examples of using assertions in practice, including a business assertions pattern for validating search results.

Uploaded by

sxoterry
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Assertions: Results Verification: Test Automation Basics With Selenium & Java

The document discusses assertions in test automation using Selenium and Java, focusing on comparing expected and actual results. It covers various assertion methods, including TestNG asserts, Fluent asserts, and libraries like AssertJ and Hamcrest matchers. Additionally, it provides examples of using assertions in practice, including a business assertions pattern for validating search results.

Uploaded by

sxoterry
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assertions: results verification

Test automation basics with Selenium & Java


By:
Evgeny Novikov
Email:
xevgnov@[Link]
Asserts
- compare expected and actuals results

true false

does nothing throws Exception

PASS FAIL
By:
Evgeny Novikov
Email:
xevgnov@[Link]
Simple TestNG asserts

[Link](condition, message);

[Link](actualResult, expectedResult, message);

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Assert import VS assert method static import
import [Link];

[Link]([Link](), "test");

import static [Link]. assertEquals;

assertEquals([Link](), "test");

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Asserts - example
WebDriver driver = new ChromeDriver();

[Link]().to( "[Link]

WebElement feelingLuckyButton =
[Link](By. name("btnI"));

assertTrue([Link](), "I'm Feeling Lucky


button is disabled!");

assertEquals([Link]( "value"), "I'm Feeling


Lucky", "Wrong text has been displayed!");

By:
Actual result Error message Expected result Evgeny Novikov
Email:
xevgnov@[Link]
Fluent asserts instead of TestNG ones
1) advanced assert features (search in collections, chains of
assertions, etc.)
2) existing solutions instead own implementation
3) more readable

What libraries?
1)AssertJ
2)Hamcrest matchers By:
Evgeny Novikov
Email:
xevgnov@[Link]
AssertJ VS Hamcrest matchers
1)AssertJ
assertThat([Link]()).as("Page have a wrong
title!").contains("Home page");

2)Hamcrest matchers
assertThat(“Page have a wrong title!”,
[Link](), contains("Home page"));

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Chains of assertions
assertThat( result)
.isNotEmpty()
.contains( "selenium", "webdriver", "java", "automation")
.doesNotContain( "restAssured", "protractor");

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Business assertions pattern
public class BusinessAssert {

public static void


assertThatValidSearchResultIsDisplayed(WebElement result) {

assertThat( [Link]())
.as( “Search result area is missing!”).isTrue()

assertThat( [Link]())
.as( “No expected content or unexpected content has
been found!”);
.contains( "selenium", "webdriver", "java",
"automation")
.doesNotContain( "restAssured", "protractor");
} By:
} Evgeny Novikov
Email:
xevgnov@[Link]
Steps:

1) Open [Link]
2) Put text ‘selenium webdriver’ to
the search field

Exercise 3) Press Enter search button

Expected results:
Execute search and verify result
words “selenium” and “webdriver”
are present in the first result row

By:
Evgeny Novikov
Email:
xevgnov@[Link]

You might also like