From e05fcb42226a88aa9f0cd6f941e9ec165a95b9bc Mon Sep 17 00:00:00 2001 From: Navin Chandra Date: Wed, 27 Nov 2024 23:43:20 +0530 Subject: [PATCH 1/2] add docs for get_logs in java for chrome and edge --- .../dev/selenium/browsers/ChromeTest.java | 28 +++++++++++++++++-- .../java/dev/selenium/browsers/EdgeTest.java | 28 +++++++++++++++++-- .../webdriver/browsers/chrome.en.md | 2 +- .../webdriver/browsers/chrome.ja.md | 2 +- .../webdriver/browsers/chrome.pt-br.md | 2 +- .../webdriver/browsers/chrome.zh-cn.md | 2 +- .../webdriver/browsers/edge.en.md | 2 +- .../webdriver/browsers/edge.ja.md | 2 +- .../webdriver/browsers/edge.pt-br.md | 2 +- .../webdriver/browsers/edge.zh-cn.md | 2 +- 10 files changed, 58 insertions(+), 14 deletions(-) diff --git a/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java b/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java index 6470f25fa83..e3363390b4b 100644 --- a/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java +++ b/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java @@ -21,17 +21,17 @@ import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.chromium.ChromiumDriverLogLevel; import org.openqa.selenium.chromium.ChromiumNetworkConditions; -import org.openqa.selenium.logging.LogEntries; -import org.openqa.selenium.logging.LogType; -import org.openqa.selenium.logging.LoggingPreferences; +import org.openqa.selenium.logging.*; import org.openqa.selenium.remote.service.DriverFinder; + public class ChromeTest extends BaseTest { @AfterEach public void clearProperties() { System.clearProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY); System.clearProperty(ChromeDriverService.CHROME_DRIVER_LOG_LEVEL_PROPERTY); } + @Test public void basicOptions() { ChromeOptions options = new ChromeOptions(); @@ -236,4 +236,26 @@ public void castFeatures() { driver.quit(); } + + @Test + public void getBrowserLogs() { + ChromeDriver driver = new ChromeDriver(); + driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"); + WebElement consoleLogButton = driver.findElement(By.id("consoleError")); + consoleLogButton.click(); + + LogEntries logs = driver.manage().logs().get(LogType.BROWSER); + + // Assert that at least one log contains the expected message + boolean logFound = false; + for (LogEntry log : logs) { + if (log.getMessage().contains("I am console error")) { + logFound = true; + break; + } + } + + Assertions.assertTrue(logFound, "No matching log message found."); + driver.quit(); + } } diff --git a/examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java b/examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java index 4fefa2d08e2..3925d763d71 100644 --- a/examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java +++ b/examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java @@ -21,11 +21,11 @@ import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.edge.EdgeDriverService; import org.openqa.selenium.edge.EdgeOptions; -import org.openqa.selenium.logging.LogEntries; -import org.openqa.selenium.logging.LogType; -import org.openqa.selenium.logging.LoggingPreferences; +import org.openqa.selenium.logging.*; import org.openqa.selenium.remote.service.DriverFinder; + + public class EdgeTest extends BaseTest { @AfterEach public void clearProperties() { @@ -231,4 +231,26 @@ public void castFeatures() { driver.quit(); } + + @Test + public void getBrowserLogs() { + EdgeDriver driver = new EdgeDriver(); + driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html"); + WebElement consoleLogButton = driver.findElement(By.id("consoleError")); + consoleLogButton.click(); + + LogEntries logs = driver.manage().logs().get(LogType.BROWSER); + + // Assert that at least one log contains the expected message + boolean logFound = false; + for (LogEntry log : logs) { + if (log.getMessage().contains("I am console error")) { + logFound = true; + break; + } + } + + Assertions.assertTrue(logFound, "No matching log message found."); + driver.quit(); + } } diff --git a/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md b/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md index 0284e0463db..224c8bcbd3b 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md @@ -419,7 +419,7 @@ You can simulate various network conditions. {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L247" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L186" >}} diff --git a/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md b/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md index 1717d82bde2..2949c39cf82 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md @@ -413,7 +413,7 @@ Chrome Castデバイスを操作することができ、タブの共有も含ま {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L247" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L186" >}} diff --git a/website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md b/website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md index d4098435d9a..ad5a7234b3d 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md @@ -422,7 +422,7 @@ please refer to the {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L247" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L186" >}} diff --git a/website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md b/website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md index 773c74516f5..44882a2a3f5 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md @@ -422,7 +422,7 @@ Chromedriver 和 Chrome 浏览器版本应该匹配, 如果它们不匹配, 驱 {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L247" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L186" >}} diff --git a/website_and_docs/content/documentation/webdriver/browsers/edge.en.md b/website_and_docs/content/documentation/webdriver/browsers/edge.en.md index 5fc35d60924..28c732910e4 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.en.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.en.md @@ -420,7 +420,7 @@ You can simulate various network conditions. {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java#L242" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_edge.py#L186" >}} diff --git a/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md b/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md index 7b5f73f5614..afa97393464 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md @@ -406,7 +406,7 @@ Edge を使用して Chrome Cast デバイスを操作し、タブを共有す {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java#L242" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_edge.py#L186" >}} diff --git a/website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md b/website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md index a7fbd686ea7..b4393d23d60 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md @@ -422,7 +422,7 @@ You can simulate various network conditions. {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java#L242" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_edge.py#L186" >}} diff --git a/website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md b/website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md index 8338c667406..ff61bdb78dc 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md @@ -422,7 +422,7 @@ You can simulate various network conditions. {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java#L242" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_edge.py#L186" >}} From 26a114ee2aaa1a25a6cb1dfe3c5aef4af7ddd79b Mon Sep 17 00:00:00 2001 From: Navin Chandra Date: Wed, 27 Nov 2024 23:51:57 +0530 Subject: [PATCH 2/2] update python docs to use new site for `get_log` --- examples/python/tests/browsers/test_chrome.py | 8 ++++---- examples/python/tests/browsers/test_edge.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/python/tests/browsers/test_chrome.py b/examples/python/tests/browsers/test_chrome.py index d34fe294654..3f72785d407 100644 --- a/examples/python/tests/browsers/test_chrome.py +++ b/examples/python/tests/browsers/test_chrome.py @@ -3,7 +3,7 @@ import subprocess import pytest from selenium import webdriver - +from selenium.webdriver.common.by import By def test_basic_options(): options = webdriver.ChromeOptions() @@ -180,11 +180,11 @@ def test_cast_features(): def test_get_browser_logs(): driver = webdriver.Chrome() - - driver.get("https://www.selenium.dev/") + driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html") + driver.find_element(By.ID, "consoleError").click() logs = driver.get_log("browser") # Assert that at least one log contains the expected message - assert any("Uncaught TypeError" in log['message'] for log in logs), "No matching log message found." + assert any("I am console error" in log['message'] for log in logs), "No matching log message found." driver.quit() diff --git a/examples/python/tests/browsers/test_edge.py b/examples/python/tests/browsers/test_edge.py index b13fd9d7cb5..7a368fb5a04 100644 --- a/examples/python/tests/browsers/test_edge.py +++ b/examples/python/tests/browsers/test_edge.py @@ -3,7 +3,7 @@ import subprocess import pytest from selenium import webdriver - +from selenium.webdriver.common.by import By def test_basic_options(): options = webdriver.EdgeOptions() @@ -180,11 +180,11 @@ def test_cast_features(): def test_get_browser_logs(): driver = webdriver.Edge() - - driver.get("https://www.selenium.dev/") + driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html") + driver.find_element(By.ID, "consoleError").click() logs = driver.get_log("browser") # Assert that at least one log contains the expected message - assert any("Uncaught TypeError" in log['message'] for log in logs), "No matching log message found." + assert any("I am console error" in log['message'] for log in logs), "No matching log message found." driver.quit()