|
|
|
@@ -1,17 +1,16 @@
|
|
|
|
|
package ru.ibs.tests;
|
|
|
|
|
|
|
|
|
|
import org.junit.*;
|
|
|
|
|
import org.openqa.selenium.*;
|
|
|
|
|
import org.openqa.selenium.By;
|
|
|
|
|
import org.openqa.selenium.WebDriver;
|
|
|
|
|
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;
|
|
|
|
|
private LoginPage loginPage;
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void setUp() {
|
|
|
|
@@ -20,126 +19,47 @@ public class ApplineBusinessTripTest {
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
loginPage = new LoginPage(driver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void applineLoginScenario() {
|
|
|
|
|
// Логин
|
|
|
|
|
fillInputField(By.id("prependedInput"), "Irina Filippova");
|
|
|
|
|
fillInputField(By.id("prependedInput2"), "testing");
|
|
|
|
|
DashboardPage dashboardPage = loginPage.login("Irina Filippova", "testing");
|
|
|
|
|
Assert.assertTrue("Dashboard not loaded", dashboardPage.isDashboardLoaded());
|
|
|
|
|
|
|
|
|
|
WebElement loginButton = driver.findElement(By.xpath("//button[@type='submit']"));
|
|
|
|
|
waitUntilClickable(loginButton).click();
|
|
|
|
|
BusinessTripPage businessTripPage = dashboardPage.goToBusinessTrip();
|
|
|
|
|
Assert.assertTrue("Trips page not loaded", businessTripPage.isTripsPageLoaded());
|
|
|
|
|
|
|
|
|
|
// Проверка заголовка
|
|
|
|
|
WebElement dashboardTitle = wait.until(ExpectedConditions.visibilityOfElementLocated(
|
|
|
|
|
By.xpath("//h1[@class='oro-subtitle' and contains(text(), 'Панель быстрого запуска')]")));
|
|
|
|
|
Assert.assertTrue("Заголовок 'Панель быстрого запуска' не найден", dashboardTitle.isDisplayed());
|
|
|
|
|
businessTripPage.openCreateTripForm();
|
|
|
|
|
|
|
|
|
|
// Наведение на меню "Расходы" и клик по "Командировки"
|
|
|
|
|
Actions actions = new Actions(driver);
|
|
|
|
|
WebElement expensesMenu = driver.findElement(By.xpath("//span[text()='Расходы']/ancestor::li"));
|
|
|
|
|
actions.moveToElement(expensesMenu).perform();
|
|
|
|
|
businessTripPage.selectDepartment("Отдел внутренней разработки");
|
|
|
|
|
businessTripPage.selectOrganization("Edge");
|
|
|
|
|
businessTripPage.setTicketsCheckbox(true);
|
|
|
|
|
businessTripPage.fillCity("Дмитров");
|
|
|
|
|
|
|
|
|
|
WebElement businessTrip = wait.until(ExpectedConditions.elementToBeClickable(
|
|
|
|
|
By.xpath("//a[@href='/business-trip/']/span[text()='Командировки']")));
|
|
|
|
|
businessTrip.click();
|
|
|
|
|
businessTripPage.fillDate(
|
|
|
|
|
By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'departureDatePlan')]"),
|
|
|
|
|
"01.01.2025"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div.loader-overlay")));
|
|
|
|
|
businessTripPage.fillDate(
|
|
|
|
|
By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'returnDatePlan')]"),
|
|
|
|
|
"10.01.2025"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
WebElement tripsHeader = wait.until(ExpectedConditions.visibilityOfElementLocated(
|
|
|
|
|
By.xpath("//h1[contains(text(), 'Командировки')]")));
|
|
|
|
|
Assert.assertTrue(tripsHeader.isDisplayed());
|
|
|
|
|
businessTripPage.saveAndClose();
|
|
|
|
|
|
|
|
|
|
// Клик по "Создать командировку"
|
|
|
|
|
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());
|
|
|
|
|
Assert.assertTrue("Expected validation error not shown",
|
|
|
|
|
businessTripPage.isErrorDisplayed("Список командируемых сотрудников не может быть пустым"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void tearDown() {
|
|
|
|
|
if (driver != null)
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|