You are on page 1of 8

Technical University of the Moldova

Software Engeneering and Automation Department

Software Testing
Laboratory work nr.7

Theme: Creation and execution of automated tests


on a live web application

Report

Done By: Verified by:

Ion Dodon Mihai Lungu

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.

Java IDE for Professional Developers – IntelliJ IDEA - IntelliJ IDEA is an


integrated development environment written in Java for developing
computer software. It is developed by JetBrains, and is available as an
Apache 2 Licensed community edition, and in a proprietary commercial
edition. Both can be used for commercial development.

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.

Selenium - Selenium is a portable framework for testing web applications.


Selenium provides a playback tool for authoring functional tests without
the need to learn a test scripting language (Selenium IDE). It also provides
a test domain-specific language (Selenese) to write tests in a number of
popular programming languages,
including C#, Groovy, Java, Perl, PHP, Python, Ruby and Scala. The tests
can then run against most modern web browsers. Selenium runs
on Windows, Linux, and macOS. It is open-source software released under
the Apache License 2.0.

Cucumber - software tool that supports behavior-driven


development (BDD). Central to the Cucumber BDD approach is its
ordinary language parser called Gherkin. It allows expected software
behaviors to be specified in a logical language that customers can
understand. As such, Cucumber allows the execution of feature
documentation written in business-facing text. It is often used for testing
other software. It runs automated acceptance tests written in
a behavior-driven development (BDD) style.
How the goal was achieved:

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

Scenario Outline: Validate that the headers is displayed after search


Given Home page of 9gag.com is opened
When Search button is clicked
Then User writes "<item>" in the search
And Enter is pressed
Then Header is displayed

Examples:
| item |
| shoes |

3. Then I Create a Base class that will hold the driver.


public class Base {
public static final String USERNAME = "iondodon1";
public static final String AUTOMATE_KEY = "tLt3ydzPGizLzfcCdR7a";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-
cloud.browserstack.com/wd/hub";

DesiredCapabilities caps = new DesiredCapabilities();

protected WebDriver driver;

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();
}

public void tearDown() {


driver.close();
driver.quit();
driver = null;
System.out.println("Working Driver was closed.");
}
}

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();
}

private void acceptCookies() {


WebElement acceptCookiesButton = driver.findElement(By.xpath("//*[text()='I ACCEPT']"));
acceptCookiesButton.click();
}

public void writeInSearchBar(String text) {


searchInput = driver.findElement(searchInputXPath);
searchInput.sendKeys(text);
searchInput.sendKeys(Keys.ENTER);
}

public void pressEnter() {


searchInput.sendKeys(Keys.ENTER);
}

public void clickSearchIcon() {


WebElement searchIcon = driver.findElement(searchIconXPath);
searchIcon.click();
}

public boolean headerIsDisplayed() {


return driver.findElement(headerXPath).isDisplayed();
}

public boolean is404() {


return driver.findElement(By.xpath("//p[contains(text(), '404')]")).isDisplayed();
}
}

5. The I created Step deffinitions:


public class CheckHeaderAfterSearchSteps {
HomePage homePage;

@Given("Home page of 9gag.com is opened")


public void homePageOfGagComIsOpened() {
homePage = new HomePage();
}

@When("Search button is clicked")


public void searchButtonIsClicked() {
homePage.clickSearchIcon();
}

@Then("User writes {string} in the search")


public void userWritesSomethingInTheSearch(String item) {
homePage.writeInSearchBar(item);
}

@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:

GitHub Link to the project:


https://github.com/iondodon/QA

Conclusion: After working on this laboratory work I have understood how


to generate reports after tests running and how to use and live environment
for testing, in this case I used browserstack. I have learned how to prepare a
Selenium project with maven and InteliJ IDE. I have understood now to
perform basic actions with the help of Selenium and Cucumber. I have
understood how to write .feature files in order to run tests from them. Then
we can defined the steps for a test. Also, I have learned how to use relative
web element path in the project.
Webography:
https://www.jetbrains.com/idea/download/#section=windows
https://www.guru99.com/intellij-selenium-
webdriver.html#:~:text=Step%203)%20Now%20You
%20need,4)%20Select%20all%20the%20selenium%20.
https://cucumber.io/

You might also like