bdd added cucumber
This commit is contained in:
parent
97f6075658
commit
4d10c1446f
34
README.md
34
README.md
@ -1,33 +1,3 @@
|
|||||||
Изменён pom файл для отображения allure отчётов.
|
Изменён pom файл для поддержки cucumber, добавлен cucumberScenario.feature, класс BusinessTripSteps
|
||||||
Успешно собирается в allure-reports/
|
|
||||||
|
|
||||||
Добавлена возможность скриншотов по шагам
|
|
||||||
```
|
|
||||||
AllureUtils.attachScreenshot()
|
|
||||||
```
|
|
||||||
|
|
||||||
а также при ошибках
|
|
||||||
|
|
||||||
```@Rule
|
|
||||||
public MyAllureListener allureListener = new MyAllureListener();
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
public class MyAllureListener extends TestWatcher {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void failed(Throwable e, Description description) {
|
|
||||||
takeScreenshot();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Attachment(value = "Screenshot on failure", type = "image/png")
|
|
||||||
public byte[] takeScreenshot() {
|
|
||||||
return ((TakesScreenshot) DriverManager.getDriverManager().getDriver())
|
|
||||||
.getScreenshotAs(OutputType.BYTES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|

|
||||||
|
86
pom.xml
86
pom.xml
@ -1,22 +1,34 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||||
|
http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>ru.ibs</groupId>
|
<groupId>ru.ibs</groupId>
|
||||||
<artifactId>sel1</artifactId>
|
<artifactId>sel1</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<name>Archetype - sel1</name>
|
<name>Archetype - sel1</name>
|
||||||
<url>https://git.goodtester.ru</url>
|
<url>https://git.goodtester.ru</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<aspectj.version>1.9.7</aspectj.version>
|
||||||
|
<allure.version>2.13.5</allure.version>
|
||||||
|
<cucumber.version>7.15.0</cucumber.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
|
<!-- Selenium -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
<groupId>org.seleniumhq.selenium</groupId>
|
||||||
<artifactId>selenium-java</artifactId>
|
<artifactId>selenium-java</artifactId>
|
||||||
<version>4.33.0</version>
|
<version>4.33.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
<!-- JUnit -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
@ -24,35 +36,58 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Cucumber -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.qameta.allure</groupId>
|
<groupId>io.cucumber</groupId>
|
||||||
<artifactId>allure-junit4</artifactId>
|
<artifactId>cucumber-java</artifactId>
|
||||||
<version>2.13.5</version>
|
<version>${cucumber.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.cucumber</groupId>
|
||||||
|
<artifactId>cucumber-junit</artifactId>
|
||||||
|
<version>${cucumber.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Allure -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.qameta.allure</groupId>
|
||||||
|
<artifactId>allure-junit4</artifactId>
|
||||||
|
<version>${allure.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.qameta.allure</groupId>
|
||||||
|
<artifactId>allure-cucumber7-jvm</artifactId>
|
||||||
|
<version>2.25.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- AspectJ -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.aspectj</groupId>
|
<groupId>org.aspectj</groupId>
|
||||||
<artifactId>aspectjweaver</artifactId>
|
<artifactId>aspectjweaver</artifactId>
|
||||||
<version>1.9.7</version>
|
<version>${aspectj.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
<!-- Компиляция -->
|
<!-- Компиляция -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.8.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>8</source>
|
<source>${maven.compiler.source}</source>
|
||||||
<target>8</target>
|
<target>${maven.compiler.target}</target>
|
||||||
<encoding>UTF-8</encoding>
|
<encoding>${encoding}</encoding>
|
||||||
|
<parameters>true</parameters> <!-- для удобства рефлексии, если используешь -->
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Тесты + сбор Allure результатов -->
|
<!-- Запуск тестов + Allure -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
@ -60,30 +95,19 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<testFailureIgnore>true</testFailureIgnore>
|
<testFailureIgnore>true</testFailureIgnore>
|
||||||
<argLine>
|
<argLine>
|
||||||
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.7/aspectjweaver-1.9.7.jar"
|
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
|
||||||
</argLine>
|
</argLine>
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
|
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
<properties>
|
<!-- Чтобы запускались все тесты, убери includes или добавь там все свои -->
|
||||||
<property>
|
<!-- <includes>
|
||||||
<name>listener</name>
|
<include>**/CucumberRunner.java</include>
|
||||||
<value>io.qameta.allure.junit4.AllureJunit4</value>
|
</includes> -->
|
||||||
</property>
|
|
||||||
</properties>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.aspectj</groupId>
|
|
||||||
<artifactId>aspectjweaver</artifactId>
|
|
||||||
<version>1.9.7</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Формирование отчёта -->
|
<!-- Allure отчет -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>io.qameta.allure</groupId>
|
<groupId>io.qameta.allure</groupId>
|
||||||
<artifactId>allure-maven</artifactId>
|
<artifactId>allure-maven</artifactId>
|
||||||
@ -103,9 +127,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
14
src/test/java/ru/ibs/framework/CucumberRunner.java
Normal file
14
src/test/java/ru/ibs/framework/CucumberRunner.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package ru.ibs.framework;
|
||||||
|
|
||||||
|
import io.cucumber.junit.Cucumber;
|
||||||
|
import io.cucumber.junit.CucumberOptions;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(Cucumber.class)
|
||||||
|
@CucumberOptions(
|
||||||
|
features = "src/test/resources/features",
|
||||||
|
glue = "ru.ibs.tests",
|
||||||
|
plugin = {"pretty", "io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"},
|
||||||
|
snippets = CucumberOptions.SnippetType.CAMELCASE
|
||||||
|
)
|
||||||
|
public class CucumberRunner {}
|
@ -1,63 +0,0 @@
|
|||||||
package ru.ibs.tests;
|
|
||||||
|
|
||||||
import org.junit.*;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import ru.ibs.framework.managers.DriverManager;
|
|
||||||
import ru.ibs.framework.utils.AllureUtils;
|
|
||||||
import ru.ibs.framework.utils.MyAllureListener;
|
|
||||||
|
|
||||||
public class ApplineBusinessTripTest extends BaseTests {
|
|
||||||
|
|
||||||
private LoginPage loginPage;
|
|
||||||
private DashboardPage dashboardPage;
|
|
||||||
private BusinessTripPage businessTripPage;
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public MyAllureListener allureListener = new MyAllureListener();
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
// Получаем драйвер из DriverManager (инициализирован в BaseTests)
|
|
||||||
loginPage = new LoginPage(DriverManager.getDriverManager().getDriver());
|
|
||||||
|
|
||||||
// Открываем страницу логина
|
|
||||||
DriverManager.getDriverManager().getDriver().get("http://training.appline.ru/user/login");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void applineLoginScenario() {
|
|
||||||
AllureUtils.attachScreenshot();
|
|
||||||
dashboardPage = loginPage.login("Irina Filippova", "testing");
|
|
||||||
Assert.assertTrue("Dashboard not loaded", dashboardPage.isDashboardLoaded());
|
|
||||||
|
|
||||||
businessTripPage = dashboardPage.goToBusinessTrip();
|
|
||||||
Assert.assertTrue("Trips page not loaded", businessTripPage.isTripsPageLoaded());
|
|
||||||
|
|
||||||
businessTripPage.openCreateTripForm();
|
|
||||||
|
|
||||||
businessTripPage.selectDepartment("Отдел внутренней разработки");
|
|
||||||
businessTripPage.selectOrganization("Edge");
|
|
||||||
businessTripPage.setTicketsCheckbox(true);
|
|
||||||
businessTripPage.fillCity("Дмитров");
|
|
||||||
|
|
||||||
AllureUtils.attachScreenshot();
|
|
||||||
|
|
||||||
businessTripPage.fillDate(
|
|
||||||
By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'departureDatePlan')]"),
|
|
||||||
"01.01.2025"
|
|
||||||
);
|
|
||||||
|
|
||||||
businessTripPage.fillDate(
|
|
||||||
By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'returnDatePlan')]"),
|
|
||||||
"10.01.2025"
|
|
||||||
);
|
|
||||||
|
|
||||||
AllureUtils.attachScreenshot();
|
|
||||||
|
|
||||||
businessTripPage.saveAndClose();
|
|
||||||
|
|
||||||
Assert.assertTrue("Expected validation error not shown",
|
|
||||||
businessTripPage.isErrorDisplayed("Список командируемых сотрудников не может быть пустым"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
91
src/test/java/ru/ibs/tests/BusinessTripSteps.java
Normal file
91
src/test/java/ru/ibs/tests/BusinessTripSteps.java
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
package ru.ibs.tests;
|
||||||
|
|
||||||
|
import io.cucumber.java.ru.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import io.cucumber.java.After;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import ru.ibs.framework.managers.DriverManager;
|
||||||
|
import ru.ibs.tests.*;
|
||||||
|
|
||||||
|
public class BusinessTripSteps {
|
||||||
|
|
||||||
|
private final LoginPage loginPage = new LoginPage(DriverManager.getDriverManager().getDriver());
|
||||||
|
private DashboardPage dashboardPage;
|
||||||
|
private BusinessTripPage businessTripPage;
|
||||||
|
|
||||||
|
@Дано("Открываем страницу логина")
|
||||||
|
public void openLoginPage() {
|
||||||
|
DriverManager.getDriverManager().getDriver().get("http://training.appline.ru/user/login");
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Вводим логин {string} и пароль {string}")
|
||||||
|
public void login(String username, String password) {
|
||||||
|
dashboardPage = loginPage.login(username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Проверяем, что панель быстрого запуска загружена")
|
||||||
|
public void dashboardLoaded() {
|
||||||
|
assertTrue("Dashboard not loaded", dashboardPage.isDashboardLoaded());
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Переходим в раздел {string}")
|
||||||
|
public void goToBusinessTrip(String name) {
|
||||||
|
businessTripPage = dashboardPage.goToBusinessTrip();
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Проверяем, что страница {string} загружена")
|
||||||
|
public void tripsPageLoaded(String title) {
|
||||||
|
assertTrue("Trips page not loaded", businessTripPage.isTripsPageLoaded());
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Нажимаем на кнопку создания новой командировки")
|
||||||
|
public void openCreateTripForm() {
|
||||||
|
businessTripPage.openCreateTripForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Выбираем подразделение {string}")
|
||||||
|
public void selectDepartment(String department) {
|
||||||
|
businessTripPage.selectDepartment(department);
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Выбираем организацию {string}")
|
||||||
|
public void selectOrganization(String organization) {
|
||||||
|
businessTripPage.selectOrganization(organization);
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Устанавливаем чекбокс {string} в положение {string}")
|
||||||
|
public void setCheckbox(String checkboxName, String value) {
|
||||||
|
boolean checked = Boolean.parseBoolean(value);
|
||||||
|
businessTripPage.setTicketsCheckbox(checked);
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Заполняем поле {string} значением {string}")
|
||||||
|
public void fillCityOrDate(String field, String value) {
|
||||||
|
if (field.equalsIgnoreCase("Город")) {
|
||||||
|
businessTripPage.fillCity(value);
|
||||||
|
} else if (field.equalsIgnoreCase("Дата отправления")) {
|
||||||
|
businessTripPage.fillDate(By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'departureDatePlan')]"), value);
|
||||||
|
} else if (field.equalsIgnoreCase("Дата возвращения")) {
|
||||||
|
businessTripPage.fillDate(By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'returnDatePlan')]"), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Нажимаем кнопку {string}")
|
||||||
|
public void clickButton(String buttonName) {
|
||||||
|
if (buttonName.equals("Сохранить и закрыть")) {
|
||||||
|
businessTripPage.saveAndClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Тогда("Проверяем, что отображается ошибка {string}")
|
||||||
|
public void checkError(String errorText) {
|
||||||
|
assertTrue("Expected validation error not shown",
|
||||||
|
businessTripPage.isErrorDisplayed(errorText));
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
DriverManager.getDriverManager().quitDriver();
|
||||||
|
}
|
||||||
|
}
|
19
src/test/resources/features/cucumberScenario.feature
Normal file
19
src/test/resources/features/cucumberScenario.feature
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# language: ru
|
||||||
|
@businessTrip
|
||||||
|
Функционал: Создание командировки
|
||||||
|
|
||||||
|
Сценарий: Проверка ошибки при попытке создать командировку без сотрудников
|
||||||
|
* Открываем страницу логина
|
||||||
|
* Вводим логин "Irina Filippova" и пароль "testing"
|
||||||
|
* Проверяем, что панель быстрого запуска загружена
|
||||||
|
* Переходим в раздел "Командировки"
|
||||||
|
* Проверяем, что страница "Командировки" загружена
|
||||||
|
* Нажимаем на кнопку создания новой командировки
|
||||||
|
* Выбираем подразделение "Отдел внутренней разработки"
|
||||||
|
* Выбираем организацию "Edge"
|
||||||
|
* Устанавливаем чекбокс "Заказ билетов" в положение "true"
|
||||||
|
* Заполняем поле "Город" значением "Дмитров"
|
||||||
|
* Заполняем поле "Дата отправления" значением "01.01.2025"
|
||||||
|
* Заполняем поле "Дата возвращения" значением "10.01.2025"
|
||||||
|
* Нажимаем кнопку "Сохранить и закрыть"
|
||||||
|
* Проверяем, что отображается ошибка "Список командируемых сотрудников не может быть пустым"
|
Loading…
x
Reference in New Issue
Block a user