diff --git a/pom.xml b/pom.xml index 39b051d..9adfd42 100644 --- a/pom.xml +++ b/pom.xml @@ -1,58 +1,30 @@ - - + 4.0.0 - ru.ibs - appline-test-project + sel1 1.0-SNAPSHOT - - - 11 - 11 - UTF-8 - + Archetype - sel1 + https://git.goodtester.ru - - - junit - junit - 4.13.2 - - + org.seleniumhq.selenium selenium-java 4.33.0 + - commons-configuration - commons-configuration - 1.10 + junit + junit + 4.13.1 + test + - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.1.2 - - - **/*Test.java - - - src/test/resources/environment.properties - - - - - + diff --git a/src/test/java/ru/ibs/tests/ApplineBusinessTripTest.java b/src/test/java/ru/ibs/tests/ApplineBusinessTripTest.java deleted file mode 100644 index 99b2ecb..0000000 --- a/src/test/java/ru/ibs/tests/ApplineBusinessTripTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package ru.ibs.tests; - -import org.junit.*; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; - -import java.time.Duration; - -public class ApplineBusinessTripTest { - - private WebDriver driver; - private LoginPage loginPage; - - @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)); - - driver.get("http://training.appline.ru/user/login"); - - loginPage = new LoginPage(driver); - } - - @Test - public void applineLoginScenario() { - DashboardPage dashboardPage = loginPage.login("Irina Filippova", "testing"); - Assert.assertTrue("Dashboard not loaded", dashboardPage.isDashboardLoaded()); - - BusinessTripPage businessTripPage = dashboardPage.goToBusinessTrip(); - Assert.assertTrue("Trips page not loaded", businessTripPage.isTripsPageLoaded()); - - businessTripPage.openCreateTripForm(); - - businessTripPage.selectDepartment("Отдел внутренней разработки"); - businessTripPage.selectOrganization("Edge"); - businessTripPage.setTicketsCheckbox(true); - businessTripPage.fillCity("Дмитров"); - - 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" - ); - - businessTripPage.saveAndClose(); - - Assert.assertTrue("Expected validation error not shown", - businessTripPage.isErrorDisplayed("Список командируемых сотрудников не может быть пустым")); - } - - @After - public void tearDown() { - if (driver != null) { - driver.quit(); - } - } -} diff --git a/src/test/java/ru/ibs/tests/TestTrainingAppline.java b/src/test/java/ru/ibs/tests/TestTrainingAppline.java new file mode 100644 index 0000000..903d21b --- /dev/null +++ b/src/test/java/ru/ibs/tests/TestTrainingAppline.java @@ -0,0 +1,89 @@ +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); + } + +}