Skip to content

Commit

Permalink
Merge branch 'trunk' into py-client-config
Browse files Browse the repository at this point in the history
  • Loading branch information
VietND96 authored Nov 7, 2024
2 parents 2657eed + d411615 commit 24e04b6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,20 @@ void canSetPermission() {
@NoDriverBeforeTest
public void canSetPermissionHeadless() {
EdgeOptions options = new EdgeOptions();
options.addArguments("--headless=chrome");
options.addArguments("--headless=new");

localDriver = new WebDriverBuilder().get(options);
HasPermissions permissions = (HasPermissions) localDriver;

localDriver.get(pages.clicksPage);
assertThat(checkPermission(localDriver, CLIPBOARD_READ)).isEqualTo("prompt");
assertThat(checkPermission(localDriver, CLIPBOARD_WRITE)).isEqualTo("prompt");
assertThat(checkPermission(localDriver, CLIPBOARD_WRITE)).isEqualTo("granted");

permissions.setPermission(CLIPBOARD_READ, "granted");
permissions.setPermission(CLIPBOARD_WRITE, "granted");
permissions.setPermission(CLIPBOARD_WRITE, "prompt");

assertThat(checkPermission(localDriver, CLIPBOARD_READ)).isEqualTo("granted");
assertThat(checkPermission(localDriver, CLIPBOARD_WRITE)).isEqualTo("granted");
assertThat(checkPermission(localDriver, CLIPBOARD_WRITE)).isEqualTo("prompt");
}

public String checkPermission(WebDriver driver, String permission) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -57,6 +58,8 @@

class RemoteWebDriverDownloadTest {

private static final Set<String> FILE_EXTENSIONS = Set.of(".txt", ".jpg");

private Server<?> server;
private NettyAppServer appServer;
private Capabilities capabilities;
Expand Down Expand Up @@ -112,7 +115,15 @@ void canListDownloadedFiles() {
driver.findElement(By.id("file-2")).click();

new WebDriverWait(driver, Duration.ofSeconds(5))
.until(d -> ((HasDownloads) d).getDownloadableFiles().size() == 2);
.until(
d ->
((HasDownloads) d)
.getDownloadableFiles().stream()
// ensure we hit no temporary file created by the browser while
// downloading
.filter((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith))
.count()
== 2);

List<String> downloadableFiles = ((HasDownloads) driver).getDownloadableFiles();
assertThat(downloadableFiles).contains("file_1.txt", "file_2.jpg");
Expand All @@ -132,7 +143,12 @@ void canDownloadFiles() throws IOException {
driver.findElement(By.id("file-1")).click();

new WebDriverWait(driver, Duration.ofSeconds(5))
.until(d -> !((HasDownloads) d).getDownloadableFiles().isEmpty());
.until(
d ->
((HasDownloads) d)
.getDownloadableFiles().stream()
// ensure we hit no temporary file created by the browser while downloading
.anyMatch((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith)));

String fileName = ((HasDownloads) driver).getDownloadableFiles().get(0);

Expand All @@ -155,7 +171,12 @@ void testCanDeleteFiles() {
driver.findElement(By.id("file-1")).click();

new WebDriverWait(driver, Duration.ofSeconds(5))
.until(d -> !((HasDownloads) d).getDownloadableFiles().isEmpty());
.until(
d ->
((HasDownloads) d)
.getDownloadableFiles().stream()
// ensure we hit no temporary file created by the browser while downloading
.anyMatch((f) -> FILE_EXTENSIONS.stream().anyMatch(f::endsWith)));

driver = new Augmenter().augment(driver);
((HasDownloads) driver).deleteDownloadableFiles();
Expand Down
10 changes: 5 additions & 5 deletions javascript/node/selenium-webdriver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
"ws": "^8.18.0"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@eslint/js": "^9.14.0",
"clean-jsdoc-theme": "^4.3.0",
"eslint": "^9.13.0",
"eslint": "^9.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-n": "^17.11.1",
"eslint-plugin-n": "^17.13.1",
"eslint-plugin-no-only-tests": "^3.3.0",
"eslint-plugin-prettier": "^5.2.1",
"express": "^4.21.1",
"globals": "^15.11.0",
"globals": "^15.12.0",
"has-flag": "^5.0.1",
"jsdoc": "^4.0.4",
"mocha": "^10.7.3",
"mocha": "^10.8.2",
"mocha-junit-reporter": "^2.2.1",
"multer": "1.4.5-lts.1",
"prettier": "^3.3.3",
Expand Down
Loading

0 comments on commit 24e04b6

Please sign in to comment.