Skip to content

Commit

Permalink
[java]: add docs for retrieving logs in chrome and edge (#2083)[deplo…
Browse files Browse the repository at this point in the history
…y site]

* add docs for get_logs in java for chrome and edge

* update python docs to use new site for `get_log`

---------

Co-authored-by: Sri Harsha <[email protected]>
  • Loading branch information
navin772 and harsha509 authored Nov 29, 2024
1 parent efbd943 commit 33a0c76
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 22 deletions.
28 changes: 25 additions & 3 deletions examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}
28 changes: 25 additions & 3 deletions examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}
}
8 changes: 4 additions & 4 deletions examples/python/tests/browsers/test_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
8 changes: 4 additions & 4 deletions examples/python/tests/browsers/test_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" >}}
Expand Down

0 comments on commit 33a0c76

Please sign in to comment.