Anul 3 Semestrul 2
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath("net.serenity-bdd:serenity-gradle-plugin:2.3.2")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'net.serenity-bdd.aggregator'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
dependencies {
|
||||
compile 'net.serenity-bdd:serenity-core:2.3.2'
|
||||
compile 'net.serenity-bdd:serenity-junit:2.3.2'
|
||||
testCompile('junit:junit:4.12')
|
||||
}
|
||||
gradle.startParameter.continueOnFailure = true
|
||||
@@ -0,0 +1,121 @@
|
||||
<?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.example</groupId>
|
||||
<artifactId>lab5</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Serenity project with JUnit and WebDriver</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<serenity.version>2.3.2</serenity.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>central</id>
|
||||
<name>bintray</name>
|
||||
<url>https://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>central</id>
|
||||
<name>bintray-plugins</name>
|
||||
<url>https://jcenter.bintray.com</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-core</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-junit</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Test.java</include>
|
||||
<include>**/Test*.java</include>
|
||||
<include>**/When*.java</include>
|
||||
<include>**/*Story.java</include>
|
||||
</includes>
|
||||
<argLine>-Xmx512m</argLine>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.serenity-bdd.maven.plugins</groupId>
|
||||
<artifactId>serenity-maven-plugin</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>serenity-reports</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>aggregate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,23 @@
|
||||
# Define the default driver
|
||||
#webdriver.driver=phantomjs
|
||||
|
||||
# Appears at the top of the reports
|
||||
serenity.project.name = Demo Project using Serenity and JUnit
|
||||
webdriver.autodownload = false
|
||||
webdriver.driver = chrome
|
||||
headless.mode = false
|
||||
webdriver.chrome.driver = chromedriver
|
||||
|
||||
# Root package for any JUnit acceptance tests
|
||||
serenity.test.root=com.example.features
|
||||
|
||||
# Customise your riequirements hierarchy
|
||||
#serenity.requirement.types=feature, story
|
||||
|
||||
# Run the tests without calling webdriver - useful to check your JUnit wireing
|
||||
#serenity.dry.run=true
|
||||
|
||||
# Customise browser size
|
||||
#serenity.browser.height = 1200
|
||||
#serenity.browser.width = 1200
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.example.features.filter;
|
||||
|
||||
import net.serenitybdd.junit.runners.SerenityParameterizedRunner;
|
||||
import net.thucydides.core.annotations.Managed;
|
||||
import net.thucydides.core.annotations.Steps;
|
||||
import net.thucydides.junit.annotations.UseTestDataFrom;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
import com.example.steps.serenity.EndUserSteps;
|
||||
import com.example.steps.serenity.FilterSteps;
|
||||
|
||||
@RunWith(SerenityParameterizedRunner.class)
|
||||
@UseTestDataFrom(value = "src/test/resources/testdatafilter.csv", separator = ',')
|
||||
public class FilterByKeywordStory {
|
||||
public String brand;
|
||||
public String expected;
|
||||
|
||||
@Managed(uniqueSession = true)
|
||||
public WebDriver webdriver;
|
||||
|
||||
@Steps
|
||||
public FilterSteps anna;
|
||||
|
||||
@Test
|
||||
public void filter_by_brand_should_return_corresponding_product() {
|
||||
anna.is_the_home_page();
|
||||
anna.accept_cookies();
|
||||
anna.enters(brand);
|
||||
WebDriverWait wait = new WebDriverWait(webdriver, 10);
|
||||
wait.until(ExpectedConditions.urlContains(brand.toLowerCase()));
|
||||
anna.should_see_definition(expected);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.example.features.search;
|
||||
|
||||
import net.serenitybdd.junit.runners.SerenityParameterizedRunner;
|
||||
import net.thucydides.core.annotations.Managed;
|
||||
import net.thucydides.core.annotations.Steps;
|
||||
import net.thucydides.junit.annotations.UseTestDataFrom;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
||||
import com.example.steps.serenity.EndUserSteps;
|
||||
|
||||
@RunWith(SerenityParameterizedRunner.class)
|
||||
@UseTestDataFrom(value = "src/test/resources/testdata.csv", separator = ',')
|
||||
public class SearchByKeywordStory {
|
||||
|
||||
public String keyword;
|
||||
public String expected;
|
||||
|
||||
@Managed(uniqueSession = true)
|
||||
public WebDriver webdriver;
|
||||
|
||||
@Steps
|
||||
public EndUserSteps anna;
|
||||
|
||||
@Test
|
||||
public void searching_by_keyword_should_display_the_corresponding_produce() {
|
||||
anna.is_the_home_page();
|
||||
anna.looks_for(keyword);
|
||||
anna.should_see_definition(expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.example.pages;
|
||||
|
||||
import net.thucydides.core.annotations.DefaultUrl;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import net.serenitybdd.core.pages.WebElementFacade;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.serenitybdd.core.annotations.findby.FindBy;
|
||||
|
||||
import net.thucydides.core.pages.PageObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@DefaultUrl("https://www.emag.ro/")
|
||||
public class DictionaryPage extends PageObject {
|
||||
|
||||
@FindBy(id = "searchboxTrigger")
|
||||
private WebElementFacade searchTerms;
|
||||
|
||||
@FindBy(className = "searchbox-submit-button")
|
||||
private WebElementFacade lookupButton;
|
||||
|
||||
public void enter_keywords(String keyword) {
|
||||
searchTerms.type(keyword);
|
||||
}
|
||||
|
||||
public void lookup_terms() {
|
||||
lookupButton.click();
|
||||
}
|
||||
|
||||
public List<String> getDefinitions() {
|
||||
WebElementFacade definitionList = find(By.id("card_grid"));
|
||||
return definitionList.findElements(By.className("card-item")).stream()
|
||||
.map(element -> element.getAttribute("data-name"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.example.pages;
|
||||
|
||||
import net.thucydides.core.annotations.DefaultUrl;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import net.serenitybdd.core.pages.WebElementFacade;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.serenitybdd.core.annotations.findby.FindBy;
|
||||
|
||||
import net.thucydides.core.pages.PageObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@DefaultUrl("https://www.emag.ro/laptopuri/c")
|
||||
public class FilterPage extends PageObject {
|
||||
|
||||
@FindBy(className = "js-accept")
|
||||
private WebElementFacade acceptCookies;
|
||||
|
||||
public void enter_keywords(String keyword) {
|
||||
WebElementFacade searchTerms = find(By.className("sidebar-container-body"));
|
||||
WebElement searchInput = searchTerms.findElement(By.xpath(String.format(
|
||||
"//div[@class='filter filter-default js-filter' and @data-name='Brand']//a[@class='js-filter-item filter-item' and @data-name='%s']",
|
||||
keyword)));
|
||||
searchInput.click();
|
||||
}
|
||||
|
||||
public void accept_cookies() {
|
||||
if (acceptCookies.isPresent()) {
|
||||
acceptCookies.click();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getDefinitions() {
|
||||
WebElementFacade definitionList = find(By.id("card_grid"));
|
||||
return definitionList.findElements(By.className("card-item")).stream()
|
||||
.map(element -> element.getAttribute("data-name"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.example.steps.serenity;
|
||||
|
||||
import com.example.pages.DictionaryPage;
|
||||
import net.thucydides.core.annotations.Step;
|
||||
import net.thucydides.core.steps.ScenarioSteps;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
public class EndUserSteps {
|
||||
|
||||
DictionaryPage dictionaryPage;
|
||||
|
||||
@Step
|
||||
public void enters(String keyword) {
|
||||
dictionaryPage.enter_keywords(keyword);
|
||||
}
|
||||
|
||||
@Step
|
||||
public void starts_search() {
|
||||
dictionaryPage.lookup_terms();
|
||||
}
|
||||
|
||||
@Step
|
||||
public void should_see_definition(String definition) {
|
||||
assertThat(dictionaryPage.getDefinitions(), hasItem(containsString(definition)));
|
||||
}
|
||||
|
||||
@Step
|
||||
public void is_the_home_page() {
|
||||
dictionaryPage.open();
|
||||
}
|
||||
|
||||
@Step
|
||||
public void looks_for(String term) {
|
||||
enters(term);
|
||||
starts_search();
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.example.steps.serenity;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
import com.example.pages.FilterPage;
|
||||
|
||||
import net.thucydides.core.annotations.Step;
|
||||
|
||||
public class FilterSteps {
|
||||
FilterPage filterPage;
|
||||
|
||||
@Step
|
||||
public void enters(String keyword) {
|
||||
filterPage.enter_keywords(keyword);
|
||||
}
|
||||
|
||||
@Step
|
||||
public void should_see_definition(String definition) {
|
||||
assertThat(filterPage.getDefinitions(), hasItem(containsString(definition)));
|
||||
}
|
||||
|
||||
@Step
|
||||
public void is_the_home_page() {
|
||||
filterPage.open();
|
||||
}
|
||||
|
||||
@Step
|
||||
public void accept_cookies() {
|
||||
filterPage.accept_cookies();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
Search for definitions
|
||||
In order to understand a word that I don't know
|
||||
As a user
|
||||
I want to be able to look up the meaning of the word
|
||||
@@ -0,0 +1,3 @@
|
||||
keyword,expected
|
||||
purificator,Purificator de aer Freezy Air
|
||||
frigider,Air Fryer
|
||||
|
@@ -0,0 +1,3 @@
|
||||
brand,expected
|
||||
Apple,MacBook
|
||||
Lenovo,MacBook
|
||||
|
Reference in New Issue
Block a user