But with Maven and a testing framework our work will be much easier. We will use JUnit 5 as a testing framework.
1. Run NetBeans IDE and create new Maven based Java Application project:
2. Enter name, location and Group id:
3. File > New > Other > select Selenium Test Case:
4. Enter Class name and a package name, then click Finish:
5. A class with a simple test example will be created as well as a pom.xml file:
6. Open pom.xml file and update it to use new versions of Selenium and JUnit.
Just copy/paste the following dependencies instead of old ones:
Selenium:
Selenium:
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.7.1</version> </dependency>
JUnit:
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.0.1</version> <scope>test</scope> </dependency>
7. Open our test class and modify it with the following code:
package com.blogspot.autoqalab; import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; public class PlaygroundTest { @Test public void testTitle() throws Exception { WebDriver driver = new FirefoxDriver(); driver.get("https://automation-playground.blogspot.com"); // Check the title of the page // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver d) { return driver.getTitle() .equalsIgnoreCase("Automation Playground"); } }); //Close the browser driver.quit(); } }
8. Mouse right click on the test class > Test File or just click Ctrl + F6 to run the Selenium test
The following test scenario will be executed:
- run Firefox browser
- go to https://automation-playground.blogspot.com
- verify the blog's title
- close Firefox browser
Test passed !
No comments:
Post a Comment