From 6202b964a02e4731f10499bc9682f1958ef51a95 Mon Sep 17 00:00:00 2001 From: Anh Tester Date: Mon, 24 Jun 2024 01:33:17 +0700 Subject: [PATCH] Update Selenium 4.22.0 --- CHANGELOG.txt | 7 +++++ README.md | 27 ++++++++++-------- config.toml | 28 +++++++++++++++++++ docker-compose-v3-dynamic-grid.yml | 25 +++++++++++++++++ pom.xml | 10 +++---- .../java/com/anhtester/keywords/WebUI.java | 10 +++---- .../anhtester/listeners/AllureListener.java | 4 +-- src/test/resources/config/config.properties | 2 +- 8 files changed, 88 insertions(+), 25 deletions(-) create mode 100644 config.toml create mode 100644 docker-compose-v3-dynamic-grid.yml diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 29e6a53..b768392 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,10 @@ +v2.4.1 +====== +Jun 24, 2024 +* Update Selenium 4.22.0 +* Update support CDP 126 (Chromium) +* Update CDP 126 in WebUI keyword + v2.4.0 ====== May 22, 2024 diff --git a/README.md b/README.md index 0f4eaa2..a004f13 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ ### ✳️ **SYSTEM REQUIREMENTS** -- Install JDK (recommend JDK >=11) +- Install JDK (recommend JDK >= 11) - Install Chrome Browser, Edge Browser, Firefox Browser - Run well on the **Windows** platform - Setup **Allure ENV**: @@ -74,7 +74,8 @@ **4. Allure Report** -- Open Terminal: **_allure serve target/allure-results_** +- Open Terminal: `allure serve target/allure-results` +- or command: `allure generate --single-file target/allure-results --clean` ![image](https://user-images.githubusercontent.com/87883620/161662507-9e4dc698-e452-4b43-a4f5-9808c81419a2.png) @@ -182,32 +183,32 @@ (tải bản Latest stable version) -**selenium-server-4.9.0.jar** (updated 21/04/2023) +**selenium-server-4.22.0.jar** (updated 24/06/2024) 2. Set PATH for driver in Environment variables: Follow with link: https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/#2-the-path-environment-variable -🔆 Đặt file **selenium-server-4.9.0.jar** vào thư mục nào đó và mở CMD tại thư mục đó lên +🔆 Đặt file **selenium-server-4.22.0.jar** vào thư mục nào đó và mở CMD tại thư mục đó lên ### Run default 1 node ✅ Mở 1 Hub với 1 Node mặc định (port 4444) -> java -jar selenium-server-4.9.0.jar standalone +> java -jar selenium-server-4.22.0.jar standalone ### Run multi Node ✅ Mở 1 Hub với 3 Node: (chạy 4 lệnh mở 4 CMD nhé) -> java -jar selenium-server-4.9.0.jar hub +> java -jar selenium-server-4.22.0.jar hub -> java -jar selenium-server-4.9.0.jar node --port 5556 +> java -jar selenium-server-4.22.0.jar node --port 5556 -> java -jar selenium-server-4.9.0.jar node --port 6667 +> java -jar selenium-server-4.22.0.jar node --port 6667 -> java -jar selenium-server-4.9.0.jar node --port 7778 +> java -jar selenium-server-4.22.0.jar node --port 7778 **📝 NOTE: Thực thi nhiều lệnh thì mở nhiều CMD** @@ -229,6 +230,8 @@ https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers **15. Use DataFaker and JavaFaker to generate data** Document DataFaker: https://www.datafaker.net/documentation/getting-started/ +or of Anh Tester blog: https://anhtester.com/blog/selenium-java/tao-du-lieu-gia-voi-datafaker + ### 🔆 Project structure @@ -584,10 +587,10 @@ Document DataFaker: https://www.datafaker.net/documentation/getting-started/ ┗ 📜README.md ``` -### I shall write document for my Framework. Coming soon... +### ⭐️ I will support your company if needed -## Copyright 2022 Anh Tester +## Copyright 2022-2024 Anh Tester > Anh Tester Blog: https://anhtester.com/ -![Alt text](https://anhtester.com/uploads/logo/anhtester_logo_512.png?raw=true "Anh Tester - Automation Testing") +![Alt text](https://anhtester.com/uploads/logo/anhtester_logo_512.png?raw=true "Anh Tester Automation Testing") diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..4f3d3a6 --- /dev/null +++ b/config.toml @@ -0,0 +1,28 @@ +[docker] +# Configs have a mapping between the Docker image to use and the capabilities that need to be matched to +# start a container with the given image. +configs = [ + "selenium/standalone-firefox:4.21.0-20240522", '{"browserName": "firefox"}', + "selenium/standalone-chrome:4.21.0-20240522", '{"browserName": "chrome"}', + "selenium/standalone-edge:4.21.0-20240522", '{"browserName": "MicrosoftEdge"}' +] + +host-config-keys = ["Dns", "DnsOptions", "DnsSearch", "ExtraHosts", "Binds"] + +# URL for connecting to the docker daemon +# 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://127.0.0.1:2375" +# Docker image used for video recording +video-image = "selenium/video:ffmpeg-6.1.1-20240522" + +# Uncomment the following section if you are running the node on a separate VM +# Fill out the placeholders with appropriate values +#[server] +#host = +#port = \ No newline at end of file diff --git a/docker-compose-v3-dynamic-grid.yml b/docker-compose-v3-dynamic-grid.yml new file mode 100644 index 0000000..761416e --- /dev/null +++ b/docker-compose-v3-dynamic-grid.yml @@ -0,0 +1,25 @@ +# To execute this docker compose yml file use `docker compose -f docker-compose-v3-dynamic-grid.yml up` +# Add the `-d` flag at the end for detached execution +# To stop the execution, hit Ctrl+C, and then `docker compose -f docker-compose-v3-dynamic-grid.yml down` +version: "3" +services: + node-docker: + image: selenium/node-docker:4.21.0-20240522 + volumes: + - ./assets:/opt/selenium/assets + - ./NodeDocker/config.toml:/opt/bin/config.toml + - /var/run/docker.sock:/var/run/docker.sock + depends_on: + - selenium-hub + environment: + - SE_EVENT_BUS_HOST=selenium-hub + - SE_EVENT_BUS_PUBLISH_PORT=4442 + - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 + + selenium-hub: + image: selenium/hub:4.21.0-20240522 + container_name: selenium-hub + ports: + - "4442:4442" + - "4443:4443" + - "4444:4444" diff --git a/pom.xml b/pom.xml index fd78d98..cbe2e3c 100644 --- a/pom.xml +++ b/pom.xml @@ -24,9 +24,9 @@ UTF-8 UTF-8 17 - 3.2.5 + 3.3.0 3.13.0 - 4.21.0 + 4.22.0 7.10.2 1.9.22.1 1.5.4 @@ -43,17 +43,17 @@ 5.2.5 2.16.1 1.0.12 - 3.25.3 + 3.26.0 2.2.2 0.7.7.0 8.0.33 3.5.3 1.18.32 - 33.2.0-jre + 33.2.1-jre 1.6.2 1.17 2.17.1 - 7.2.1 + 7.4.0 3.14.0 8.4.0 2.9.0 diff --git a/src/main/java/com/anhtester/keywords/WebUI.java b/src/main/java/com/anhtester/keywords/WebUI.java index 756f0c6..a38c3ae 100644 --- a/src/main/java/com/anhtester/keywords/WebUI.java +++ b/src/main/java/com/anhtester/keywords/WebUI.java @@ -30,8 +30,8 @@ import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.devtools.DevTools; import org.openqa.selenium.devtools.HasDevTools; -import org.openqa.selenium.devtools.v125.network.Network; -import org.openqa.selenium.devtools.v125.network.model.Headers; +import org.openqa.selenium.devtools.v126.network.Network; +import org.openqa.selenium.devtools.v126.network.model.Headers; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.print.PrintOptions; import org.openqa.selenium.support.ui.ExpectedCondition; @@ -2675,7 +2675,7 @@ public static void clearAndFillText(By by, String value) { */ @Step("Click on the element {0}") public static void clickElement(By by) { - waitForElementVisible(by).click(); + waitForElementClickable(by).click(); LogUtils.info("Clicked on the element " + by.toString()); if (ExtentTestManager.getExtentTest() != null) { @@ -2694,7 +2694,7 @@ public static void clickElement(By by) { */ @Step("Click on the element {0} with timeout {1}s") public static void clickElement(By by, int timeout) { - waitForElementVisible(by, timeout).click(); + waitForElementClickable(by, timeout).click(); LogUtils.info("Clicked on the element " + by.toString()); if (ExtentTestManager.getExtentTest() != null) { @@ -2758,7 +2758,7 @@ public static void clickLinkText(String linkText) { @Step("Right click on element {0}") public static void rightClickElement(By by) { Actions action = new Actions(DriverManager.getDriver()); - action.contextClick(waitForElementVisible(by)).build().perform(); + action.contextClick(waitForElementClickable(by)).build().perform(); LogUtils.info("Right click on element " + by); if (ExtentTestManager.getExtentTest() != null) { ExtentReportManager.pass("Right click on element " + by); diff --git a/src/test/java/com/anhtester/listeners/AllureListener.java b/src/test/java/com/anhtester/listeners/AllureListener.java index 317f0e4..605601f 100644 --- a/src/test/java/com/anhtester/listeners/AllureListener.java +++ b/src/test/java/com/anhtester/listeners/AllureListener.java @@ -41,12 +41,12 @@ public void afterTestStart(TestResult result) { @Override public void beforeTestStop(TestResult result) { - if (SCREENSHOT_PASSED_TCS.equals(YES)) { + if (SCREENSHOT_PASSED_TCS.equals(YES) && result.getStatus().equals(Status.PASSED)) { if (DriverManager.getDriver() != null) { Allure.addAttachment(result.getName() + "_Passed_Screenshot", new ByteArrayInputStream(((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES))); } } - if (SCREENSHOT_FAILED_TCS.equals(YES)) { + if (SCREENSHOT_FAILED_TCS.equals(YES) && result.getStatus().equals(Status.FAILED)) { if (DriverManager.getDriver() != null) { Allure.addAttachment(result.getName() + "_Failed_Screenshot", new ByteArrayInputStream(((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES))); } diff --git a/src/test/resources/config/config.properties b/src/test/resources/config/config.properties index f8f2883..df87998 100644 --- a/src/test/resources/config/config.properties +++ b/src/test/resources/config/config.properties @@ -21,7 +21,7 @@ URL_CRM = https://rise.anhtester.com/signin URL_CMS_ADMIN = https://cms.anhtester.com/login URL_CMS_USER = https://cms.anhtester.com # target execution: local or remote -TARGET = remote +TARGET = local # grid url and port REMOTE_URL = localhost REMOTE_PORT = 4444