-
Notifications
You must be signed in to change notification settings - Fork 0
Add Stellar Burgers UI tests #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
supogolik-code
wants to merge
3
commits into
main
Choose a base branch
from
develop3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| target/ | ||
| .allure/ | ||
| allure-results/ | ||
| allure-report/ | ||
| .idea/ | ||
| *.iml | ||
| tools/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Stellar Burgers UI tests | ||
|
|
||
| UI autotests based on Page Object. The project uses JUnit 4, Selenium, and Allure. | ||
|
|
||
| ## Test coverage | ||
|
|
||
| The UI suite checks: | ||
|
|
||
| - registration with valid data; | ||
| - validation for a short password during registration; | ||
| - login from the home page, personal account link, registration form, and password recovery form; | ||
| - switching constructor sections: buns, sauces, and fillings. | ||
|
|
||
| ## Run in Google Chrome | ||
|
|
||
| ```shell | ||
| mvn clean test -Dbrowser=chrome | ||
| ``` | ||
|
|
||
| ## Run in Yandex Browser | ||
|
|
||
| ```shell | ||
| mvn clean test -Dbrowser=yandex | ||
| ``` | ||
|
|
||
| If Yandex Browser is installed in a non-standard directory, pass the executable explicitly: | ||
|
|
||
| ```shell | ||
| mvn clean test -Dbrowser=yandex -Dyandex.binary="C:\path\to\browser.exe" | ||
| ``` | ||
|
|
||
| If Selenium Manager cannot pick a ChromeDriver version compatible with Yandex Browser, pass the driver explicitly: | ||
|
|
||
| ```shell | ||
| mvn clean test -Dbrowser=yandex -Dyandex.driver="C:\path\to\chromedriver.exe" | ||
| ``` | ||
|
|
||
| The default mode is headless. Use `-Dheadless=false` to see the browser. | ||
|
|
||
| ## Test reports | ||
|
|
||
| JUnit/Surefire XML and text reports are generated after each test run: | ||
|
|
||
| ```text | ||
| target/surefire-reports/ | ||
| ``` | ||
|
|
||
| Allure raw results are generated here: | ||
|
|
||
| ```text | ||
| target/allure-results/ | ||
| ``` | ||
|
|
||
| Generate a static Allure report: | ||
|
|
||
| ```shell | ||
| mvn allure:report | ||
| ``` | ||
|
|
||
| The generated report entry point is: | ||
|
|
||
| ```text | ||
| target/site/allure-maven-plugin/index.html | ||
| ``` | ||
|
|
||
| To open the report through a temporary local server, use: | ||
|
|
||
| ```shell | ||
| mvn allure:serve | ||
| ``` | ||
|
|
||
| The latest documented test run is available in `docs/test-report.md`. The static Allure report artifact for that run is stored in `reports/allure-report-2026-09-06.zip`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # UI test report | ||
|
|
||
| Run date: 2026-09-06 22:10 MSK | ||
|
|
||
| Project: Stellar Burgers UI tests | ||
|
|
||
| Environment: | ||
|
|
||
| - OS: Windows 10 amd64 | ||
| - Java: OpenJDK 11.0.31 Amazon Corretto | ||
| - Maven: Apache Maven 3.9.15 | ||
| - Browser: Google Chrome 152.0.7977.76 | ||
| - Test command: `mvn clean test -Dbrowser=chrome` | ||
| - Allure command: `mvn allure:report` | ||
|
|
||
| ## Summary | ||
|
|
||
| | Suite | Tests | Passed | Failed | Errors | Skipped | Time | | ||
| | --- | ---: | ---: | ---: | ---: | ---: | ---: | | ||
| | `ConstructorSectionTest` | 3 | 3 | 0 | 0 | 0 | 31.74 s | | ||
| | `LoginTest` | 4 | 4 | 0 | 0 | 0 | 50.42 s | | ||
| | `RegistrationTest` | 2 | 2 | 0 | 0 | 0 | 20.62 s | | ||
| | **Total** | **9** | **9** | **0** | **0** | **0** | **102.60 s** | | ||
|
|
||
| Result: build success, all UI tests passed. | ||
|
|
||
| Generated reports: | ||
|
|
||
| - Surefire reports: `target/surefire-reports/` | ||
| - Allure raw results: `target/allure-results/` | ||
| - Static Allure report: `target/site/allure-maven-plugin/index.html` | ||
| - Attached static report artifact: `reports/allure-report-2026-09-06.zip` | ||
|
|
||
| Note: Selenium printed CDP version warnings for Chrome 152.0.7977.76, but the warnings did not affect the test result. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>ru.praktikum</groupId> | ||
| <artifactId>stellar-burgers-ui-tests</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> | ||
| <junit.version>4.13.2</junit.version> | ||
| <selenium.version>4.23.1</selenium.version> | ||
| <allure.version>2.29.0</allure.version> | ||
| <gson.version>2.11.0</gson.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>${junit.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.seleniumhq.selenium</groupId> | ||
| <artifactId>selenium-java</artifactId> | ||
| <version>${selenium.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.qameta.allure</groupId> | ||
| <artifactId>allure-junit4</artifactId> | ||
| <version>${allure.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.code.gson</groupId> | ||
| <artifactId>gson</artifactId> | ||
| <version>${gson.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>3.11.0</version> | ||
| <configuration> | ||
| <compilerId>eclipse</compilerId> | ||
| </configuration> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.codehaus.plexus</groupId> | ||
| <artifactId>plexus-compiler-eclipse</artifactId> | ||
| <version>2.13.0</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>3.2.5</version> | ||
| <configuration> | ||
| <systemPropertyVariables> | ||
| <allure.results.directory>${project.build.directory}/allure-results</allure.results.directory> | ||
| </systemPropertyVariables> | ||
| <properties> | ||
| <property> | ||
| <name>listener</name> | ||
| <value>io.qameta.allure.junit4.AllureJunit4</value> | ||
| </property> | ||
| </properties> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>io.qameta.allure</groupId> | ||
| <artifactId>allure-maven</artifactId> | ||
| <version>2.15.2</version> | ||
| <configuration> | ||
| <reportVersion>${allure.version}</reportVersion> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
Binary file not shown.
72 changes: 72 additions & 0 deletions
72
src/test/java/ru/praktikum/stellarburgers/ui/api/UserApiHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package ru.praktikum.stellarburgers.ui.api; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonParser; | ||
| import io.qameta.allure.Step; | ||
| import ru.praktikum.stellarburgers.ui.config.TestConfig; | ||
| import ru.praktikum.stellarburgers.ui.model.TestUser; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpRequest; | ||
| import java.net.http.HttpResponse; | ||
|
|
||
| public class UserApiHelper { | ||
|
|
||
| private final HttpClient client = HttpClient.newHttpClient(); | ||
| private final Gson gson = new Gson(); | ||
|
|
||
| @Step("Create test user via API") | ||
| public String create(TestUser user) { | ||
| return sendForToken("/auth/register", user); | ||
| } | ||
|
|
||
| @Step("Login test user via API") | ||
| public String login(TestUser user) { | ||
| return sendForToken("/auth/login", user); | ||
| } | ||
|
|
||
| @Step("Delete test user via API") | ||
| public void delete(String accessToken) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛔️Нужно исправить. Для всех методов, описывающих шаги теста, необходимо использовать аннотацию @step |
||
| if (accessToken == null) { | ||
| return; | ||
| } | ||
| HttpRequest request = HttpRequest.newBuilder() | ||
| .uri(URI.create(TestConfig.API_URL + "/auth/user")) | ||
| .header("Authorization", accessToken) | ||
| .DELETE() | ||
| .build(); | ||
| HttpResponse<String> response = send(request); | ||
| if (response.statusCode() != 202) { | ||
| throw new IllegalStateException("Unable to delete test user: " + response.statusCode()); | ||
| } | ||
| } | ||
|
|
||
| private String sendForToken(String path, TestUser user) { | ||
| String body = gson.toJson(user); | ||
| HttpRequest request = HttpRequest.newBuilder() | ||
| .uri(URI.create(TestConfig.API_URL + path)) | ||
| .header("Content-Type", "application/json") | ||
| .POST(HttpRequest.BodyPublishers.ofString(body)) | ||
| .build(); | ||
| HttpResponse<String> response = send(request); | ||
| if (response.statusCode() != 200) { | ||
| throw new IllegalStateException("User API request failed: " + response.statusCode() + " " + response.body()); | ||
| } | ||
| JsonObject json = JsonParser.parseString(response.body()).getAsJsonObject(); | ||
| return json.get("accessToken").getAsString(); | ||
| } | ||
|
|
||
| private HttpResponse<String> send(HttpRequest request) { | ||
| try { | ||
| return client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
| } catch (IOException exception) { | ||
| throw new IllegalStateException("User API is unavailable", exception); | ||
| } catch (InterruptedException exception) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new IllegalStateException("User API request was interrupted", exception); | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
src/test/java/ru/praktikum/stellarburgers/ui/config/TestConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package ru.praktikum.stellarburgers.ui.config; | ||
|
|
||
| public final class TestConfig { | ||
|
|
||
| public static final String BASE_URL = System.getProperty( | ||
| "base.url", "https://stellarburgers.education-services.ru"); | ||
| public static final String API_URL = BASE_URL + "/api"; | ||
|
|
||
| private TestConfig() { | ||
| } | ||
| } |
95 changes: 95 additions & 0 deletions
95
src/test/java/ru/praktikum/stellarburgers/ui/config/WebDriverFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package ru.praktikum.stellarburgers.ui.config; | ||
|
|
||
| import org.openqa.selenium.WebDriver; | ||
| import org.openqa.selenium.chrome.ChromeDriver; | ||
| import org.openqa.selenium.chrome.ChromeOptions; | ||
|
|
||
| import java.io.File; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| public final class WebDriverFactory { | ||
|
|
||
| private WebDriverFactory() { | ||
| } | ||
|
|
||
| public static WebDriver create() { | ||
| String browser = System.getProperty("browser", "chrome").toLowerCase(); | ||
| ChromeOptions options = commonOptions(); | ||
|
|
||
| if ("yandex".equals(browser)) { | ||
| options.setBinary(resolveYandexBinary()); | ||
| String driverPath = System.getProperty("yandex.driver"); | ||
| if (driverPath != null && !driverPath.isBlank()) { | ||
| File driver = Paths.get(driverPath).toFile(); | ||
| if (!driver.isFile()) { | ||
| throw new IllegalStateException("Yandex ChromeDriver was not found: " + driverPath); | ||
| } | ||
| System.setProperty("webdriver.chrome.driver", driver.getAbsolutePath()); | ||
| } | ||
| } else if ("chrome".equals(browser)) { | ||
| options.setBinary(resolveChromeBinary()); | ||
| } else { | ||
| throw new IllegalArgumentException("Unsupported browser: " + browser + ". Use chrome or yandex."); | ||
| } | ||
|
|
||
| return new ChromeDriver(options); | ||
| } | ||
|
|
||
| private static ChromeOptions commonOptions() { | ||
| ChromeOptions options = new ChromeOptions(); | ||
| String profile = Paths.get(System.getProperty("user.dir"), "target", "browser-profiles", UUID.randomUUID().toString()).toString(); | ||
| options.addArguments( | ||
| "--window-size=1440,900", | ||
| "--disable-notifications", | ||
| "--disable-gpu", | ||
| "--no-sandbox", | ||
| "--disable-dev-shm-usage", | ||
| "--remote-allow-origins=*", | ||
| "--user-data-dir=" + profile); | ||
| if (Boolean.parseBoolean(System.getProperty("headless", "true"))) { | ||
| options.addArguments("--headless=new"); | ||
| } | ||
| return options; | ||
| } | ||
|
|
||
| private static String resolveChromeBinary() { | ||
| String configured = System.getProperty("chrome.binary"); | ||
| List<Path> candidates = Arrays.asList( | ||
| configured == null ? Paths.get("") : Paths.get(configured), | ||
| Paths.get("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"), | ||
| Paths.get("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe") | ||
| ); | ||
| return candidates.stream() | ||
| .filter(Files::isRegularFile) | ||
| .map(Path::toString) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalStateException( | ||
| "Google Chrome was not found. Set -Dchrome.binary=<path-to-chrome.exe>")); | ||
| } | ||
|
|
||
| private static String resolveYandexBinary() { | ||
| String configured = System.getProperty("yandex.binary"); | ||
| if (configured != null && Files.isRegularFile(Paths.get(configured))) { | ||
| return configured; | ||
| } | ||
|
|
||
| String localAppData = System.getenv("LOCALAPPDATA"); | ||
| List<Path> candidates = Arrays.asList( | ||
| localAppData == null ? Paths.get("") : Paths.get(localAppData, "Yandex", "YandexBrowser", "Application", "browser.exe"), | ||
| Paths.get("C:\\Program Files (x86)\\Yandex\\YandexBrowser\\Application\\browser.exe"), | ||
| Paths.get("C:\\Program Files\\Yandex\\YandexBrowser\\Application\\browser.exe") | ||
| ); | ||
|
|
||
| return candidates.stream() | ||
| .filter(Files::isRegularFile) | ||
| .map(Path::toString) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalStateException( | ||
| "Yandex Browser was not found. Set -Dyandex.binary=<path-to-browser.exe>")); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛔️Нужно исправить. Нет аллюр отчета
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавь папку allure-results