Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java]: add docs for retrieving logs in chrome and edge #2083

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading