Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
97f6075658 |
BIN
.gitignore
vendored
BIN
.gitignore
vendored
Binary file not shown.
33
README.md
Normal file
33
README.md
Normal file
@ -0,0 +1,33 @@
|
||||
Изменён pom файл для отображения allure отчётов.
|
||||
Успешно собирается в 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);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
|
81
pom.xml
81
pom.xml
@ -24,7 +24,88 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.qameta.allure</groupId>
|
||||
<artifactId>allure-junit4</artifactId>
|
||||
<version>2.13.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.7</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Компиляция -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Тесты + сбор Allure результатов -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
<configuration>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
<argLine>
|
||||
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.7/aspectjweaver-1.9.7.jar"
|
||||
</argLine>
|
||||
<systemPropertyVariables>
|
||||
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
|
||||
</systemPropertyVariables>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
<value>io.qameta.allure.junit4.AllureJunit4</value>
|
||||
</property>
|
||||
</properties>
|
||||
</configuration>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</plugin>
|
||||
|
||||
<!-- Формирование отчёта -->
|
||||
<plugin>
|
||||
<groupId>io.qameta.allure</groupId>
|
||||
<artifactId>allure-maven</artifactId>
|
||||
<version>2.10.0</version>
|
||||
<configuration>
|
||||
<reportVersion>2.10.0</reportVersion>
|
||||
<resultsDirectory>${project.build.directory}/allure-results</resultsDirectory>
|
||||
<reportDirectory>${project.build.directory}/allure-report</reportDirectory>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>report</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
|
15
src/test/java/ru/ibs/framework/utils/AllureUtils.java
Normal file
15
src/test/java/ru/ibs/framework/utils/AllureUtils.java
Normal file
@ -0,0 +1,15 @@
|
||||
package ru.ibs.framework.utils;
|
||||
|
||||
import io.qameta.allure.Attachment;
|
||||
import org.openqa.selenium.OutputType;
|
||||
import org.openqa.selenium.TakesScreenshot;
|
||||
import ru.ibs.framework.managers.DriverManager;
|
||||
|
||||
public class AllureUtils {
|
||||
|
||||
@Attachment(value = "Screenshot at step", type = "image/png")
|
||||
public static byte[] attachScreenshot() {
|
||||
return ((TakesScreenshot) DriverManager.getDriverManager().getDriver())
|
||||
.getScreenshotAs(OutputType.BYTES);
|
||||
}
|
||||
}
|
22
src/test/java/ru/ibs/framework/utils/MyAllureListener.java
Normal file
22
src/test/java/ru/ibs/framework/utils/MyAllureListener.java
Normal file
@ -0,0 +1,22 @@
|
||||
package ru.ibs.framework.utils;
|
||||
|
||||
import io.qameta.allure.Attachment;
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
import org.openqa.selenium.OutputType;
|
||||
import org.openqa.selenium.TakesScreenshot;
|
||||
import ru.ibs.framework.managers.DriverManager;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
63
src/test/java/ru/ibs/tests/ApplineBusinessTripTest.java
Normal file
63
src/test/java/ru/ibs/tests/ApplineBusinessTripTest.java
Normal file
@ -0,0 +1,63 @@
|
||||
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("Список командируемых сотрудников не может быть пустым"));
|
||||
}
|
||||
|
||||
}
|
@ -8,8 +8,8 @@ import org.openqa.selenium.support.ui.*;
|
||||
import java.time.Duration;
|
||||
|
||||
public class BusinessTripPage {
|
||||
private WebDriver driver;
|
||||
private WebDriverWait wait;
|
||||
private final WebDriver driver;
|
||||
private final WebDriverWait wait;
|
||||
|
||||
@FindBy(xpath = "//h1[contains(text(), 'Командировки')]")
|
||||
private WebElement tripsHeader;
|
||||
@ -77,7 +77,6 @@ public class BusinessTripPage {
|
||||
scrollToElement(cityInput);
|
||||
cityInput.clear();
|
||||
cityInput.sendKeys(city);
|
||||
// Optionally assert
|
||||
}
|
||||
|
||||
public void fillDate(By dateLocator, String dateValue) {
|
||||
@ -86,7 +85,6 @@ public class BusinessTripPage {
|
||||
dateInput.clear();
|
||||
dateInput.sendKeys(dateValue);
|
||||
dateInput.sendKeys(Keys.TAB);
|
||||
// Optionally assert
|
||||
}
|
||||
|
||||
public void saveAndClose() {
|
||||
|
@ -1,89 +0,0 @@
|
||||
package ru.ibs.tests;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class TestTrainingAppline {
|
||||
|
||||
private WebDriver driver;
|
||||
private WebDriverWait wait;
|
||||
Duration default_timeout = Duration.ofSeconds(10);
|
||||
Duration default_sleep = Duration.ofMillis(500);
|
||||
String fieldXPath = "//input[@id='%s']";
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
// win
|
||||
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");
|
||||
|
||||
driver = new ChromeDriver();
|
||||
driver.manage().window().maximize();
|
||||
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));
|
||||
driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(30));
|
||||
|
||||
wait = new WebDriverWait(driver, default_timeout, default_sleep);
|
||||
|
||||
String baseUrl = "http://training.appline.ru/user/login";
|
||||
driver.get(baseUrl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applineLoginScenario() throws InterruptedException {
|
||||
|
||||
WebElement usernameField = driver.findElement(By.xpath(String.format(fieldXPath, "prependedInput")));
|
||||
fillInputField(usernameField, "Irina Filippova");
|
||||
|
||||
WebElement passwordField = driver.findElement(By.xpath(String.format(fieldXPath, "prependedInput2")));
|
||||
fillInputField(passwordField, "testing");
|
||||
|
||||
// Нажать на кнопку Войти
|
||||
String buttonLocator = "//button[@type='submit']";
|
||||
WebElement loginButton = driver.findElement(By.xpath(buttonLocator));
|
||||
scrollToElementJs(loginButton);
|
||||
waitUtilElementToBeClickable(loginButton);
|
||||
loginButton.click();
|
||||
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
driver.quit();
|
||||
}
|
||||
|
||||
private void scrollToElementJs(WebElement element) {
|
||||
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
|
||||
javascriptExecutor.executeScript("arguments[0].scrollIntoView(true);", element);
|
||||
}
|
||||
|
||||
private void waitUtilElementToBeClickable(WebElement element) {
|
||||
wait.until(ExpectedConditions.elementToBeClickable(element));
|
||||
}
|
||||
|
||||
private void waitUtilElementToBeVisible(By locator) {
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
|
||||
}
|
||||
|
||||
private void waitUtilElementToBeVisible(WebElement element) {
|
||||
wait.until(ExpectedConditions.visibilityOf(element));
|
||||
}
|
||||
|
||||
private void fillInputField(WebElement element, String value) {
|
||||
scrollToElementJs(element);
|
||||
waitUtilElementToBeClickable(element);
|
||||
element.click();
|
||||
element.clear();
|
||||
element.sendKeys(value);
|
||||
boolean checkFlag = wait.until(ExpectedConditions.attributeContains(element, "value", value));
|
||||
Assert.assertTrue("Поле было заполнено некорректно", checkFlag);
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user