-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ChromiumDriver.setPermission to Java bindings
Add setPermission to ChromiumDriver to support the same command added for version 78. This change updates the Java client bindings. This will allow Selenium code to override default permissions that would otherwise require user action. Fixes #7539
- Loading branch information
1 parent
f25d117
commit 2260d41
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
java/client/test/org/openqa/selenium/chrome/ChromeDriverFunctionalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.chrome; | ||
|
||
import org.junit.Test; | ||
import org.openqa.selenium.testing.JUnit4TestBase; | ||
|
||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ChromeDriverFunctionalTest extends JUnit4TestBase { | ||
|
||
private final String CLIPBOARD_READ = "clipboard-read"; | ||
private final String CLIPBOARD_WRITE = "clipboard-write"; | ||
|
||
private ChromeDriver driver = null; | ||
|
||
@Test | ||
public void canSetPermission() { | ||
//Cast provided driver to enable ChromeSpecific calls | ||
driver = (ChromeDriver) super.driver; | ||
|
||
driver.get(pages.clicksPage); | ||
assertThat(checkPermission(driver, CLIPBOARD_READ)).isEqualTo("prompt"); | ||
assertThat(checkPermission(driver, CLIPBOARD_WRITE)).isEqualTo("granted"); | ||
|
||
driver.setPermission(CLIPBOARD_READ, "denied"); | ||
driver.setPermission(CLIPBOARD_WRITE, "prompt"); | ||
|
||
assertThat(checkPermission(driver, CLIPBOARD_READ)).isEqualTo("denied"); | ||
assertThat(checkPermission(driver, CLIPBOARD_WRITE)).isEqualTo("prompt"); | ||
} | ||
|
||
@Test | ||
public void canSetPermissionHeadless() { | ||
ChromeOptions options = new ChromeOptions(); | ||
options.setHeadless(true); | ||
//TestChromeDriver is not honoring headless request; using ChromeDriver instead | ||
super.driver = new ChromeDriver(options); | ||
driver = (ChromeDriver) super.driver; | ||
|
||
driver.get(pages.clicksPage); | ||
assertThat(checkPermission(driver, CLIPBOARD_READ)).isEqualTo("prompt"); | ||
assertThat(checkPermission(driver, CLIPBOARD_WRITE)).isEqualTo("prompt"); | ||
|
||
driver.setPermission(CLIPBOARD_READ, "granted"); | ||
driver.setPermission(CLIPBOARD_WRITE, "granted"); | ||
|
||
assertThat(checkPermission(driver, CLIPBOARD_READ)).isEqualTo("granted"); | ||
assertThat(checkPermission(driver, CLIPBOARD_WRITE)).isEqualTo("granted"); | ||
} | ||
|
||
public String checkPermission(ChromeDriver driver, String permission){ | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> result = (Map<String, Object>) driver.executeAsyncScript( | ||
"callback = arguments[arguments.length - 1];" | ||
+ "callback(navigator.permissions.query({" | ||
+ "name: arguments[0]" | ||
+ "}));", permission); | ||
return result.get("state").toString(); | ||
} | ||
} |