diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 223753f..26cb682 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,7 +6,8 @@
-
+
+
@@ -21,9 +22,22 @@
+
+
+
+
+
@@ -54,11 +68,14 @@
-
+
-
+
-
+
@@ -100,12 +117,12 @@
-
+
-
+
@@ -118,12 +135,12 @@
-
+
-
+
@@ -136,12 +153,12 @@
-
+
-
+
@@ -154,12 +171,12 @@
-
+
-
+
@@ -170,10 +187,11 @@
-
-
-
+
+
+
+
diff --git a/src/test/java/automatiom/tests/runner/BaseTest.java b/src/test/java/automatiom/tests/runner/BaseTest.java
index e5822e8..3aff3ee 100644
--- a/src/test/java/automatiom/tests/runner/BaseTest.java
+++ b/src/test/java/automatiom/tests/runner/BaseTest.java
@@ -1,135 +1,113 @@
package automatiom.tests.runner;
+import io.github.bonigarcia.wdm.WebDriverManager;
+import io.qameta.allure.Allure;
+import org.openqa.selenium.OutputType;
+import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.edge.EdgeDriver;
+import org.openqa.selenium.edge.EdgeOptions;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.ITestResult;
import org.testng.annotations.*;
+import java.io.ByteArrayInputStream;
import java.lang.reflect.Method;
import java.time.Duration;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Collectors;
public abstract class BaseTest {
- private WebDriver driver;
+ protected WebDriver driver;
+ private String browser;
- private WebDriverWait wait2;
- private WebDriverWait wait5;
- private WebDriverWait wait10;
-
-
- private void startDriver() {
- ProjectUtils.log("Browser open");
-
- driver = ProjectUtils.createDriver();
- }
-
- private void clearData() {
- ProjectUtils.log("Clear data");
-
- }
-
- private void loginWeb() {
- ProjectUtils.log("Login");
- }
-
- private void getWeb() {
- ProjectUtils.log("Get web page: https://demoqa.com/");
- ProjectUtils.get(driver);
- }
-
-
- private void acceptAlert() {
- ProjectUtils.acceptAlert(driver);
+ protected WebDriver getDriver() {
+ return driver;
}
- private void stopDriver() {
- try {
- driver.quit();
- } catch (Exception ignore) {
- }
+ List optionalBrowser = List.of("firefox", "chrome", "edge");
+ Random random = new Random();
+ String optionalItem = optionalBrowser.get(random.nextInt(optionalBrowser.size()));
- closeDriver();
- }
- private void closeDriver() {
- if (driver != null) {
- driver.quit();
-
- driver = null;
- wait2 = null;
- wait5 = null;
- wait10 = null;
+ @BeforeClass
+ @Parameters("browser")
+ protected void beforeClass() {
+ this.browser = "chrome";
+ Arrays.stream(this.getClass().getMethods())
+ .filter(m -> m.getAnnotation(Test.class) != null && m.getAnnotation(Ignore.class) == null)
+ .collect(Collectors.toList());
- ProjectUtils.log("Browser closed");
- }
}
-
@BeforeMethod
- protected void beforeMethod(Method method) {
- ProjectUtils.logf("Run %s.%s", this.getClass().getName(), method.getName());
- try {
- clearData();
- startDriver();
- getWeb();
- loginWeb();
-
- } catch (Exception e) {
- closeDriver();
- throw new RuntimeException(e);
+ public WebDriver setUp() {
+
+ switch (browser.toLowerCase()) {
+ case "chrome":
+ WebDriverManager.chromedriver().setup();
+ ChromeOptions chromeOptions = new ChromeOptions();
+ chromeOptions.addArguments("--headless"); // стабильно на Windows
+ chromeOptions.addArguments("--window-size=1920,1080");
+ chromeOptions.addArguments("--disable-gpu");
+ chromeOptions.addArguments("--remote-allow-origins=*");
+
+ if (!System.getProperty("os.name").toLowerCase().contains("win")) {
+ chromeOptions.addArguments("--no-sandbox", "--disable-dev-shm-usage");
+ chromeOptions.addArguments("--user-data-dir=/tmp/chrome-profile-" + System.currentTimeMillis());
+ } else {
+ chromeOptions.addArguments("--user-data-dir=" + System.getProperty("java.io.tmpdir") + "chrome-profile-" + System.currentTimeMillis());
+ }
+ driver = new ChromeDriver(chromeOptions);
+
+ break;
+ case "firefox":
+ WebDriverManager.firefoxdriver().setup();
+ FirefoxOptions firefoxOptions = new FirefoxOptions();
+ firefoxOptions.addArguments("--width=1920");
+ firefoxOptions.addArguments("--height=1080");
+ firefoxOptions.addArguments("--headless");
+ driver = new FirefoxDriver(firefoxOptions);
+ break;
+ case "edge":
+ WebDriverManager.edgedriver().setup();
+ EdgeOptions edgeOptions = new EdgeOptions();
+ edgeOptions.addArguments("--window-size=1920,1080");
+ edgeOptions.addArguments("--headless");
+ driver = new EdgeDriver(edgeOptions);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported browser: " + browser);
}
- }
- protected WebDriver getDriver () {
+ driver.get("https://demoqa.com/");
return driver;
}
- protected WebDriverWait getWait2 () {
- if (wait2 == null) {
- wait2 = new WebDriverWait(getDriver(), Duration.ofSeconds(2));
- }
-
- return wait2;
- }
-
- protected WebDriverWait getWait5 () {
- if (wait5 == null) {
- wait5 = new WebDriverWait(getDriver(), Duration.ofSeconds(5));
- }
-
- return wait5;
- }
-
- protected WebDriverWait getWait10 () {
- if (wait10 == null) {
- wait10 = new WebDriverWait(getDriver(), Duration.ofSeconds(10));
- }
-
- return wait10;
- }
@AfterMethod
- protected void afterMethod(Method method, ITestResult testResult) {
-
- if (ProjectUtils.isServerRun() && !testResult.isSuccess()) {
- ProjectUtils.takeScreenshot(driver, method.getName(), this.getClass().getName());
-
- }
- if (ProjectUtils.isServerRun() && testResult.isSuccess()) {
- closeDriver();
+ public void tearDown(ITestResult testResult) {
+ if (testResult.isSuccess()) {
+ driver.quit();
}
-
-
- if ( !(!ProjectUtils.isServerRun() && !testResult.isSuccess() && !ProjectUtils.closeBrowserIfError())) {
- stopDriver();
+ else if (!testResult.isSuccess()) {
+ Allure.addAttachment(
+ "screenshot.png",
+ "image/png",
+ new ByteArrayInputStream(((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.BYTES)),
+ "png");
+ } else {
+ System.out.println("Failed: " + testResult.getTestClass());
}
-
- ProjectUtils.logf("Execution time is %o sec\n\n", (testResult.getEndMillis() - testResult.getStartMillis()) / 1000);
}
-
-
-}
-
+}
\ No newline at end of file
diff --git a/src/test/java/automatiom/tests/runner/ProjectUtils.java b/src/test/java/automatiom/tests/runner/ProjectUtils.java
deleted file mode 100644
index 4efe86b..0000000
--- a/src/test/java/automatiom/tests/runner/ProjectUtils.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package automatiom.tests.runner;
-
-import io.github.bonigarcia.wdm.WebDriverManager;
-import org.apache.commons.io.FileUtils;
-import org.openqa.selenium.Alert;
-import org.openqa.selenium.OutputType;
-import org.openqa.selenium.TakesScreenshot;
-import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.chrome.ChromeDriver;
-import org.openqa.selenium.chrome.ChromeOptions;
-import org.openqa.selenium.support.ui.ExpectedConditions;
-
-import java.io.File;
-import java.io.IOException;
-import java.time.Duration;
-import java.util.Properties;
-
-public class ProjectUtils {
-
- private static final String PREFIX_PROP = "https://";
- private static final String PROP_HOST = PREFIX_PROP + "demoqa.com/";
- private static final String CLOSE_BROWSER_IF_ERROR = PREFIX_PROP + "closeBrowserIfError";
- private static Properties properties;
-
- static final ChromeOptions chromeOptions;
-
- static {
- chromeOptions = new ChromeOptions();
- String options = getUrl();
- if (options != null) {
- for (String argument : options.split(";")) {
- chromeOptions.addArguments(argument);
- }
- }
-
- WebDriverManager.chromedriver().setup();
- }
-
- static boolean isServerRun() {
- return System.getenv("CI_RUN") != null;
- }
-
- static boolean closeBrowserIfError() {
- return Boolean.getBoolean(properties.getProperty(CLOSE_BROWSER_IF_ERROR, "true"));
- }
-
- static String getUrl() {
- return String.format(PROP_HOST);
-
- }
-
- static void get(WebDriver driver) {
- driver.get(getUrl());
- }
-
- static void acceptAlert(WebDriver driver) {
- Alert alert = ExpectedConditions.alertIsPresent().apply(driver);
- if (alert != null) {
- alert.accept();
- }
- }
-
- static WebDriver createDriver() {
- WebDriver driver = new ChromeDriver(ProjectUtils.chromeOptions);
- driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
-
- return driver;
- }
-
- public static void log(String str) {
- System.out.println(str);
- }
-
- public static void logf(String str, Object... arr) {
- System.out.printf(str, arr);
- System.out.println();
- }
-
- static File takeScreenshot(WebDriver driver, String methodName, String className) {
- File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
- try {
- FileUtils.copyFile(file, new File(String.format("screenshots/%s.%s.png", className, methodName)));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return file;
- }
-
-
-}
diff --git a/src/test/java/automatiom/tests/tests/ElementsPageTest.java b/src/test/java/automatiom/tests/tests/elements/text_box/ElementsPageTest.java
similarity index 97%
rename from src/test/java/automatiom/tests/tests/ElementsPageTest.java
rename to src/test/java/automatiom/tests/tests/elements/text_box/ElementsPageTest.java
index 8dc57ed..e428621 100644
--- a/src/test/java/automatiom/tests/tests/ElementsPageTest.java
+++ b/src/test/java/automatiom/tests/tests/elements/text_box/ElementsPageTest.java
@@ -1,4 +1,4 @@
-package automatiom.tests.tests;
+package automatiom.tests.tests.elements.text_box;
import automatiom.tests.ElementsPage;
import automatiom.tests.ElementsTextBoxPage;