148 lines
6.7 KiB
Java
148 lines
6.7 KiB
Java
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);
|
||
}
|
||
}
|