Skip to content
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
2 changes: 2 additions & 0 deletions .skipped-tests
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
-//java/test/org/openqa/selenium/bidi/browsingcontext:BrowsingContextInspectorTest-firefox-beta-remote
-//java/test/org/openqa/selenium/bidi/browsingcontext:BrowsingContextTest-firefox-beta
-//java/test/org/openqa/selenium/bidi/browsingcontext:BrowsingContextTest-firefox-beta-remote
-//java/test/org/openqa/selenium/bidi/emulation:SetNetworkConditionsTest-firefox-beta
-//java/test/org/openqa/selenium/bidi/emulation:SetNetworkConditionsTest-firefox-beta-remote
-//rb/spec/integration/selenium/webdriver/bidi:browsing_context-firefox-beta-bidi
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
package org.openqa.selenium;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.openqa.selenium.UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY;
import static org.openqa.selenium.UnexpectedAlertBehaviour.IGNORE;
import static org.openqa.selenium.WaitingConditions.elementTextToEqual;
import static org.openqa.selenium.remote.CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR;
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;

import java.time.Duration;
Expand Down Expand Up @@ -58,7 +60,7 @@ public void canSilentlyAcceptUnhandledAlert() {
@Ignore(value = EDGE, reason = "Unstable Chrome behavior")
@NoDriverBeforeTest
public void canDismissUnhandledAlert() {
runScenarioWithUnhandledAlert(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY, "null", false);
runScenarioWithUnhandledAlert(DISMISS_AND_NOTIFY, "null", false);
}

@Test
Expand All @@ -72,6 +74,7 @@ public void canSilentlyDismissUnhandledAlert() {
@Test
@Ignore(value = CHROME, reason = "Chrome uses IGNORE mode by default")
@Ignore(value = EDGE, reason = "Edge uses IGNORE mode by default")
@Ignore(value = FIREFOX, reason = "Browser#FIREFOX sets IGNORE mode by default")
@NoDriverBeforeTest
public void canDismissUnhandledAlertsByDefault() {
runScenarioWithUnhandledAlert(null, "null", false);
Expand Down
119 changes: 68 additions & 51 deletions java/test/org/openqa/selenium/WebScriptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,37 @@

package org.openqa.selenium;

import static java.time.Instant.ofEpochMilli;
import static java.time.ZoneId.systemDefault;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;

import java.time.Duration;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.bidi.log.ConsoleLogEntry;
import org.openqa.selenium.bidi.log.JavascriptLogEntry;
import org.openqa.selenium.bidi.log.LogLevel;
import org.openqa.selenium.remote.DomMutation;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.Script;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.NeedsFreshDriver;

class WebScriptTest extends JupiterTestBase {

String page;
private String page;

@Test
@NeedsFreshDriver
Expand Down Expand Up @@ -182,58 +186,52 @@ void canAddMultipleHandlers() throws ExecutionException, InterruptedException, T

@Test
@NeedsFreshDriver
void canAddDomMutationHandler() throws InterruptedException {
AtomicReference<DomMutation> seen = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
void canAddDomMutationHandler() {
List<String> mutations = new CopyOnWriteArrayList<>();

((RemoteWebDriver) driver)
.script()
.addDomMutationHandler(
mutation -> {
seen.set(mutation);
latch.countDown();
});
Script script = ((RemoteWebDriver) driver).script();
script.addDomMutationHandler(mutationHandler(mutations));

driver.get(pages.dynamicPage);
triggerDomMutation();

WebElement reveal = driver.findElement(By.id("reveal"));
reveal.click();
WebElement revealed = driver.findElement(By.id("revealed"));

new WebDriverWait(driver, Duration.ofSeconds(10)).until(visibilityOf(revealed));

Assertions.assertThat(latch.await(10, SECONDS)).isTrue();
assertThat(seen.get().getAttributeName()).isEqualTo("style");
assertThat(seen.get().getCurrentValue()).isEmpty();
assertThat(seen.get().getOldValue()).isEqualTo("display:none;");
assertThat(mutations).isNotEmpty();
assertThat(lastOf(mutations)).isEqualTo("style: 'display:none;' -> ''");
}

@Test
@NeedsFreshDriver
void canRemoveDomMutationHandler() throws InterruptedException {
AtomicReference<DomMutation> seen = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);

long id =
((RemoteWebDriver) driver)
.script()
.addDomMutationHandler(
mutation -> {
seen.set(mutation);
latch.countDown();
});
void canRemoveDomMutationHandler() {
List<String> mutations = new CopyOnWriteArrayList<>();
Script script = ((RemoteWebDriver) driver).script();
long id = script.addDomMutationHandler(mutationHandler(mutations));

driver.get(pages.dynamicPage);
triggerDomMutation();
assertThat(mutations).isNotEmpty();

script.removeDomMutationHandler(id);

((RemoteWebDriver) driver).script().removeDomMutationHandler(id);
mutations.clear();
driver.get(pages.dynamicPage);
triggerDomMutation();
assertThat(mutations).isEmpty();
}

private void triggerDomMutation() {
WebElement reveal = driver.findElement(By.id("reveal"));
reveal.click();
WebElement revealed = driver.findElement(By.id("revealed"));

new WebDriverWait(driver, Duration.ofSeconds(10)).until(visibilityOf(revealed));
}

Assertions.assertThat(latch.await(10, SECONDS)).isFalse();
private static Consumer<DomMutation> mutationHandler(List<String> mutations) {
return mutation -> {
mutations.add(
String.format(
"%s: '%s' -> '%s'",
mutation.getAttributeName(), mutation.getOldValue(), mutation.getCurrentValue()));
};
}

@Test
Expand All @@ -257,27 +255,46 @@ void canPinScript() throws ExecutionException, InterruptedException, TimeoutExce

@Test
@NeedsFreshDriver
void canUnpinScript() {
CountDownLatch latch = new CountDownLatch(2);
void canUnpinScript() throws InterruptedException {
List<String> logs = new CopyOnWriteArrayList<>();
CountDownLatch latch = new CountDownLatch(1);

Script script = ((RemoteWebDriver) driver).script();
String pinnedScript = script.pin("() => { console.log('Hello!'); }");

String pinnedScript =
((RemoteWebDriver) driver).script().pin("() => { console.log('Hello!'); }");
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("HH:mm:ss:SSS").withZone(systemDefault());

long id =
((RemoteWebDriver) driver)
.script()
.addConsoleMessageHandler(consoleLogEntry -> latch.countDown());
script.addConsoleMessageHandler(
log -> {
String time = formatter.format(ofEpochMilli(log.getTimestamp()));
String message = String.format("%s %s", log.getText(), time);
logs.add(message);
latch.countDown();
});

page = appServer.whereIs("/bidi/logEntryAdded.html");
try {
page = appServer.whereIs("/bidi/logEntryAdded.html");
assertThat(logs).hasSize(0);

driver.get(page);
driver.get(page);
assertThat(latch.await(10, SECONDS)).isTrue();

((RemoteWebDriver) driver).script().unpin(pinnedScript);
assertThat(logs).as("Chrome logs once, FireFox logs twice").isNotEmpty();
assertThat(logs.get(0)).startsWith("Hello!");

driver.get(page);
script.unpin(pinnedScript);

assertThat(latch.getCount()).isEqualTo(1L);
logs.clear();
driver.get(page);
assertThat(logs).as("Script has been unpinned, no logs anymore.").isEmpty();
} finally {
script.removeConsoleMessageHandler(id);
}
}

((RemoteWebDriver) driver).script().removeConsoleMessageHandler(id);
private static <T> T lastOf(List<T> list) {
return list.get(list.size() - 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.bidi.browser.DownloadBehavior.allowed;
import static org.openqa.selenium.bidi.browser.DownloadBehavior.denied;
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
import static org.openqa.selenium.testing.drivers.Browser.detect;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -47,7 +45,6 @@
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.NeedsFreshDriver;
import org.openqa.selenium.testing.NotYetImplemented;

class BrowserCommandsTest extends JupiterTestBase {

Expand All @@ -62,9 +59,7 @@ final void setUp() {

@AfterEach
final void resetDownloadBehavior() {
if (detect() != FIREFOX) {
browser.setDownloadBehavior(new SetDownloadBehaviorParameters(null));
}
browser.setDownloadBehavior(new SetDownloadBehaviorParameters(null));
}

@AfterEach
Expand Down Expand Up @@ -133,7 +128,6 @@ void canGetClientWindows() {

@Test
@NeedsFreshDriver
@NotYetImplemented(FIREFOX)
void canSetDownloadBehaviorAllowed() {
browser.setDownloadBehavior(new SetDownloadBehaviorParameters(allowed(tmpDir)));

Expand All @@ -148,7 +142,6 @@ void canSetDownloadBehaviorAllowed() {

@Test
@NeedsFreshDriver
@NotYetImplemented(FIREFOX)
void canSetDownloadBehaviorDenied() throws InterruptedException {
browser.setDownloadBehavior(new SetDownloadBehaviorParameters(denied()));

Expand All @@ -168,7 +161,6 @@ void canSetDownloadBehaviorDenied() throws InterruptedException {

@Test
@NeedsFreshDriver
@NotYetImplemented(FIREFOX)
void canSetDownloadBehaviorWithUserContext() throws InterruptedException {
String userContext = browser.createUserContext();

Expand Down
2 changes: 2 additions & 0 deletions java/test/org/openqa/selenium/testing/drivers/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.openqa.selenium.testing.drivers;

import static org.openqa.selenium.UnexpectedAlertBehaviour.IGNORE;
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
import static org.openqa.selenium.remote.CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR;

Expand Down Expand Up @@ -135,6 +136,7 @@ public Capabilities getCapabilities() {
@Override
public Capabilities getCapabilities() {
FirefoxOptions options = new FirefoxOptions().configureFromEnv();
options.setCapability(UNHANDLED_PROMPT_BEHAVIOUR, IGNORE);

resolveDriverPath("webdriver.gecko.driver");
String binary = InProject.resolveRunfilesPath(System.getProperty("webdriver.firefox.bin"));
Expand Down
Loading