v2-1
This commit is contained in:
parent
7f7ec064ef
commit
2829cfe461
145
src/test/java/ru/ibs/tests/ApplineBusinessTripTest.java
Normal file
145
src/test/java/ru/ibs/tests/ApplineBusinessTripTest.java
Normal file
@ -0,0 +1,145 @@
|
||||
package ru.ibs.tests;
|
||||
|
||||
import org.junit.*;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
import org.openqa.selenium.support.ui.*;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class ApplineBusinessTripTest {
|
||||
|
||||
private WebDriver driver;
|
||||
private WebDriverWait wait;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");
|
||||
|
||||
driver = new ChromeDriver();
|
||||
driver.manage().window().maximize();
|
||||
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
|
||||
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
||||
|
||||
driver.get("http://training.appline.ru/user/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applineLoginScenario() {
|
||||
// Логин
|
||||
fillInputField(By.id("prependedInput"), "Irina Filippova");
|
||||
fillInputField(By.id("prependedInput2"), "testing");
|
||||
|
||||
WebElement loginButton = driver.findElement(By.xpath("//button[@type='submit']"));
|
||||
waitUntilClickable(loginButton).click();
|
||||
|
||||
// Проверка заголовка
|
||||
WebElement dashboardTitle = wait.until(ExpectedConditions.visibilityOfElementLocated(
|
||||
By.xpath("//h1[@class='oro-subtitle' and contains(text(), 'Панель быстрого запуска')]")));
|
||||
Assert.assertTrue("Заголовок 'Панель быстрого запуска' не найден", dashboardTitle.isDisplayed());
|
||||
|
||||
// Наведение на меню "Расходы" и клик по "Командировки"
|
||||
Actions actions = new Actions(driver);
|
||||
WebElement expensesMenu = driver.findElement(By.xpath("//span[text()='Расходы']/ancestor::li"));
|
||||
actions.moveToElement(expensesMenu).perform();
|
||||
|
||||
WebElement businessTrip = wait.until(ExpectedConditions.elementToBeClickable(
|
||||
By.xpath("//a[@href='/business-trip/']/span[text()='Командировки']")));
|
||||
businessTrip.click();
|
||||
|
||||
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div.loader-overlay")));
|
||||
|
||||
WebElement tripsHeader = wait.until(ExpectedConditions.visibilityOfElementLocated(
|
||||
By.xpath("//h1[contains(text(), 'Командировки')]")));
|
||||
Assert.assertTrue(tripsHeader.isDisplayed());
|
||||
|
||||
// Клик по "Создать командировку"
|
||||
WebElement containerDiv = wait.until(ExpectedConditions.elementToBeClickable(
|
||||
By.cssSelector("div.pull-left.btn-group.icons-holder")
|
||||
));
|
||||
|
||||
containerDiv.click();
|
||||
|
||||
// Проверка заголовка "Создать командировку"
|
||||
WebElement createTripHeader = wait.until(ExpectedConditions.visibilityOfElementLocated(
|
||||
By.xpath("//h1[@class='user-name' and contains(text(), 'Создать командировку')]")));
|
||||
Assert.assertTrue(createTripHeader.isDisplayed());
|
||||
|
||||
// Подразделение
|
||||
WebElement departmentSelect = driver.findElement(By.xpath("//select[contains(@name,'businessUnit')]"));
|
||||
new Select(departmentSelect).selectByVisibleText("Отдел внутренней разработки");
|
||||
|
||||
// Принимающая организация
|
||||
driver.findElement(By.id("company-selector-show")).click();
|
||||
|
||||
WebElement organizationSpan = wait.until(ExpectedConditions.elementToBeClickable(
|
||||
By.cssSelector("span.select2-chosen")
|
||||
));
|
||||
organizationSpan.click();
|
||||
|
||||
WebElement input = wait.until(ExpectedConditions.visibilityOfElementLocated(
|
||||
By.cssSelector("input.select2-input")
|
||||
));
|
||||
|
||||
input.sendKeys("Edge");
|
||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='select2-match' and text()='Edge']"))).click();
|
||||
|
||||
// Чекбокс "Заказ билетов"
|
||||
WebElement ticketsCheckbox = driver.findElement(By.xpath("//label[contains(text(),'Заказ билетов')]/preceding-sibling::input"));
|
||||
if (!ticketsCheckbox.isSelected()) {
|
||||
ticketsCheckbox.click();
|
||||
}
|
||||
|
||||
// Заполнить города
|
||||
fillInputField(By.xpath("//input[contains(@id,'arrivalCity')]"), "Дмитров");
|
||||
|
||||
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div.loader-overlay")));
|
||||
// Даты
|
||||
By departureDateLocator = By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'departureDatePlan')]");
|
||||
By returnDateLocator = By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'returnDatePlan')]");
|
||||
|
||||
fillDateField(departureDateLocator, "01.01.2025");
|
||||
fillDateField(returnDateLocator, "10.01.2025");
|
||||
|
||||
// Сохранить и закрыть
|
||||
WebElement saveBtn = driver.findElement(By.xpath("//button[contains(text(),'Сохранить и закрыть')]"));
|
||||
scrollToElement(saveBtn);
|
||||
saveBtn.click();
|
||||
|
||||
WebElement errorMsg = wait.until(ExpectedConditions.visibilityOfElementLocated(
|
||||
By.xpath("//span[@class='validation-failed' and contains(text(), 'Список командируемых сотрудников не может быть пустым')]")));
|
||||
Assert.assertTrue("Ожидаемая ошибка не найдена", errorMsg.isDisplayed());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (driver != null)
|
||||
driver.quit();
|
||||
}
|
||||
|
||||
private WebElement waitUntilClickable(WebElement element) {
|
||||
return wait.until(ExpectedConditions.elementToBeClickable(element));
|
||||
}
|
||||
|
||||
private void fillInputField(By locator, String value) {
|
||||
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
|
||||
scrollToElement(element);
|
||||
element.clear();
|
||||
element.sendKeys(value);
|
||||
Assert.assertEquals("Поле заполнено некорректно", value, element.getAttribute("value"));
|
||||
}
|
||||
|
||||
private void fillDateField(By locator, String dateValue) {
|
||||
WebElement dateInput = wait.until(ExpectedConditions.elementToBeClickable(locator));
|
||||
scrollToElement(dateInput);
|
||||
dateInput.clear();
|
||||
dateInput.sendKeys(dateValue);
|
||||
dateInput.sendKeys(Keys.TAB);
|
||||
Assert.assertEquals("Поле даты заполнено некорректно", dateValue, dateInput.getAttribute("value"));
|
||||
}
|
||||
|
||||
private void scrollToElement(WebElement element) {
|
||||
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user