Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>Sprint_4</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.6.3</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
Comment thread
AngryNiko marked this conversation as resolved.
<artifactId>selenium-java</artifactId>
<version>4.15.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
61 changes: 61 additions & 0 deletions src/main/java/pageobject/MainPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package pageobject;

import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class MainPage {

private final WebDriver driver;
private final WebDriverWait wait;

public static final String URL = "https://qa-scooter.praktikum-services.ru/";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно улучшить: константы лучше хранить в отдельном классе, урл не является частью страницы


public MainPage(WebDriver driver) {
this.driver = driver;
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}

public void open() {
driver.get(URL);
}

// Верхняя кнопка «Заказать»
private final By orderButtonTop =
By.className("Button_Button__ra12g");

// Нижняя кнопка «Заказать»
private final By orderButtonBottom =
By.xpath(".//button[contains(@class,'Button_Middle__1CSJM')]");

// Вопрос о важном
public By questionHeading(int index) {
return By.id("accordion__heading-" + index);
}
// Ответ о важном
public By answerPanel(int index) {
return By.id("accordion__panel-" + index);
}
// Верхняя кнопка заказа
public void clickTopOrderButton() {
wait.until(ExpectedConditions.elementToBeClickable(orderButtonTop)).click();
}
// Нижняя кнопка заказа
public void clickBottomOrderButton() {
WebElement bottomButton = driver.findElement(orderButtonBottom);
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", bottomButton);
wait.until(ExpectedConditions.elementToBeClickable(orderButtonBottom)).click();
}
// Открыть вопросы о важном
public void openQuestion(int index) {
WebElement question = wait.until(ExpectedConditions.visibilityOfElementLocated(questionHeading(index)));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", question);
wait.until(ExpectedConditions.elementToBeClickable(question)).click();
}
// Получить ответы о важном
public String getAnswerText(int index) {
return wait.until(ExpectedConditions.visibilityOfElementLocated(answerPanel(index))).getText();
}
}
72 changes: 72 additions & 0 deletions src/main/java/pageobject/OrderPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package pageobject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class OrderPage {

private final WebDriver driver;
private final WebDriverWait wait;

public OrderPage(WebDriver driver) {
this.driver = driver;
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}

// Первая форма заказа
private final By firstName = By.xpath(".//input[@placeholder='* Имя']");
private final By lastName = By.xpath(".//input[@placeholder='* Фамилия']");
private final By address = By.xpath(".//input[@placeholder='* Адрес: куда привезти заказ']");
private final By metro = By.xpath(".//input[@placeholder='* Станция метро']");
private final By phone = By.xpath(".//input[@placeholder='* Телефон: на него позвонит курьер']");
private final By nextButton = By.xpath(".//button[text()='Далее']");

// Вторая форма заказа
private final By dateField = By.xpath(".//input[@placeholder='* Когда привезти самокат']");
private final By rentDropdown = By.className("Dropdown-placeholder");
private final By orderButton = By.xpath(".//div[contains(@class,'Order_Buttons')]//button[text()='Заказать']");
private final By confirmYes = By.xpath(".//button[text()='Да']");
// Заполнение первой формы
public void fillFirstForm(String name, String surname, String addr, String station, String phoneNum) {
wait.until(ExpectedConditions.visibilityOfElementLocated(firstName)).sendKeys(name);
driver.findElement(lastName).sendKeys(surname);
driver.findElement(address).sendKeys(addr);

driver.findElement(metro).click();
wait.until(ExpectedConditions.elementToBeClickable(
By.xpath(".//div[text()='" + station + "']"))).click();

driver.findElement(phone).sendKeys(phoneNum);
driver.findElement(nextButton).click();
}
// Заполнение второй формы
public void fillSecondForm(
String date,
String rentPeriod,
boolean black,
boolean grey
) {
wait.until(ExpectedConditions.elementToBeClickable(dateField)).click();
driver.findElement(By.xpath(".//div[text()='" + date + "']")).click();

driver.findElement(rentDropdown).click();
wait.until(ExpectedConditions.elementToBeClickable(
By.xpath(".//div[text()='" + rentPeriod + "']"))).click();

if (black) driver.findElement(By.id("black")).click();
if (grey) driver.findElement(By.id("grey")).click();

wait.until(ExpectedConditions.elementToBeClickable(orderButton)).click();
wait.until(ExpectedConditions.elementToBeClickable(confirmYes)).click();
}
//Появление окна оформленного заказа
private final By orderSuccessHeader = By.xpath(".//div[contains(text(),'Заказ оформлен')]");

public boolean isOrderSuccessDisplayed() {
return wait.until(ExpectedConditions.visibilityOfElementLocated(orderSuccessHeader)).isDisplayed();
}
}
74 changes: 74 additions & 0 deletions src/test/java/tests/ImportantQuestionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package tests;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.openqa.selenium.WebDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import pageobject.MainPage;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class ImportantQuestionsTest {

private WebDriver driver;
private MainPage mainPage;

private final int questionIndex;
private final String expectedAnswer;

public ImportantQuestionsTest(int questionIndex, String expectedAnswer) {
this.questionIndex = questionIndex;
this.expectedAnswer = expectedAnswer;
}

@Parameterized.Parameters
public static Collection<Object[]> testData() {
return Arrays.asList(new Object[][]{
{0, "Сутки — 400 рублей. Оплата курьеру — наличными или картой."},
{1, "Пока что у нас так: один заказ — один самокат. Если хотите покататься с друзьями, можете просто сделать несколько заказов — один за другим."},
{2, "Допустим, вы оформляете заказ на 8 мая. Мы привозим самокат 8 мая в течение дня. Отсчёт времени аренды начинается с момента, когда вы оплатите заказ курьеру. Если мы привезли самокат 8 мая в 20:30, суточная аренда закончится 9 мая в 20:30."},
{3, "Только начиная с завтрашнего дня. Но скоро станем расторопнее."},
{4, "Пока что нет! Но если что-то срочное — всегда можно позвонить в поддержку по красивому номеру 1010."},
{5, "Самокат приезжает к вам с полной зарядкой. Этого хватает на восемь суток — даже если будете кататься без передышек и во сне. Зарядка не понадобится."},
{6, "Да, пока самокат не привезли. Штрафа не будет, объяснительной записки тоже не попросим. Все же свои."},
{7, "Да, обязательно. Всем самокатов! И Москве, и Московской области."}
});
}

@Before
public void setUp() {
String browser = System.getProperty("browser", "chrome");

if (browser.equals("chrome")) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
} else if (browser.equals("firefox")) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
}

driver.get("https://qa-scooter.praktikum-services.ru/");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: у тебя есть переменная с этим значением

mainPage = new MainPage(driver);
}

@Test
public void checkQuestionAnswer() {
mainPage.openQuestion(questionIndex);
String actualAnswer = mainPage.getAnswerText(questionIndex);
assertEquals(expectedAnswer, actualAnswer);
}

@After
public void tearDown() {
driver.quit();
}
}
94 changes: 94 additions & 0 deletions src/test/java/tests/OrderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package tests;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.openqa.selenium.WebDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import pageobject.MainPage;
import pageobject.OrderPage;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertTrue;

@RunWith(Parameterized.class)
public class OrderTest {

private WebDriver driver;
private MainPage mainPage;
private OrderPage orderPage;

private final boolean useTopButton;
private final String name;
private final String surname;
private final String address;
private final String metro;
private final String phone;
private final String date;
private final String rentPeriod;
private final boolean black;
private final boolean grey;

public OrderTest(boolean useTopButton, String name, String surname, String address, String metro, String phone, String date, String rentPeriod, boolean black, boolean grey) {
this.useTopButton = useTopButton;
this.name = name;
this.surname = surname;
this.address = address;
this.metro = metro;
this.phone = phone;
this.date = date;
this.rentPeriod = rentPeriod;
this.black = black;
this.grey = grey;
}

@Parameterized.Parameters
public static Collection<Object[]> testData() {
return Arrays.asList(new Object[][]{
{true, "Иван", "Иванов", "Московская, 12", "Черкизовская", "89999999999", "22", "двое суток", true, false},
{false, "Анна", "Петрова", "Какаято, 8А", "Сокольники", "88888888888", "23", "трое суток", false, true}
});
}

@Before
public void setUp() {
String browser = System.getProperty("browser", "chrome");

if (browser.equals("chrome")) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
} else if (browser.equals("firefox")) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
}

driver.get("https://qa-scooter.praktikum-services.ru/");
mainPage = new MainPage(driver);
orderPage = new OrderPage(driver);
}

@Test
public void orderTest() {

if (useTopButton) {
mainPage.clickTopOrderButton();
} else {
mainPage.clickBottomOrderButton();
}

orderPage.fillFirstForm(name, surname, address, metro, phone);
orderPage.fillSecondForm(date, rentPeriod, black, grey);
assertTrue("Окно успешного заказа не отображается", orderPage.isOrderSuccessDisplayed());
}

@After
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно улучшить: действие нужно для каждого теста, лучше вынести на уровень выше

public void tearDown() {
driver.quit();
}
}