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

Building The Test Framework: Testng Annotations: Test Automation Basics With Selenium & Java

The document outlines the process of building a test framework using TestNG annotations and Selenium with Java. It provides examples of organizing test code by utilizing @Before and @After annotations, and suggests improvements by creating a BaseTest class for common setup and teardown actions. Additionally, it recommends enhancing tests by maximizing the browser window and enabling quick switching between different web drivers.

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 views8 pages

Building The Test Framework: Testng Annotations: Test Automation Basics With Selenium & Java

The document outlines the process of building a test framework using TestNG annotations and Selenium with Java. It provides examples of organizing test code by utilizing @Before and @After annotations, and suggests improvements by creating a BaseTest class for common setup and teardown actions. Additionally, it recommends enhancing tests by maximizing the browser window and enabling quick switching between different web drivers.

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

Building the test framework:

TestNG annotations
Test automation basics with Selenium & Java
By:
Evgeny Novikov
Email:
xevgnov@[Link]
Mostly usable TestNG annotations
● @Test
● Before: @BeforeSuite, @BeforeTest, @BeforeClass,
@BeforeMethod
● After: @AfterSuite, @AfterTest, @AfterClass,
@AfterMethod
● @DataProvider
By:
Evgeny Novikov
Email:
xevgnov@[Link]
Move repetitive code to @Before and @After
public class SearchTest {

private WebDriver driver;

@BeforeClass
public void setUp() {
File file = new File("src/main/resources/[Link]");
System. setProperty("[Link]",
[Link]());
driver = new ChromeDriver();
[Link]().to( "[Link]
}

@AfterClass
public void tearDown() { By:
[Link](); Evgeny Novikov
} Email:
xevgnov@[Link]
Now test is short and clear
@Test
public void openGoogleOrgContainsFeelingLuckyButtonTest() {
WebElement feelingLuckyButton =
[Link](By. name("btnI"));
assertEquals([Link]( "value"), "I'm
Feeling Lucky", "Wrong text has been displayed!");
}

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Let’s improve our tests even more
1) Move @Before and @After annotations to abstract class
BaseTest
2) Extend SearchTest with BaseTest class

By:
Evgeny Novikov
Email:
xevgnov@[Link]
BaseTest - includes pre and post actions
public abstract class BaseTest {

protected WebDriver driver;

@BeforeClass
public void setUp() {
File file = new File("src/main/resources/[Link]");
[Link]("[Link]", [Link]());
driver = new ChromeDriver();
[Link]().to("[Link]
}

@AfterClass
public void tearDown() {
[Link](); By:
} Evgeny Novikov
} Email:
xevgnov@[Link]
SearchTest (steps, results) inherits BaseTest
public class SearchTest extends BaseTest{

@Test

public void openGoogleOrgContainsFeelingLuckyButtonTest() {

WebElement feelingLuckyButton = [Link]([Link]("btnI"));

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


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

}
By:
Evgeny Novikov
Email:
xevgnov@[Link]
Update your tests with
following changes:

1) maximize browser window

Exercise when new driver instance is


created
2) modify setUp() method to be
Modifying tests framework
able to do quick switch between
Internet Explorer Driver and
Chrome Driver

By:
Evgeny Novikov
Email:
xevgnov@[Link]

You might also like