Skip to content

Commit

Permalink
[java] Running a single driver instance if possible (some drivers don…
Browse files Browse the repository at this point in the history
…'t allow multiple instances e.g. Safari or Edge)
  • Loading branch information
barancev committed Feb 19, 2019
1 parent 832ea2d commit 4c41c3d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testShouldFireFocusEventWhenClicking() {
@Test
@Ignore(FIREFOX)
@NotYetImplemented(SAFARI)
@Ignore(EDGE)
@Ignore(value = EDGE, reason = "Can't run two instances at once")
public void testShouldFireFocusEventInNonTopmostWindow() {
WebDriver driver2 = new WebDriverBuilder().get();
try {
Expand Down Expand Up @@ -302,7 +302,7 @@ public void testSendingKeysToAnotherElementShouldCauseTheBlurEventToFire() {

@Test
@Ignore(value = SAFARI, reason = "Allows only one instance")
@Ignore(EDGE)
@Ignore(value = EDGE, reason = "Can't run two instances at once")
public void testSendingKeysToAnotherElementShouldCauseTheBlurEventToFireInNonTopmostWindow() {
assumeFalse(browserNeedsFocusOnThisOs(driver));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,27 @@
import static org.openqa.selenium.WaitingConditions.elementTextToEqual;
import static org.openqa.selenium.remote.CapabilityType.UNEXPECTED_ALERT_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.HTMLUNIT;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;

import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.NeedsLocalEnvironment;
import org.openqa.selenium.testing.NotYetImplemented;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;
import org.openqa.selenium.testing.NoDriverBeforeTest;

@NeedsLocalEnvironment(reason = "Requires local browser launching environment")
@Ignore(value = SAFARI, reason = "Does not support alerts yet")
@Ignore(EDGE)
public class UnexpectedAlertBehaviorTest extends JUnit4TestBase {

private WebDriver driver2;

@After
public void quitDriver() {
if (driver2 != null) {
driver2.quit();
}
}

@Test
@Ignore(value = FIREFOX, reason = "Legacy behaviour, not W3C conformant")
@Ignore(value = CHROME, reason = "Legacy behaviour, not W3C conformant")
@Ignore(value = HTMLUNIT, reason = "Legacy behaviour, not W3C conformant")
@NoDriverBeforeTest
public void canAcceptUnhandledAlert() {
runScenarioWithUnhandledAlert(UnexpectedAlertBehaviour.ACCEPT_AND_NOTIFY, "This is a default value", false);
}
Expand All @@ -62,14 +51,15 @@ public void canAcceptUnhandledAlert() {
@Ignore(value = FIREFOX, reason = "Legacy behaviour, not W3C conformant")
@Ignore(value = CHROME, reason = "Legacy behaviour, not W3C conformant")
@Ignore(value = HTMLUNIT, reason = "Legacy behaviour, not W3C conformant")
@NoDriverBeforeTest
public void canSilentlyAcceptUnhandledAlert() {
runScenarioWithUnhandledAlert(UnexpectedAlertBehaviour.ACCEPT, "This is a default value", true);
}

@Test
@Ignore(value = CHROME, reason = "Unstable Chrome behavior")
@Ignore(value = HTMLUNIT, reason = "Legacy behaviour, not W3C conformant")
@NotYetImplemented(EDGE)
@NoDriverBeforeTest
public void canDismissUnhandledAlert() {
runScenarioWithUnhandledAlert(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY, "null", false);
}
Expand All @@ -78,22 +68,25 @@ public void canDismissUnhandledAlert() {
@Ignore(value = FIREFOX, reason = "Legacy behaviour, not W3C conformant")
@Ignore(value = CHROME, reason = "Legacy behaviour, not W3C conformant")
@Ignore(value = HTMLUNIT, reason = "Legacy behaviour, not W3C conformant")
@NoDriverBeforeTest
public void canSilentlyDismissUnhandledAlert() {
runScenarioWithUnhandledAlert(UnexpectedAlertBehaviour.DISMISS, "null", true);
}

@Test
@Ignore(value = CHROME, reason = "Chrome uses IGNORE mode by default")
@NoDriverBeforeTest
public void canDismissUnhandledAlertsByDefault() {
runScenarioWithUnhandledAlert(null, "null", false);
}

@Test
@Ignore(value = CHROME, reason = "Unstable Chrome behavior")
@NoDriverBeforeTest
public void canIgnoreUnhandledAlert() {
assertThatExceptionOfType(UnhandledAlertException.class).isThrownBy(
() -> runScenarioWithUnhandledAlert(IGNORE, "Text ignored", true));
driver2.switchTo().alert().dismiss();
driver.switchTo().alert().dismiss();
}

private void runScenarioWithUnhandledAlert(
Expand All @@ -103,15 +96,14 @@ private void runScenarioWithUnhandledAlert(
Capabilities caps = behaviour == null
? new ImmutableCapabilities()
: new ImmutableCapabilities(UNEXPECTED_ALERT_BEHAVIOUR, behaviour);
driver2 = new WebDriverBuilder().get(caps);
createNewDriver(caps);

driver2.get(pages.alertsPage);
driver2.findElement(By.id("prompt-with-default")).click();
driver.get(pages.alertsPage);
driver.findElement(By.id("prompt-with-default")).click();

WebDriverWait wait1 = new WebDriverWait(driver2, 10);
if (! silently) {
wait1.ignoring(UnhandledAlertException.class);
}
Wait<WebDriver> wait1
= silently ? wait
: new WebDriverWait(driver, 10).ignoring(UnhandledAlertException.class);
wait1.until(elementTextToEqual(By.id("text"), expectedAlertText));
}

Expand Down
26 changes: 11 additions & 15 deletions java/client/test/org/openqa/selenium/UploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.NeedsFreshDriver;
import org.openqa.selenium.testing.NoDriverBeforeTest;
import org.openqa.selenium.testing.NotYetImplemented;
import org.openqa.selenium.testing.SwitchToTopAfterTest;
import org.openqa.selenium.testing.TestUtilities;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -123,6 +123,7 @@ public void testUploadingWithHiddenFileInput() {
@Ignore(value = SAFARI, reason = "Hangs forever in sendKeys")
@Ignore(HTMLUNIT)
@NotYetImplemented(EDGE)
@NeedsFreshDriver
public void testUploadingWithInvisibleFileInput() {
driver.get(appServer.whereIs("upload_invisible.html"));
driver.findElement(By.id("upload")).sendKeys(testFile.getAbsolutePath());
Expand All @@ -142,21 +143,16 @@ public void testUploadingWithInvisibleFileInput() {
@Ignore(FIREFOX)
@Ignore(HTMLUNIT)
@NotYetImplemented(EDGE)
@NoDriverBeforeTest
public void testUploadingWithInvisibleFileInputWhenStringFileInteractabilityIsOn() {
WebDriver driver2 = new WebDriverBuilder().get(
new ImmutableCapabilities(CapabilityType.STRICT_FILE_INTERACTABILITY, true));
try {
System.out.println(((RemoteWebDriver) driver2).getCapabilities());
driver2.get(appServer.whereIs("upload_invisible.html"));
WebElement input = driver2.findElement(By.id("upload"));
System.out.println(input.isDisplayed());

assertThatExceptionOfType(ElementNotInteractableException.class).isThrownBy(
() -> input.sendKeys(testFile.getAbsolutePath()));
} finally {
driver2.quit();
}
createNewDriver(new ImmutableCapabilities(CapabilityType.STRICT_FILE_INTERACTABILITY, true));

driver.get(appServer.whereIs("upload_invisible.html"));
WebElement input = driver.findElement(By.id("upload"));
System.out.println(input.isDisplayed());

assertThatExceptionOfType(ElementNotInteractableException.class).isThrownBy(
() -> input.sendKeys(testFile.getAbsolutePath()));
}

private File createTmpFile(String content) throws IOException {
Expand Down

0 comments on commit 4c41c3d

Please sign in to comment.