diff --git a/.github/workflows/on-pr.yml b/.github/workflows/on-pr.yml new file mode 100644 index 0000000..69175b4 --- /dev/null +++ b/.github/workflows/on-pr.yml @@ -0,0 +1,28 @@ +name: On Pull Request + +on: + pull_request: + branches: + - main + +jobs: + build: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 24 + uses: actions/setup-java@v4 + with: + distribution: oracle + java-version: 24 + + - name: Cache Maven packages + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build + run: mvn -q compile diff --git a/.github/workflows/test-execution.yml b/.github/workflows/test-execution.yml index fbe9763..338cdd1 100644 --- a/.github/workflows/test-execution.yml +++ b/.github/workflows/test-execution.yml @@ -12,14 +12,14 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up JDK + - name: Set up JDK 24 uses: actions/setup-java@v4 with: - java-version: 21 - distribution: temurin + java-version: 24 + distribution: oracle - name: Cache Maven packages - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -27,7 +27,7 @@ jobs: ${{ runner.os }}-maven- - name: Build with Maven - run: mvn -B -q -DskipTests package --file pom.xml + run: mvn -q -DskipTests package - name: Run local tests - run: mvn -B -q test -Pweb-execution -Dsuite=local -Dtarget=local -Dheadless=true -Dbrowser=chrome + run: mvn -q test -Pweb-execution -Dsuite=local -Dtarget=local -Dheadless=true -Dbrowser=chrome diff --git a/README.MD b/README.MD index e26a83c..d90fecc 100644 --- a/README.MD +++ b/README.MD @@ -10,16 +10,7 @@ It has a complete solution to run tests in different ways: * local testing using the browser on your local machine * parallel (or single) testing using Selenium Docker * local testing using TestContainers -* Distributed execution using Selenium Grid - -## Important information - -### Know issues - -```shell -This current version has excluded the guava library from WebDriverManager and Allure Environment Writer -due to a conflict with the guava version of Selenium 4 -``` +* Distributed execution using Selenium Grid ## Examples @@ -35,16 +26,15 @@ due to a conflict with the guava version of Selenium 4 This project uses the following languages and frameworks: -* [Java 21](https://openjdk.java.net/projects/jdk/21/) as the programming language +* [Java 23](https://openjdk.java.net/projects/jdk/23/) as the programming language * [TestNG](https://testng.org/doc/) as the UnitTest framework to support the test creation * [Selenium WebDriver](https://www.selenium.dev/) as the web browser automation framework using the Java binding * [AssertJ](https://joel-costigliola.github.io/assertj/) as the fluent assertion library * [Allure Report](https://docs.qameta.io/allure/) as the testing report strategy * [DataFaker](https://www.datafaker.net/) as the faker data generation strategy * [Log4J2](https://logging.apache.org/log4j/2.x/) as the logging management strategy -* [WebDriverManager](https://github.com/bonigarcia/webdrivermanager) as the Selenium binaries management * [Owner](http://owner.aeonbits.org/) to minimize the code to handle the properties file -* [TestContainers] (https://java.testcontainers.org/modules/webdriver_containers/) Webdriver Containers +* [TestContainers](https://java.testcontainers.org/modules/webdriver_containers/) Webdriver Containers ## Test architecture @@ -108,8 +98,6 @@ on `general.properties` file. Its usage is placed on the `BaseWeb` class before **This approach is automatically used when you run the test class in your IDE.** -This execution type uses [WebDriverManager](https://github.com/bonigarcia/webdrivermanager) class to instantiate the web -browsers. When the `target` is `local` the `createLocalDriver()` method is used from the `BrowserFactory` class to return the browser instance. @@ -117,8 +105,8 @@ The browser used in the test is placed on the `browser` property in the `general ##### Local Suite -This execution type also uses the [WebDriverManager](https://github.com/bonigarcia/webdrivermanager) to instantiate the -web browser. The difference is that the browser is taken from the TestNG suite file instead of the `general.properties` +It's the same as the Local Execution, where the difference is that the browser is taken from the TestNG suite file +instead of the `general.properties` file, enabling you to run multi-browser test approach locally. ##### Testcontainers @@ -131,6 +119,7 @@ the container based on the browser set in the `browser` property. Currently, Tes Firefox. Example + ```shell mvn test -Pweb-execution -Dtarget=testcontainers -Dbrowser=chrome ``` @@ -166,7 +155,8 @@ Each browser is an `enum`, and each enum implements four methods: * `createDriver()`: creates the browser instance for the remote execution * `getOptions()`: creates a new browser `Options` setting some specific configurations, and it's used for the remote executions using the Selenium Grid -* `createTestContainerDriver()` : Creates selenium grid lightweight test container in Standalone mode with Chrome/Firefox/Edge browser support. +* `createTestContainerDriver()` : Creates selenium grid lightweight test container in Standalone mode with + Chrome/Firefox/Edge browser support. You can see that the `createLocalDriver()` method use the `getOptions()` to get specific browser configurations, as starting the browser maximized and others. @@ -224,7 +214,8 @@ factory [BookingDataFactory](https://github.com/eliasnogueira/selenium-java-lean The parallel test execution is based on the [parallel tests](https://testng.org/doc/documentation-main.html#parallel-tests) -feature on TestNG. This is used by `selenium-grid.xml` test suite file which has the `parallel="tests"` attribute and value, +feature on TestNG. This is used by `selenium-grid.xml` test suite file which has the `parallel="tests"` attribute and +value, whereas `test` item inside the test suite will execute in parallel. The browser in use for each `test` should be defined by a parameter, like: @@ -250,18 +241,21 @@ Please note that you need to do the following actions before running it in paral * Docker installed * Pull the images for Chrome Edge and Firefox - Optional - * Images are pulled if not available and initial test execution will be slow - * `docker pull selenium-standalog-chrome` - * `docker pull selenium-standalog-firefox` - * `docker pull selenium/standalone-edge` - * If you are using a MacBook with either M1 or M2 chip you must check the following experimental feature in Docker Desktop: Settings -> Features in development -> Use Rosetta for x86/amd64 emulation on Apple Silicon + * Images are pulled if not available and initial test execution will be slow + * `docker pull selenium-standalog-chrome` + * `docker pull selenium-standalog-firefox` + * `docker pull selenium/standalone-edge` + * If you are using a MacBook with either M1 or M2 chip you must check the following experimental feature in Docker + Desktop: Settings -> Features in development -> Use Rosetta for x86/amd64 emulation on Apple Silicon * Pay attention to the `grid/config.toml` file that has comments for each specific SO * Start the Grid by running the following command inside the `grid` folder * `docker-compose up` * Run the project using the following command + ```shell mvn test -Pweb-execution -Dsuite=selenium-grid -Dtarget=selenium-grid -Dheadless=true ``` + * Open the [Selenium Grid] page to see the node status ### Configuration files @@ -308,7 +302,7 @@ To execute this suite, via the command line you can call the parameter `-P` and Eg: executing the multi_browser suite ``` bash -mvn test -Pweb-execution -Dtestng.dtd.http=true +mvn test -Pweb-execution ``` If you have more than one suite on _src/test/resources/suites_ folder you can parameterize the xml file name. @@ -346,7 +340,7 @@ To do this you need: * Use `-Dsuite=suite_name` to call the suite ````bash -mvn test -Pweb-execution -Dsuite=parallel +mvn test -Pweb-execution -Dsuite=suite_name ```` ### Pipeline as a code diff --git a/grid/config.toml b/grid/config.toml index b304a88..2d961ae 100644 --- a/grid/config.toml +++ b/grid/config.toml @@ -6,11 +6,17 @@ configs = [ "selenium/standalone-chrome:latest", "{\"browserName\": \"chrome\"}" ] +host-config-keys = ["Binds"] + # URL for connecting to the docker daemon -# host.docker.internal works for macOS and Windows. -# Linux could use --net=host in the `docker run` instruction or 172.17.0.1 in the URI below. -# To have Docker listening through tcp on macOS, install socat and run the following command -# socat -4 TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock +# Most simple approach, leave it as http://127.0.0.1:2375, and mount /var/run/docker.sock. +# 127.0.0.1 is used because internally the container uses socat when /var/run/docker.sock is mounted +# If var/run/docker.sock is not mounted: +# Windows: make sure Docker Desktop exposes the daemon via tcp, and use http://host.docker.internal:2375. +# macOS: install socat and run the following command, socat -4 TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock, +# then use http://host.docker.internal:2375. +# Linux: varies from machine to machine, please mount /var/run/docker.sock. If this does not work, please create an issue. + url = "http://host.docker.internal:2375/" # Docker image used for video recording video-image = "selenium/video:latest" @@ -19,4 +25,4 @@ video-image = "selenium/video:latest" # Fill out the placeholders with appropriate values #[server] #host = -#port = \ No newline at end of file +#port = diff --git a/grid/docker-compose.yml b/grid/docker-compose.yml index 498c08a..7163cac 100644 --- a/grid/docker-compose.yml +++ b/grid/docker-compose.yml @@ -1,10 +1,11 @@ -version: "3" services: node-docker: image: selenium/node-docker:latest volumes: - ./assets:/opt/selenium/assets - ./config.toml:/opt/bin/config.toml + - ~/Downloads:/home/seluser/Downloads + - /var/run/docker.sock:/var/run/docker.sock depends_on: - selenium-hub environment: @@ -18,4 +19,4 @@ services: ports: - "4442:4442" - "4443:4443" - - "4444:4444" \ No newline at end of file + - "4444:4444" diff --git a/pom.xml b/pom.xml index 1d7fe65..d3faf76 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.eliasnogueira selenium-java-lean-test-architecture - 3.3.8 + 3.8.0 scm:git@github.com:eliasnogueira/selenium-java-lean-test-architecture.git @@ -15,30 +15,29 @@ - 21 + 24 UTF-8 UTF-8 - 3.2.5 - 3.12.1 - - 1.9.21 - 4.13.0 - 7.9.0 - 3.25.2 - 2.1.0 - 2.22.1 - 5.6.3 + 3.5.3 + 3.14.0 + + 1.9.24 + 4.35.0 + 7.11.0 + 3.27.4 + 2.4.4 + 2.25.1 1.0.12 - 2.25.0 - 2.12.0 + 2.33.0 + 2.29.1 + 2.29.1 + 2.15.2 1.0.0 https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline - 1.19.3 - - - 2.16.1 + 1.21.3 + 2.0.17 local @@ -50,22 +49,10 @@ ${selenium.version} - - org.seleniumhq.selenium - selenium-http-jdk-client - ${selenium.version} - - org.testng testng ${testng.version} - - - org.webjars - jquery - - @@ -104,28 +91,16 @@ ${owner.version} - - io.github.bonigarcia - webdrivermanager - ${webdrivermanager.version} - - - com.fasterxml.jackson.core - jackson-databind - - - - io.qameta.allure allure-testng - ${allure.version} + ${allure-testng.version} io.qameta.allure allure-attachments - ${allure.version} + ${allure-attachments.version} @@ -144,18 +119,24 @@ org.testcontainers selenium ${testcontainers.selenium.version} + + + org.apache.commons + commons-compress + + - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind.version} + org.slf4j + slf4j-simple + ${slf4j-simple.version} + test - + web-execution diff --git a/src/main/java/com/eliasnogueira/config/Configuration.java b/src/main/java/com/eliasnogueira/config/Configuration.java index 4322f53..dda4233 100644 --- a/src/main/java/com/eliasnogueira/config/Configuration.java +++ b/src/main/java/com/eliasnogueira/config/Configuration.java @@ -32,7 +32,6 @@ @Config.Sources({ "system:properties", "classpath:general.properties", - "classpath:local.properties", "classpath:selenium-grid.properties"}) public interface Configuration extends Config { diff --git a/src/main/java/com/eliasnogueira/config/ConfigurationManager.java b/src/main/java/com/eliasnogueira/config/ConfigurationManager.java index ba842b4..ce15843 100644 --- a/src/main/java/com/eliasnogueira/config/ConfigurationManager.java +++ b/src/main/java/com/eliasnogueira/config/ConfigurationManager.java @@ -35,4 +35,3 @@ public static Configuration configuration() { return ConfigCache.getOrCreate(Configuration.class); } } - diff --git a/src/main/java/com/eliasnogueira/data/dynamic/BookingDataFactory.java b/src/main/java/com/eliasnogueira/data/dynamic/BookingDataFactory.java index 644b3c3..c1dc321 100644 --- a/src/main/java/com/eliasnogueira/data/dynamic/BookingDataFactory.java +++ b/src/main/java/com/eliasnogueira/data/dynamic/BookingDataFactory.java @@ -49,7 +49,7 @@ public static Booking createBookingData() { password(faker.internet().password()). dailyBudget(returnDailyBudget()). newsletter(faker.bool().bool()). - roomType(RoomType.getRandom()). + roomType(faker.options().option(RoomType.class)). roomDescription(faker.lorem().paragraph()). build(); diff --git a/src/main/java/com/eliasnogueira/driver/BrowserFactory.java b/src/main/java/com/eliasnogueira/driver/BrowserFactory.java index 35816b3..0b7f43f 100644 --- a/src/main/java/com/eliasnogueira/driver/BrowserFactory.java +++ b/src/main/java/com/eliasnogueira/driver/BrowserFactory.java @@ -25,7 +25,6 @@ package com.eliasnogueira.driver; import com.eliasnogueira.exceptions.HeadlessNotSupportedException; -import io.github.bonigarcia.wdm.WebDriverManager; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; @@ -40,7 +39,12 @@ import org.testcontainers.containers.BrowserWebDriverContainer; import static com.eliasnogueira.config.ConfigurationManager.configuration; -import static com.eliasnogueira.data.changeless.BrowserData.*; +import static com.eliasnogueira.data.changeless.BrowserData.CHROME_HEADLESS; +import static com.eliasnogueira.data.changeless.BrowserData.DISABLE_INFOBARS; +import static com.eliasnogueira.data.changeless.BrowserData.DISABLE_NOTIFICATIONS; +import static com.eliasnogueira.data.changeless.BrowserData.GENERIC_HEADLESS; +import static com.eliasnogueira.data.changeless.BrowserData.REMOTE_ALLOW_ORIGINS; +import static com.eliasnogueira.data.changeless.BrowserData.START_MAXIMIZED; import static java.lang.Boolean.TRUE; public enum BrowserFactory { @@ -119,8 +123,6 @@ public EdgeOptions getOptions() { }, SAFARI { @Override public WebDriver createLocalDriver() { - WebDriverManager.safaridriver().setup(); - return new SafariDriver(getOptions()); } diff --git a/src/main/java/com/eliasnogueira/driver/TargetFactory.java b/src/main/java/com/eliasnogueira/driver/TargetFactory.java index 434c1a2..3919b61 100644 --- a/src/main/java/com/eliasnogueira/driver/TargetFactory.java +++ b/src/main/java/com/eliasnogueira/driver/TargetFactory.java @@ -60,9 +60,9 @@ private RemoteWebDriver createRemoteInstance(MutableCapabilities capability) { remoteWebDriver = new RemoteWebDriver(URI.create(gridURL).toURL(), capability); } catch (java.net.MalformedURLException e) { logger.error("Grid URL is invalid or Grid is not available"); - logger.error(format("Browser: %s", capability.getBrowserName()), e); + logger.error("Browser: {}", capability.getBrowserName(), e); } catch (IllegalArgumentException e) { - logger.error(format("Browser %s is not valid or recognized", capability.getBrowserName()), e); + logger.error("Browser {} is not valid or recognized", capability.getBrowserName(), e); } return remoteWebDriver; diff --git a/src/main/java/com/eliasnogueira/enums/RoomType.java b/src/main/java/com/eliasnogueira/enums/RoomType.java index 94844d1..d7b0980 100644 --- a/src/main/java/com/eliasnogueira/enums/RoomType.java +++ b/src/main/java/com/eliasnogueira/enums/RoomType.java @@ -24,7 +24,6 @@ package com.eliasnogueira.enums; -import java.security.SecureRandom; import java.util.function.Supplier; public enum RoomType implements Supplier { @@ -37,12 +36,8 @@ public enum RoomType implements Supplier { this.value = value; } - public static RoomType getRandom() { - return values()[new SecureRandom().nextInt(values().length)]; - } - @Override public String get() { return this.value; } -} \ No newline at end of file +} diff --git a/src/main/java/com/eliasnogueira/enums/Target.java b/src/main/java/com/eliasnogueira/enums/Target.java index 0b7618d..d9dfa4e 100644 --- a/src/main/java/com/eliasnogueira/enums/Target.java +++ b/src/main/java/com/eliasnogueira/enums/Target.java @@ -33,7 +33,8 @@ public enum Target { - LOCAL("local"), LOCAL_SUITE("local-suite"), SELENIUM_GRID("selenium-grid"), TESTCONTAINERS("testcontainers"); + LOCAL("local"), LOCAL_SUITE("local-suite"), SELENIUM_GRID("selenium-grid"), + TESTCONTAINERS("testcontainers"); private final String value; private static final Map ENUM_MAP; @@ -43,12 +44,15 @@ public enum Target { } static { - Map map = stream(Target.values()).collect(toMap( - instance -> instance.value.toLowerCase(), instance -> instance, (a, b) -> b, ConcurrentHashMap::new)); + Map map = stream(Target.values()) + .collect(toMap(instance -> instance.value.toLowerCase(), instance -> instance, (_, b) -> b, ConcurrentHashMap::new)); ENUM_MAP = Collections.unmodifiableMap(map); } public static Target get(String value) { + if (!ENUM_MAP.containsKey(value.toLowerCase())) + throw new IllegalArgumentException(String.format("Value %s not valid. Use one of the TARGET enum values", value)); + return ENUM_MAP.get(value.toLowerCase()); } } diff --git a/src/main/java/com/eliasnogueira/model/Booking.java b/src/main/java/com/eliasnogueira/model/Booking.java index 01bd9b4..5348d03 100644 --- a/src/main/java/com/eliasnogueira/model/Booking.java +++ b/src/main/java/com/eliasnogueira/model/Booking.java @@ -78,4 +78,4 @@ public Booking build() { return new Booking(email, country, password, dailyBudget, newsletter, roomType, roomDescription); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/eliasnogueira/page/booking/common/NavigationPage.java b/src/main/java/com/eliasnogueira/page/booking/common/NavigationPage.java index 46be648..ceafb1d 100644 --- a/src/main/java/com/eliasnogueira/page/booking/common/NavigationPage.java +++ b/src/main/java/com/eliasnogueira/page/booking/common/NavigationPage.java @@ -45,11 +45,6 @@ public void next() { next.click(); } - @Step - public void previous() { - previous.click(); - } - @Step public void finish() { finish.click(); diff --git a/src/main/java/com/eliasnogueira/report/AllureManager.java b/src/main/java/com/eliasnogueira/report/AllureManager.java index 4fabc20..2180e2e 100644 --- a/src/main/java/com/eliasnogueira/report/AllureManager.java +++ b/src/main/java/com/eliasnogueira/report/AllureManager.java @@ -24,18 +24,14 @@ package com.eliasnogueira.report; -import com.eliasnogueira.driver.DriverManager; import com.eliasnogueira.enums.Target; import com.github.automatedowl.tools.AllureEnvironmentWriter; import com.google.common.collect.ImmutableMap; -import io.qameta.allure.Attachment; -import org.openqa.selenium.TakesScreenshot; import java.util.HashMap; import java.util.Map; import static com.eliasnogueira.config.ConfigurationManager.configuration; -import static org.openqa.selenium.OutputType.BYTES; public class AllureManager { @@ -59,14 +55,4 @@ public static void setAllureEnvironmentInformation() { AllureEnvironmentWriter.allureEnvironmentWriter(ImmutableMap.copyOf(basicInfo)); } - - @Attachment(value = "Failed test screenshot", type = "image/png") - public static byte[] takeScreenshotToAttachOnAllureReport() { - return ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(BYTES); - } - - @Attachment(value = "Browser information", type = "text/plain") - public static String addBrowserInformationOnAllureReport() { - return DriverManager.getInfo(); - } } diff --git a/src/main/java/com/eliasnogueira/report/AllureTestLifecycleListener.java b/src/main/java/com/eliasnogueira/report/AllureTestLifecycleListener.java new file mode 100644 index 0000000..4d09ef2 --- /dev/null +++ b/src/main/java/com/eliasnogueira/report/AllureTestLifecycleListener.java @@ -0,0 +1,56 @@ +/* + * MIT License + * + * Copyright (c) 2024 Elias Nogueira + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.eliasnogueira.report; + +import com.eliasnogueira.driver.DriverManager; +import io.qameta.allure.Attachment; +import io.qameta.allure.listener.TestLifecycleListener; +import io.qameta.allure.model.TestResult; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.WebDriver; + +import static io.qameta.allure.model.Status.BROKEN; +import static io.qameta.allure.model.Status.FAILED; + +/* + * Approach implemented using the https://github.com/biczomate/allure-testng7.5-attachment-example as reference + */ +public class AllureTestLifecycleListener implements TestLifecycleListener { + + public AllureTestLifecycleListener() { + } + + @Attachment(value = "Page Screenshot", type = "image/png") + public byte[] saveScreenshot(WebDriver driver) { + return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); + } + + @Override + public void beforeTestStop(TestResult result) { + if (FAILED == result.getStatus() || BROKEN == result.getStatus()) { + saveScreenshot(DriverManager.getDriver()); + } + } +} diff --git a/src/test/java/com/eliasnogueira/BaseWeb.java b/src/test/java/com/eliasnogueira/BaseWeb.java index b7965de..cd5c894 100644 --- a/src/test/java/com/eliasnogueira/BaseWeb.java +++ b/src/test/java/com/eliasnogueira/BaseWeb.java @@ -31,18 +31,15 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; -import org.testng.annotations.Listeners; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import static com.eliasnogueira.config.ConfigurationManager.configuration; -@Listeners({TestListener.class}) public abstract class BaseWeb { @BeforeSuite public void beforeSuite() { - System.setProperty("webdriver.http.factory", "jdk-http-client"); AllureManager.setAllureEnvironmentInformation(); } diff --git a/src/test/java/com/eliasnogueira/TestListener.java b/src/test/java/com/eliasnogueira/TestListener.java deleted file mode 100644 index a0fa483..0000000 --- a/src/test/java/com/eliasnogueira/TestListener.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2018 Elias Nogueira - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.eliasnogueira; - -import com.eliasnogueira.report.AllureManager; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.testng.ITestContext; -import org.testng.ITestListener; -import org.testng.ITestResult; - -public class TestListener implements ITestListener { - - private static final Logger logger = LogManager.getLogger(TestListener.class); - - @Override - public void onTestStart(ITestResult result) { - // empty - } - - @Override - public void onTestSuccess(ITestResult result) { - // empty - } - - @Override - public void onTestFailure(ITestResult result) { - failTest(result); - } - - @Override - public void onTestSkipped(ITestResult result) { - logger.error(result.getThrowable()); - } - - @Override - public void onTestFailedButWithinSuccessPercentage(ITestResult result) { - // empty - } - - @Override - public void onStart(ITestContext context) { - // empty - } - - @Override - public void onFinish(ITestContext context) { - // empty - } - - private void failTest(ITestResult iTestResult) { - logger.error(iTestResult.getTestClass().getName()); - logger.error(iTestResult.getThrowable()); - - AllureManager.takeScreenshotToAttachOnAllureReport(); - } -} diff --git a/src/test/resources/META-INF/services/io.qameta.allure.listener.TestLifecycleListener b/src/test/resources/META-INF/services/io.qameta.allure.listener.TestLifecycleListener new file mode 100644 index 0000000..dda40f5 --- /dev/null +++ b/src/test/resources/META-INF/services/io.qameta.allure.listener.TestLifecycleListener @@ -0,0 +1 @@ +com.eliasnogueira.report.AllureTestLifecycleListener diff --git a/src/test/resources/general.properties b/src/test/resources/general.properties index 69cf156..15bb713 100644 --- a/src/test/resources/general.properties +++ b/src/test/resources/general.properties @@ -5,7 +5,7 @@ target = local browser = chrome # initial URL -url.base = http://eliasnogueira.com/external/selenium-java-architecture/ +url.base = https://eliasnogueira.com/external/selenium-java-architecture/ # global test timeout timeout = 3