From 0ec7656387a792fb1137020c60ed33109cc5a9e6 Mon Sep 17 00:00:00 2001 From: Navin Chandra <98466550+navin772@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:49:03 +0530 Subject: [PATCH] [java]: add java docs for setPermission for chrome and edge browsers (#2063) * add java docs for setPermission in chrome and edge * remove text blocks to support Java 11 --- .../java/dev/selenium/browsers/ChromeTest.java | 16 ++++++++++++++++ .../java/dev/selenium/browsers/EdgeTest.java | 16 ++++++++++++++++ .../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 +- .../documentation/webdriver/browsers/edge.en.md | 2 +- .../documentation/webdriver/browsers/edge.ja.md | 2 +- .../webdriver/browsers/edge.pt-br.md | 2 +- .../webdriver/browsers/edge.zh-cn.md | 2 +- 10 files changed, 40 insertions(+), 8 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 a7a6e55ef7b7..430ae5d16394 100644 --- a/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java +++ b/examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java @@ -180,4 +180,20 @@ private File getChromeLocation() { DriverFinder finder = new DriverFinder(ChromeDriverService.createDefaultService(), options); return new File(finder.getBrowserPath()); } + + @Test + public void setPermission() { + ChromeDriver driver = new ChromeDriver(); + driver.get("https://www.selenium.dev"); + + driver.setPermission("camera", "denied"); + + // Verify the permission state is 'denied' + String script = "return navigator.permissions.query({ name: 'camera' })" + + " .then(permissionStatus => permissionStatus.state);"; + String permissionState = (String) driver.executeScript(script); + + Assertions.assertEquals("denied", permissionState); + 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 0711b26292cb..164d73b0aa0b 100644 --- a/examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java +++ b/examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java @@ -174,4 +174,20 @@ private File getEdgeLocation() { DriverFinder finder = new DriverFinder(EdgeDriverService.createDefaultService(), options); return new File(finder.getBrowserPath()); } + + @Test + public void setPermissions() { + EdgeDriver driver = new EdgeDriver(); + driver.get("https://www.selenium.dev"); + + driver.setPermission("camera", "denied"); + + // Verify the permission state is 'denied' + String script = "return navigator.permissions.query({ name: 'camera' })" + + " .then(permissionStatus => permissionStatus.state);"; + String permissionState = (String) driver.executeScript(script); + + Assertions.assertEquals("denied", permissionState); + 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 64ca84f8bb84..511793595a0d 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.en.md @@ -442,7 +442,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#L189" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L149" >}} 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 4bb00f9601d2..d467f29bd714 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md +++ b/website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md @@ -436,7 +436,7 @@ Chrome Castデバイスを操作することができ、タブの共有も含ま {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L189" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L149" >}} 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 0fc6df4a34dc..4ab23dc41ea6 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 @@ -445,7 +445,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#L189" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L149" >}} 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 ca9b273ed67b..7c11540fc1ba 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 @@ -446,7 +446,7 @@ Chromedriver 和 Chrome 浏览器版本应该匹配, 如果它们不匹配, 驱 {{< tabpane text=true >}} {{< tab header="Java" >}} -{{< badge-code >}} +{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L189" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_chrome.py#L149" >}} 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 cb2a9cd63bcb..ac1d97f57137 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.en.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.en.md @@ -442,7 +442,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#L183" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_edge.py#L149" >}} 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 857d2052449f..9ec2b35bc6c7 100644 --- a/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md +++ b/website_and_docs/content/documentation/webdriver/browsers/edge.ja.md @@ -428,7 +428,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#L183" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_edge.py#L149" >}} 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 058ed2a451eb..ff70e45c0664 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 @@ -444,7 +444,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#L183" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_edge.py#L149" >}} 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 f2a2d6cc1b54..0f72fe589e3a 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 @@ -444,7 +444,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#L183" >}} {{< /tab >}} {{< tab header="Python" >}} {{< gh-codeblock path="/examples/python/tests/browsers/test_edge.py#L149" >}}