regard scenario 1
This commit is contained in:
parent
4d10c1446f
commit
90bed51df4
@ -1,3 +1,6 @@
|
|||||||
Изменён pom файл для поддержки cucumber, добавлен cucumberScenario.feature, класс BusinessTripSteps
|
Итоговое задание для магазина "Регард" с использованием Cucumber.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||

|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package ru.ibs.framework;
|
|
||||||
|
|
||||||
import io.cucumber.junit.Cucumber;
|
|
||||||
import io.cucumber.junit.CucumberOptions;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
@RunWith(Cucumber.class)
|
|
||||||
@CucumberOptions(
|
|
||||||
features = "src/test/resources/features",
|
|
||||||
glue = "ru.ibs.tests",
|
|
||||||
plugin = {"pretty", "io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"},
|
|
||||||
snippets = CucumberOptions.SnippetType.CAMELCASE
|
|
||||||
)
|
|
||||||
public class CucumberRunner {}
|
|
16
src/test/java/ru/ibs/framework/RegardTestRunner.java
Normal file
16
src/test/java/ru/ibs/framework/RegardTestRunner.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package ru.ibs.framework;
|
||||||
|
|
||||||
|
import io.cucumber.junit.Cucumber;
|
||||||
|
import io.cucumber.junit.CucumberOptions;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(Cucumber.class)
|
||||||
|
@CucumberOptions(
|
||||||
|
features = "src/test/resources/features",
|
||||||
|
glue = "ru.ibs.tests",
|
||||||
|
plugin = {
|
||||||
|
"pretty",
|
||||||
|
"io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public class RegardTestRunner {}
|
@ -1,45 +1,46 @@
|
|||||||
package ru.ibs.framework.pages;
|
package ru.appline.framework.pages;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.JavascriptExecutor;
|
import org.openqa.selenium.JavascriptExecutor;
|
||||||
|
import org.openqa.selenium.Keys;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.support.PageFactory;
|
|
||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
import ru.ibs.framework.managers.DriverManager;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BasePage {
|
public abstract class BasePage {
|
||||||
|
protected WebDriver driver;
|
||||||
|
protected WebDriverWait wait;
|
||||||
|
|
||||||
protected WebDriver driver = DriverManager.getDriverManager().getDriver();
|
public BasePage(WebDriver driver) {
|
||||||
protected WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
this.driver = driver;
|
||||||
|
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
||||||
public BasePage() {
|
|
||||||
PageFactory.initElements(driver, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fillInputField(By locator, String value) {
|
protected void click(By locator) {
|
||||||
WebElement el = waitUntilVisible(locator);
|
wait.until(ExpectedConditions.elementToBeClickable(locator)).click();
|
||||||
scrollToElement(el);
|
}
|
||||||
|
|
||||||
|
protected void type(By locator, String text) {
|
||||||
|
WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
|
||||||
el.clear();
|
el.clear();
|
||||||
el.sendKeys(value);
|
el.sendKeys(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void scrollToElement(WebElement element) {
|
protected String getText(By locator) {
|
||||||
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
|
return wait.until(ExpectedConditions.visibilityOfElementLocated(locator)).getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected WebElement waitUntilVisible(By locator) {
|
protected List<WebElement> findElements(By locator) {
|
||||||
return wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
|
return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(locator));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected WebElement waitUntilClickable(By locator) {
|
protected void waitForJSIdle() {
|
||||||
return wait.until(ExpectedConditions.elementToBeClickable(locator));
|
new WebDriverWait(driver, Duration.ofSeconds(15)).until(
|
||||||
}
|
wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete")
|
||||||
|
);
|
||||||
protected void waitUntilInvisible(By locator) {
|
|
||||||
wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
src/test/java/ru/ibs/framework/pages/CatalogPage.java
Normal file
49
src/test/java/ru/ibs/framework/pages/CatalogPage.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package ru.ibs.framework.pages;
|
||||||
|
|
||||||
|
import org.openqa.selenium.*;
|
||||||
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
public class CatalogPage {
|
||||||
|
private final WebDriver driver;
|
||||||
|
private final WebDriverWait wait;
|
||||||
|
|
||||||
|
public CatalogPage(WebDriver driver) {
|
||||||
|
this.driver = driver;
|
||||||
|
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectCategory(String name) {
|
||||||
|
WebElement categoryLink = wait.until(ExpectedConditions.elementToBeClickable(
|
||||||
|
By.xpath("//a[text()='" + name + "']")));
|
||||||
|
categoryLink.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeCookieBannerIfPresent() {
|
||||||
|
try {
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
|
||||||
|
WebElement acceptButton = wait.until(ExpectedConditions.elementToBeClickable(
|
||||||
|
By.cssSelector("button.CookieBannerPopover_acceptBtn__VRuFj")));
|
||||||
|
acceptButton.click();
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (TimeoutException | InterruptedException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectSubCategory(String name) {
|
||||||
|
closeCookieBannerIfPresent(); // Закрыть баннер если есть
|
||||||
|
|
||||||
|
WebElement subCategory = wait.until(ExpectedConditions.presenceOfElementLocated(
|
||||||
|
By.xpath("//p[contains(text(), '" + name + "')]/ancestor::a[1]")));
|
||||||
|
// Клик через JS:
|
||||||
|
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", subCategory);
|
||||||
|
((JavascriptExecutor) driver).executeScript("arguments[0].click();", subCategory);
|
||||||
|
|
||||||
|
// Ждём загрузки фильтра, чтобы убедиться, что перешли
|
||||||
|
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name='min']")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
48
src/test/java/ru/ibs/framework/pages/ListingPage.java
Normal file
48
src/test/java/ru/ibs/framework/pages/ListingPage.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package ru.ibs.framework.pages;
|
||||||
|
|
||||||
|
import org.openqa.selenium.*;
|
||||||
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ListingPage {
|
||||||
|
private final WebDriver driver;
|
||||||
|
private final WebDriverWait wait;
|
||||||
|
|
||||||
|
public ListingPage(WebDriver driver) {
|
||||||
|
this.driver = driver;
|
||||||
|
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinPrice(String price) {
|
||||||
|
WebElement minPrice = driver.findElement(By.cssSelector("input[name='min']"));
|
||||||
|
minPrice.clear();
|
||||||
|
minPrice.sendKeys(price);
|
||||||
|
minPrice.sendKeys(Keys.ENTER);
|
||||||
|
waitForJSIdle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectGigabyte() {
|
||||||
|
WebElement checkbox = wait.until(ExpectedConditions.elementToBeClickable(
|
||||||
|
By.cssSelector("input[id*='Gigabyte'] + label")));
|
||||||
|
checkbox.click();
|
||||||
|
waitForJSIdle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getAllProducts() {
|
||||||
|
return driver.findElements(By.cssSelector("div.Card_wrap__hES44"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstProductTitle() {
|
||||||
|
return wait.until(ExpectedConditions.visibilityOfElementLocated(
|
||||||
|
By.cssSelector("a.CardText_link__C_fPZ > div.CardText_title__7bSbO"))).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void waitForJSIdle() {
|
||||||
|
new WebDriverWait(driver, Duration.ofSeconds(10)).until(driver ->
|
||||||
|
((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
19
src/test/java/ru/ibs/framework/pages/MainPage.java
Normal file
19
src/test/java/ru/ibs/framework/pages/MainPage.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// MainPage.java
|
||||||
|
package ru.ibs.framework.pages;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
public class MainPage {
|
||||||
|
private final WebDriver driver;
|
||||||
|
|
||||||
|
public MainPage(WebDriver driver) {
|
||||||
|
this.driver = driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openCatalog() {
|
||||||
|
WebElement catalogButton = driver.findElement(By.xpath("//span[text()='Каталог']/parent::button"));
|
||||||
|
catalogButton.click();
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +0,0 @@
|
|||||||
package ru.ibs.tests;
|
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import ru.ibs.framework.managers.DriverManager;
|
|
||||||
|
|
||||||
public class BaseTests {
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeAll() {
|
|
||||||
DriverManager.getDriverManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void afterAll() {
|
|
||||||
DriverManager.getDriverManager().quitDriver();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
package ru.ibs.tests;
|
|
||||||
|
|
||||||
import org.openqa.selenium.*;
|
|
||||||
import org.openqa.selenium.support.FindBy;
|
|
||||||
import org.openqa.selenium.support.PageFactory;
|
|
||||||
import org.openqa.selenium.support.ui.*;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public class BusinessTripPage {
|
|
||||||
private final WebDriver driver;
|
|
||||||
private final WebDriverWait wait;
|
|
||||||
|
|
||||||
@FindBy(xpath = "//h1[contains(text(), 'Командировки')]")
|
|
||||||
private WebElement tripsHeader;
|
|
||||||
|
|
||||||
@FindBy(css = "div.pull-left.btn-group.icons-holder")
|
|
||||||
private WebElement createTripButton;
|
|
||||||
|
|
||||||
@FindBy(xpath = "//h1[@class='user-name' and contains(text(), 'Создать командировку')]")
|
|
||||||
private WebElement createTripHeader;
|
|
||||||
|
|
||||||
@FindBy(xpath = "//select[contains(@name,'businessUnit')]")
|
|
||||||
private WebElement departmentSelect;
|
|
||||||
|
|
||||||
@FindBy(id = "company-selector-show")
|
|
||||||
private WebElement companySelectorShow;
|
|
||||||
|
|
||||||
@FindBy(css = "span.select2-chosen")
|
|
||||||
private WebElement organizationSpan;
|
|
||||||
|
|
||||||
@FindBy(css = "input.select2-input")
|
|
||||||
private WebElement organizationInput;
|
|
||||||
|
|
||||||
@FindBy(xpath = "//label[contains(text(),'Заказ билетов')]/preceding-sibling::input")
|
|
||||||
private WebElement ticketsCheckbox;
|
|
||||||
|
|
||||||
@FindBy(xpath = "//button[contains(text(),'Сохранить и закрыть')]")
|
|
||||||
private WebElement saveAndCloseButton;
|
|
||||||
|
|
||||||
public BusinessTripPage(WebDriver driver) {
|
|
||||||
this.driver = driver;
|
|
||||||
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
|
||||||
PageFactory.initElements(driver, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTripsPageLoaded() {
|
|
||||||
return wait.until(ExpectedConditions.visibilityOf(tripsHeader)).isDisplayed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openCreateTripForm() {
|
|
||||||
wait.until(ExpectedConditions.elementToBeClickable(createTripButton)).click();
|
|
||||||
wait.until(ExpectedConditions.visibilityOf(createTripHeader));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void selectDepartment(String departmentName) {
|
|
||||||
Select select = new Select(departmentSelect);
|
|
||||||
select.selectByVisibleText(departmentName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void selectOrganization(String orgName) {
|
|
||||||
companySelectorShow.click();
|
|
||||||
wait.until(ExpectedConditions.elementToBeClickable(organizationSpan)).click();
|
|
||||||
wait.until(ExpectedConditions.visibilityOf(organizationInput)).sendKeys(orgName);
|
|
||||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='select2-match' and text()='" + orgName + "']"))).click();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTicketsCheckbox(boolean checked) {
|
|
||||||
if (ticketsCheckbox.isSelected() != checked) {
|
|
||||||
ticketsCheckbox.click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fillCity(String city) {
|
|
||||||
By cityInputLocator = By.xpath("//input[contains(@id,'arrivalCity')]");
|
|
||||||
WebElement cityInput = wait.until(ExpectedConditions.visibilityOfElementLocated(cityInputLocator));
|
|
||||||
scrollToElement(cityInput);
|
|
||||||
cityInput.clear();
|
|
||||||
cityInput.sendKeys(city);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fillDate(By dateLocator, String dateValue) {
|
|
||||||
WebElement dateInput = wait.until(ExpectedConditions.elementToBeClickable(dateLocator));
|
|
||||||
scrollToElement(dateInput);
|
|
||||||
dateInput.clear();
|
|
||||||
dateInput.sendKeys(dateValue);
|
|
||||||
dateInput.sendKeys(Keys.TAB);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveAndClose() {
|
|
||||||
scrollToElement(saveAndCloseButton);
|
|
||||||
saveAndCloseButton.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isErrorDisplayed(String errorText) {
|
|
||||||
By errorLocator = By.xpath("//span[@class='validation-failed' and contains(text(), '" + errorText + "')]");
|
|
||||||
return wait.until(ExpectedConditions.visibilityOfElementLocated(errorLocator)).isDisplayed();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scrollToElement(WebElement element) {
|
|
||||||
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
package ru.ibs.tests;
|
|
||||||
|
|
||||||
import io.cucumber.java.ru.*;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import io.cucumber.java.After;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import ru.ibs.framework.managers.DriverManager;
|
|
||||||
import ru.ibs.tests.*;
|
|
||||||
|
|
||||||
public class BusinessTripSteps {
|
|
||||||
|
|
||||||
private final LoginPage loginPage = new LoginPage(DriverManager.getDriverManager().getDriver());
|
|
||||||
private DashboardPage dashboardPage;
|
|
||||||
private BusinessTripPage businessTripPage;
|
|
||||||
|
|
||||||
@Дано("Открываем страницу логина")
|
|
||||||
public void openLoginPage() {
|
|
||||||
DriverManager.getDriverManager().getDriver().get("http://training.appline.ru/user/login");
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Вводим логин {string} и пароль {string}")
|
|
||||||
public void login(String username, String password) {
|
|
||||||
dashboardPage = loginPage.login(username, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Проверяем, что панель быстрого запуска загружена")
|
|
||||||
public void dashboardLoaded() {
|
|
||||||
assertTrue("Dashboard not loaded", dashboardPage.isDashboardLoaded());
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Переходим в раздел {string}")
|
|
||||||
public void goToBusinessTrip(String name) {
|
|
||||||
businessTripPage = dashboardPage.goToBusinessTrip();
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Проверяем, что страница {string} загружена")
|
|
||||||
public void tripsPageLoaded(String title) {
|
|
||||||
assertTrue("Trips page not loaded", businessTripPage.isTripsPageLoaded());
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Нажимаем на кнопку создания новой командировки")
|
|
||||||
public void openCreateTripForm() {
|
|
||||||
businessTripPage.openCreateTripForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Выбираем подразделение {string}")
|
|
||||||
public void selectDepartment(String department) {
|
|
||||||
businessTripPage.selectDepartment(department);
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Выбираем организацию {string}")
|
|
||||||
public void selectOrganization(String organization) {
|
|
||||||
businessTripPage.selectOrganization(organization);
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Устанавливаем чекбокс {string} в положение {string}")
|
|
||||||
public void setCheckbox(String checkboxName, String value) {
|
|
||||||
boolean checked = Boolean.parseBoolean(value);
|
|
||||||
businessTripPage.setTicketsCheckbox(checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Заполняем поле {string} значением {string}")
|
|
||||||
public void fillCityOrDate(String field, String value) {
|
|
||||||
if (field.equalsIgnoreCase("Город")) {
|
|
||||||
businessTripPage.fillCity(value);
|
|
||||||
} else if (field.equalsIgnoreCase("Дата отправления")) {
|
|
||||||
businessTripPage.fillDate(By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'departureDatePlan')]"), value);
|
|
||||||
} else if (field.equalsIgnoreCase("Дата возвращения")) {
|
|
||||||
businessTripPage.fillDate(By.xpath("//input[@placeholder='Укажите дату' and contains(@id, 'returnDatePlan')]"), value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@И("Нажимаем кнопку {string}")
|
|
||||||
public void clickButton(String buttonName) {
|
|
||||||
if (buttonName.equals("Сохранить и закрыть")) {
|
|
||||||
businessTripPage.saveAndClose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Тогда("Проверяем, что отображается ошибка {string}")
|
|
||||||
public void checkError(String errorText) {
|
|
||||||
assertTrue("Expected validation error not shown",
|
|
||||||
businessTripPage.isErrorDisplayed(errorText));
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
DriverManager.getDriverManager().quitDriver();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package ru.ibs.tests;
|
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
import org.openqa.selenium.interactions.Actions;
|
|
||||||
import org.openqa.selenium.support.FindBy;
|
|
||||||
import org.openqa.selenium.support.PageFactory;
|
|
||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public class DashboardPage {
|
|
||||||
private final WebDriver driver;
|
|
||||||
private final WebDriverWait wait;
|
|
||||||
|
|
||||||
@FindBy(xpath = "//h1[@class='oro-subtitle' and contains(text(), 'Панель быстрого запуска')]")
|
|
||||||
private WebElement dashboardTitle;
|
|
||||||
|
|
||||||
@FindBy(xpath = "//span[text()='Расходы']/ancestor::li")
|
|
||||||
private WebElement expensesMenu;
|
|
||||||
|
|
||||||
@FindBy(xpath = "//a[@href='/business-trip/']/span[text()='Командировки']")
|
|
||||||
private WebElement businessTripLink;
|
|
||||||
|
|
||||||
public DashboardPage(WebDriver driver) {
|
|
||||||
this.driver = driver;
|
|
||||||
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
|
||||||
PageFactory.initElements(driver, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDashboardLoaded() {
|
|
||||||
return wait.until(ExpectedConditions.visibilityOf(dashboardTitle)).isDisplayed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BusinessTripPage goToBusinessTrip() {
|
|
||||||
Actions actions = new Actions(driver);
|
|
||||||
actions.moveToElement(expensesMenu).perform();
|
|
||||||
wait.until(ExpectedConditions.elementToBeClickable(businessTripLink)).click();
|
|
||||||
return new BusinessTripPage(driver);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package ru.ibs.tests;
|
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
import org.openqa.selenium.support.FindBy;
|
|
||||||
import org.openqa.selenium.support.PageFactory;
|
|
||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public class LoginPage {
|
|
||||||
private final WebDriver driver;
|
|
||||||
private final WebDriverWait wait;
|
|
||||||
|
|
||||||
@FindBy(id = "prependedInput")
|
|
||||||
private WebElement usernameInput;
|
|
||||||
|
|
||||||
@FindBy(id = "prependedInput2")
|
|
||||||
private WebElement passwordInput;
|
|
||||||
|
|
||||||
@FindBy(xpath = "//button[@type='submit']")
|
|
||||||
private WebElement loginButton;
|
|
||||||
|
|
||||||
public LoginPage(WebDriver driver) {
|
|
||||||
this.driver = driver;
|
|
||||||
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
|
||||||
PageFactory.initElements(driver, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DashboardPage login(String username, String password) {
|
|
||||||
wait.until(ExpectedConditions.visibilityOf(usernameInput)).clear();
|
|
||||||
usernameInput.sendKeys(username);
|
|
||||||
wait.until(ExpectedConditions.visibilityOf(passwordInput)).clear();
|
|
||||||
passwordInput.sendKeys(password);
|
|
||||||
wait.until(ExpectedConditions.elementToBeClickable(loginButton)).click();
|
|
||||||
return new DashboardPage(driver);
|
|
||||||
}
|
|
||||||
}
|
|
106
src/test/java/ru/ibs/tests/SearchSteps.java
Normal file
106
src/test/java/ru/ibs/tests/SearchSteps.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package ru.ibs.tests;
|
||||||
|
|
||||||
|
import io.cucumber.java.After;
|
||||||
|
import io.cucumber.java.ru.Дано;
|
||||||
|
import io.cucumber.java.ru.И;
|
||||||
|
import io.cucumber.java.ru.Тогда;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.Keys;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
import ru.ibs.framework.managers.DriverManager;
|
||||||
|
import ru.ibs.framework.pages.CatalogPage;
|
||||||
|
import ru.ibs.framework.pages.ListingPage;
|
||||||
|
import ru.ibs.framework.pages.MainPage;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class SearchSteps {
|
||||||
|
|
||||||
|
WebDriver driver = DriverManager.getDriverManager().getDriver();
|
||||||
|
MainPage mainPage = new MainPage(driver);
|
||||||
|
CatalogPage catalogPage = new CatalogPage(driver);
|
||||||
|
ListingPage listingPage = new ListingPage(driver);
|
||||||
|
String savedProductTitle;
|
||||||
|
|
||||||
|
@Дано("Открываем сайт regard")
|
||||||
|
public void openSite() {
|
||||||
|
driver.get("https://regard.ru/");
|
||||||
|
driver.manage().window().maximize();
|
||||||
|
catalogPage.closeCookieBannerIfPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Открываем меню Каталог")
|
||||||
|
public void openCatalog() {
|
||||||
|
mainPage.openCatalog();
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Выбираем раздел {string}")
|
||||||
|
public void chooseCategory(String category) {
|
||||||
|
catalogPage.selectCategory(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Выбираем подраздел {string}")
|
||||||
|
public void chooseSubCategory(String sub) {
|
||||||
|
catalogPage.selectSubCategory(sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Задаем цену от {string}")
|
||||||
|
public void setPrice(String price) {
|
||||||
|
listingPage.setMinPrice(price);
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Фильтруем по производителю {string}")
|
||||||
|
public void filterByManufacturer(String name) {
|
||||||
|
if (name.equalsIgnoreCase("Gigabyte")) {
|
||||||
|
listingPage.selectGigabyte();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Проверяем, что товаров не более {int}")
|
||||||
|
public void checkNumberOfProducts(int max) {
|
||||||
|
assertTrue(listingPage.getAllProducts().size() <= max);
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Сохраняем наименование первого товара")
|
||||||
|
public void saveFirstProductName() {
|
||||||
|
savedProductTitle = listingPage.getFirstProductTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Ищем товар по сохраненному имени")
|
||||||
|
public void searchSavedProduct() {
|
||||||
|
WebElement searchInput = driver.findElement(By.id("searchInput"));
|
||||||
|
searchInput.clear();
|
||||||
|
searchInput.sendKeys(savedProductTitle);
|
||||||
|
searchInput.sendKeys(Keys.ENTER);
|
||||||
|
|
||||||
|
// Ждем, пока появится хотя бы один товар на странице результатов поиска
|
||||||
|
new WebDriverWait(driver, Duration.ofSeconds(10)).until(
|
||||||
|
ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.Card_wrap__hES44"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Тогда("На странице только один товар")
|
||||||
|
public void waitForProductsCountChange() {
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
||||||
|
int oldCount = listingPage.getAllProducts().size();
|
||||||
|
wait.until(driver -> driver.findElements(By.cssSelector("div.Card_wrap__hES44")).size() != oldCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@И("Название товара соответствует сохраненному")
|
||||||
|
public void titleShouldMatchSaved() {
|
||||||
|
assertEquals(savedProductTitle, listingPage.getFirstProductTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
DriverManager.getDriverManager().quitDriver();
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +0,0 @@
|
|||||||
# language: ru
|
|
||||||
@businessTrip
|
|
||||||
Функционал: Создание командировки
|
|
||||||
|
|
||||||
Сценарий: Проверка ошибки при попытке создать командировку без сотрудников
|
|
||||||
* Открываем страницу логина
|
|
||||||
* Вводим логин "Irina Filippova" и пароль "testing"
|
|
||||||
* Проверяем, что панель быстрого запуска загружена
|
|
||||||
* Переходим в раздел "Командировки"
|
|
||||||
* Проверяем, что страница "Командировки" загружена
|
|
||||||
* Нажимаем на кнопку создания новой командировки
|
|
||||||
* Выбираем подразделение "Отдел внутренней разработки"
|
|
||||||
* Выбираем организацию "Edge"
|
|
||||||
* Устанавливаем чекбокс "Заказ билетов" в положение "true"
|
|
||||||
* Заполняем поле "Город" значением "Дмитров"
|
|
||||||
* Заполняем поле "Дата отправления" значением "01.01.2025"
|
|
||||||
* Заполняем поле "Дата возвращения" значением "10.01.2025"
|
|
||||||
* Нажимаем кнопку "Сохранить и закрыть"
|
|
||||||
* Проверяем, что отображается ошибка "Список командируемых сотрудников не может быть пустым"
|
|
15
src/test/resources/features/regard_search.feature
Normal file
15
src/test/resources/features/regard_search.feature
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# language: ru
|
||||||
|
Функциональность: Поиск видеокарты на сайте regard.ru
|
||||||
|
|
||||||
|
Сценарий: Поиск видеокарты Gigabyte с фильтрами и проверкой результатов
|
||||||
|
Дано Открываем сайт regard
|
||||||
|
И Открываем меню Каталог
|
||||||
|
И Выбираем раздел "Комплектующие для ПК"
|
||||||
|
И Выбираем подраздел "Видеокарты"
|
||||||
|
И Задаем цену от "20000"
|
||||||
|
И Фильтруем по производителю "Gigabyte"
|
||||||
|
И Проверяем, что товаров не более 24
|
||||||
|
И Сохраняем наименование первого товара
|
||||||
|
И Ищем товар по сохраненному имени
|
||||||
|
Тогда На странице только один товар
|
||||||
|
И Название товара соответствует сохраненному
|
Loading…
x
Reference in New Issue
Block a user