diff --git a/README.MD b/README.MD index 083075d..b15da45 100644 --- a/README.MD +++ b/README.MD @@ -105,7 +105,8 @@ The browser used in the test is placed on the `browser` property in the `general ##### Local Suite -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` +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 @@ -118,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 ``` @@ -153,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. @@ -211,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: @@ -237,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 @@ -295,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. @@ -333,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 518c9d4..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" 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 75a9b5e..be5b264 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.eliasnogueira selenium-java-lean-test-architecture - 3.4.6 + 3.4.7 scm:git@github.com:eliasnogueira/selenium-java-lean-test-architecture.git @@ -25,7 +25,7 @@ 4.25.0 7.10.2 3.26.3 - 2.4.0 + 2.4.1 2.23.1 1.0.12 2.29.0 @@ -34,7 +34,7 @@ https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline - 1.20.2 + 1.20.3 1.27.1 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/driver/BrowserFactory.java b/src/main/java/com/eliasnogueira/driver/BrowserFactory.java index 3bb5dd4..0b7f43f 100644 --- a/src/main/java/com/eliasnogueira/driver/BrowserFactory.java +++ b/src/main/java/com/eliasnogueira/driver/BrowserFactory.java @@ -39,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 { diff --git a/src/main/java/com/eliasnogueira/enums/RoomType.java b/src/main/java/com/eliasnogueira/enums/RoomType.java index 94844d1..e62f586 100644 --- a/src/main/java/com/eliasnogueira/enums/RoomType.java +++ b/src/main/java/com/eliasnogueira/enums/RoomType.java @@ -45,4 +45,4 @@ public static RoomType getRandom() { public String get() { return this.value; } -} \ No newline at end of file +} 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 +}