Lab 7 Report
Lab 7 Report
Software Testing
Laboratory work nr.7
Report
Chisinau 2020
Laboratory scope: the scope of this laboratory work is to run the tests on a
live web application, to undersatnd how to use Cucumber, how to run tests
using cucumber, how to create .feature files and how to use them for testing
purposes.
Apache Maven - Maven is a build automation tool used primarily for Java
projects. Maven can also be used to build and manage projects written in
C#, Ruby, Scala, and other languages. The Maven project is hosted by the
Apache Software Foundation, where it was formerly part of the Jakarta
Project.
1. First of all we have to setup the tools: InteliJIdea, a maven project and
prepare Selenium dependencies.
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.utm</groupId>
<artifactId>Selenium</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.10</maven.compiler.source>
<maven.compiler.target>1.10</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.23.2</version>
</dependency>
</dependencies>
</project>
2. Thecreate I created a .feature file witch will describe the test case steps:
Example: Contact.feature
Feature: Header is displayed after search
Examples:
| item |
| shoes |
public Base() {
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "80");
caps.setCapability("name", "iondodon1's First Test");
try {
driver = new RemoteWebDriver(new URL(URL), caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.manage().window().maximize();
}
4. Then I created a class for each page HomePage. These classes hold
methods that interact with the UI elemnets.
Example: HomePage
public class HomePage extends Base {
private final By searchIconXPath = By.xpath("//*[@id=\"top-nav\"]/div/div/div[1]/a[2]");
private final By searchInputXPath = By.xpath("//*[@id=\"top-nav\"]/div/div/div[1]/div/form/div[1]/
input");
private final By headerXPath = By.xpath("//*[@id=\"top-nav\"]");
WebElement searchInput;
public HomePage() {
driver.get("https://9gag.com/");
acceptCookies();
}
@And("Enter is pressed")
public void enterIsPressed() {
homePage.pressEnter();
}
@Then("Header is displayed")
public void headerIsDisplayed() {
boolean headerIsDisplayed = homePage.headerIsDisplayed();
assertTrue("Header is not displayed!", headerIsDisplayed);
}
}
5. Then I create a feature test case runner:
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features/Header.feature",
glue = {"steps/header"},
stepNotifications = true,
plugin = { "json:target/cucumber.json", "pretty", "html:target/header-test.html" }
)
public class HeaderAfterSearchRunner {
}
Result:
Test-Video:
https://drive.google.com/file/d/18M_41ElmECcZH3Bj66Uz9sDcD0wz
WTYe/view?usp=sharing
Report: