Skip to content

Commit

Permalink
support edge simulation also and some test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 5, 2021
1 parent f8e6738 commit f59869b
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 13 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-edge-driver</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public class BrowserVersionDeterminer {

static {
browsers.add(new Chrome());
browsers.add(new IE());
browsers.add(new Edge());
browsers.add(new Firefox());
browsers.add(new IE());
}

/**
Expand Down Expand Up @@ -105,6 +106,18 @@ public BrowserVersion getBrowserVersion() {
}
}

protected static class Edge implements BrowserInfo {
@Override
public Browser getBrowser() {
return Browser.EDGE;
}

@Override
public BrowserVersion getBrowserVersion() {
return BrowserVersion.EDGE;
}
}

protected static class IE implements BrowserInfo {
@Override
public Browser getBrowser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ public String getDomAttribute(String name) {
if (ATTRIBUTE_NOT_DEFINED == value) {
return null;
}

if ("disabled".equals(lowerName)) {
if (element instanceof DisabledElement) {
return trueOrNull(((DisabledElement) element).isDisabled());
}
}

return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ else if (browsers.contains("ff")) {
runners_.add(new BrowserVersionClassRunnerWithParameters(
klass, BrowserVersion.INTERNET_EXPLORER, true, tests));
}
if (browsers.contains("edge")) {
runners_.add(new BrowserVersionClassRunnerWithParameters(
klass, BrowserVersion.EDGE, true, tests));
}
}

if (browsers.contains("hu-chrome")) {
Expand Down
36 changes: 35 additions & 1 deletion src/test/java/org/openqa/selenium/htmlunit/BrowserRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.htmlunit;

import static org.openqa.selenium.htmlunit.BrowserRunner.TestedBrowser.CHROME;
import static org.openqa.selenium.htmlunit.BrowserRunner.TestedBrowser.EDGE;
import static org.openqa.selenium.htmlunit.BrowserRunner.TestedBrowser.FF;
import static org.openqa.selenium.htmlunit.BrowserRunner.TestedBrowser.FF78;
import static org.openqa.selenium.htmlunit.BrowserRunner.TestedBrowser.IE;
Expand Down Expand Up @@ -88,6 +89,9 @@ public BrowserRunner(final Class<WebTestCase> klass) throws Throwable {
if (browsers.contains("ie")) {
runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.INTERNET_EXPLORER, true));
}
if (browsers.contains("edge")) {
runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.EDGE, true));
}
}

if (browsers.contains("hu-chrome")) {
Expand All @@ -105,6 +109,9 @@ public BrowserRunner(final Class<WebTestCase> klass) throws Throwable {
if (browsers.contains("hu-ie")) {
runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.INTERNET_EXPLORER, false));
}
if (browsers.contains("hu-edge")) {
runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.EDGE, false));
}
}
else {
throw new IllegalStateException("No @Test method found");
Expand Down Expand Up @@ -162,6 +169,9 @@ public enum TestedBrowser {
/** Internet Explorer 11. */
IE,

/** Edge. */
EDGE,

/** Firefox. */
FF,

Expand Down Expand Up @@ -194,6 +204,12 @@ public enum TestedBrowser {
*/
String[] IE() default { EMPTY_DEFAULT };

/**
* Alerts for latest Edge.
* @return the alerts
*/
String[] EDGE() default { EMPTY_DEFAULT };

/**
* Alerts for latest Firefox.
* @return the alerts
Expand Down Expand Up @@ -240,6 +256,12 @@ public enum TestedBrowser {
*/
String[] IE() default { EMPTY_DEFAULT };

/**
* Alerts for latest Edge.
* @return the alerts
*/
String[] EDGE() default { EMPTY_DEFAULT };

/**
* Alerts for latest Firefox.
* @return the alerts
Expand Down Expand Up @@ -291,7 +313,7 @@ public enum OS {
* @return the browsers
*/
TestedBrowser[] value() default {
IE, FF78, FF, CHROME
IE, EDGE, FF78, FF, CHROME
};

/**
Expand Down Expand Up @@ -320,6 +342,12 @@ TestedBrowser[] value() default {
*/
String[] IE() default { EMPTY_DEFAULT };

/**
* Alerts for latest Edge.
* @return the alerts
*/
String[] EDGE() default { EMPTY_DEFAULT };

/**
* Alerts for any Firefox, it can be overridden by specific FF version.
* @return the alerts
Expand Down Expand Up @@ -364,6 +392,12 @@ TestedBrowser[] value() default {
*/
String[] IE() default { EMPTY_DEFAULT };

/**
* Alerts for latest Edge.
* @return the alerts
*/
String[] EDGE() default { EMPTY_DEFAULT };

/**
* Alerts for latest Firefox.
* @return the alerts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public void unsupportedAttribute() throws Exception {
}

@Test
@Alerts(DEFAULT = {"true", "true"},
FF = {"", "disabled"},
FF78 = {"", "disabled"})
public void disabled() throws Exception {
String html = "<html>\n"
+ "<head>\n"
Expand All @@ -86,4 +83,21 @@ public void disabled() throws Exception {
WebElement elem = driver.findElement(By.id("chkBx"));
assertEquals("true", elem.getDomAttribute("disabled"));
}

@Test
public void notDisabled() throws Exception {
String html = "<html>\n"
+ "<head>\n"
+ "</head>\n"
+ "<body>\n"
+ " <fieldset>\n"
+ " <input type='checkbox' id='chkBx' name='chbox' value='dis'>not disabled\n"
+ " </fieldset>\n"
+ "</body>\n"
+ "</html>\n";

final WebDriver driver = loadPage2(html);
WebElement elem = driver.findElement(By.id("chkBx"));
assertNull(elem.getDomAttribute("disabled"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.BrowserRunner.Alerts;
import org.openqa.selenium.htmlunit.BrowserRunner.HtmlUnitNYI;
import org.openqa.selenium.htmlunit.BrowserRunner.NotYetImplemented;

/**
Expand All @@ -39,10 +40,13 @@ public class HtmlUnitWebElementTextTest extends WebDriverTestCase {
*/
@Test
@Alerts(CHROME = " option1\n Number Three\n Number 4\n ",
EDGE = " option1\n Number Three\n Number 4\n ",
FF = "option1\nNumber Three\nNumber 4",
FF78 = "option1\nNumber Three\nNumber 4",
IE = "option1 Number Three Number 4")
@NotYetImplemented({CHROME, IE})
@HtmlUnitNYI(CHROME = "option1\nNumber Three\nNumber 4",
EDGE = "option1\nNumber Three\nNumber 4",
IE = "option1\nNumber Three\nNumber 4")
public void select() throws Exception {
final String html =
"<html>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeDriverService;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.htmlunit.html.HtmlPageTest;
Expand Down Expand Up @@ -126,14 +128,15 @@ public abstract class WebDriverTestCase extends WebTestCase {
/**
* All browsers supported.
*/
public static BrowserVersion[] ALL_BROWSERS_ = {BrowserVersion.CHROME, BrowserVersion.FIREFOX,
public static BrowserVersion[] ALL_BROWSERS_ = {BrowserVersion.CHROME, BrowserVersion.EDGE, BrowserVersion.FIREFOX,
BrowserVersion.FIREFOX_78, BrowserVersion.INTERNET_EXPLORER};

private static final Log LOG = LogFactory.getLog(WebDriverTestCase.class);

private static Set<String> BROWSERS_PROPERTIES_;
private static String CHROME_BIN_;
private static String IE_BIN_;
private static String EDGE_BIN_;
private static String GECKO_BIN_;
private static String FF_BIN_;
private static String FF78_BIN_;
Expand Down Expand Up @@ -186,6 +189,7 @@ static Set<String> getBrowsersProperties() {
.toLowerCase(Locale.ROOT).split(",")));
CHROME_BIN_ = properties.getProperty("chrome.bin");
IE_BIN_ = properties.getProperty("ie.bin");
EDGE_BIN_ = properties.getProperty("edge.bin");

GECKO_BIN_ = properties.getProperty("geckodriver.bin");
FF_BIN_ = properties.getProperty("ff.bin");
Expand Down Expand Up @@ -400,6 +404,13 @@ protected WebDriver buildWebDriver() throws IOException {
return ieDriver;
}

if (BrowserVersion.EDGE == getBrowserVersion()) {
if (EDGE_BIN_ != null) {
System.setProperty(EdgeDriverService.EDGE_DRIVER_EXE_PROPERTY, EDGE_BIN_);
}
return new EdgeDriver();
}

if (BrowserVersion.CHROME == getBrowserVersion()) {
if (CHROME_BIN_ != null) {
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, CHROME_BIN_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class HTMLImageElementTest extends WebDriverTestCase {
@Test
@Alerts(DEFAULT = {"number: 300", "number: 200", "number: 24", "number: 24", "number: 24", "number: 24"},
CHROME = {"number: 300", "number: 200", "number: 16", "number: 16", "number: 16", "number: 16"},
EDGE = {"number: 300", "number: 200", "number: 16", "number: 16", "number: 16", "number: 16"},
IE = {"number: 300", "number: 200", "number: 28", "number: 30", "number: 28", "number: 30"})
public void widthHeightInvalidSource() throws Exception {
getMockWebConnection().setDefaultResponse("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openqa.selenium.htmlunit.BrowserRunner;
import org.openqa.selenium.htmlunit.BrowserRunner.Alerts;
import org.openqa.selenium.htmlunit.BrowserRunner.AlertsStandards;
import org.openqa.selenium.htmlunit.BrowserRunner.HtmlUnitNYI;

import com.gargoylesoftware.htmlunit.BrowserVersion;

Expand All @@ -37,15 +38,13 @@ class BrowserStatement extends Statement {
private Statement next_;
private final boolean notYetImplemented_;
private final FrameworkMethod method_;
private final boolean realBrowser_;
private final BrowserVersion browserVersion_;
private final int tries_;

BrowserStatement(final Statement next, final FrameworkMethod method, final boolean realBrowser,
final boolean notYetImplemented, final int tries, final BrowserVersion browserVersion) {
next_ = next;
method_ = method;
realBrowser_ = realBrowser;
notYetImplemented_ = notYetImplemented;
tries_ = tries;
browserVersion_ = browserVersion;
Expand Down Expand Up @@ -84,20 +83,71 @@ private void assertAlerts() {
&& BrowserVersionClassRunner.isDefined(alerts.CHROME())
&& BrowserVersionClassRunner.isDefined(alerts.FF())
&& BrowserVersionClassRunner.isDefined(alerts.FF78())
&& BrowserVersionClassRunner.isDefined(alerts.IE()));
&& BrowserVersionClassRunner.isDefined(alerts.IE())
&& BrowserVersionClassRunner.isDefined(alerts.EDGE()));

assertFalse("Obsolete DEFAULT because all browser expectations are defined individually",
BrowserVersionClassRunner.isDefined(alerts.DEFAULT())
&& BrowserVersionClassRunner.isDefined(alerts.CHROME())
&& BrowserVersionClassRunner.isDefined(alerts.FF())
&& BrowserVersionClassRunner.isDefined(alerts.FF78())
&& BrowserVersionClassRunner.isDefined(alerts.IE()));
&& BrowserVersionClassRunner.isDefined(alerts.IE())
&& BrowserVersionClassRunner.isDefined(alerts.EDGE()));

assertNotEquals(BrowserVersion.INTERNET_EXPLORER, alerts.IE(), alerts.DEFAULT());
assertNotEquals(BrowserVersion.CHROME, alerts.CHROME(), alerts.DEFAULT());
assertNotEquals(BrowserVersion.EDGE, alerts.EDGE(), alerts.DEFAULT());
assertNotEquals(BrowserVersion.FIREFOX, alerts.FF(), alerts.DEFAULT());
assertNotEquals(BrowserVersion.FIREFOX_78, alerts.FF78(), alerts.DEFAULT());
}

final HtmlUnitNYI nyiAlerts = method_.getAnnotation(HtmlUnitNYI.class);
if (nyiAlerts != null) {
if (BrowserVersionClassRunner.isDefined(alerts.CHROME())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.CHROME())) {
assertNotEquals(BrowserVersion.CHROME, alerts.CHROME(), nyiAlerts.CHROME());
}
else if (BrowserVersionClassRunner.isDefined(alerts.DEFAULT())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.CHROME())) {
assertNotEquals(BrowserVersion.CHROME, alerts.DEFAULT(), nyiAlerts.CHROME());
}

if (BrowserVersionClassRunner.isDefined(alerts.FF78())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.FF78())) {
assertNotEquals(BrowserVersion.FIREFOX_78, alerts.FF78(), nyiAlerts.FF78());
}
else if (BrowserVersionClassRunner.isDefined(alerts.DEFAULT())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.FF78())) {
assertNotEquals(BrowserVersion.FIREFOX_78, alerts.DEFAULT(), nyiAlerts.FF78());
}

if (BrowserVersionClassRunner.isDefined(alerts.FF())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.FF())) {
assertNotEquals(BrowserVersion.FIREFOX, alerts.FF(), nyiAlerts.FF());
}
else if (BrowserVersionClassRunner.isDefined(alerts.DEFAULT())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.FF())) {
assertNotEquals(BrowserVersion.FIREFOX, alerts.DEFAULT(), nyiAlerts.FF());
}

if (BrowserVersionClassRunner.isDefined(alerts.IE())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.IE())) {
assertNotEquals(BrowserVersion.INTERNET_EXPLORER, alerts.IE(), nyiAlerts.IE());
}
else if (BrowserVersionClassRunner.isDefined(alerts.DEFAULT())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.IE())) {
assertNotEquals(BrowserVersion.INTERNET_EXPLORER, alerts.DEFAULT(), nyiAlerts.IE());
}

if (BrowserVersionClassRunner.isDefined(alerts.EDGE())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.EDGE())) {
assertNotEquals(BrowserVersion.EDGE, alerts.EDGE(), nyiAlerts.EDGE());
}
else if (BrowserVersionClassRunner.isDefined(alerts.DEFAULT())
&& BrowserVersionClassRunner.isDefined(nyiAlerts.EDGE())) {
assertNotEquals(BrowserVersion.EDGE, alerts.DEFAULT(), nyiAlerts.EDGE());
}
}
}

final AlertsStandards alerts2 = method_.getAnnotation(AlertsStandards.class);
Expand All @@ -107,10 +157,11 @@ private void assertAlerts() {
BrowserVersionClassRunner.isDefined(alerts2.DEFAULT())
&& BrowserVersionClassRunner.isDefined(alerts2.CHROME())
&& BrowserVersionClassRunner.isDefined(alerts2.FF())
&& BrowserVersionClassRunner.isDefined(alerts2.FF78())
&& BrowserVersionClassRunner.isDefined(alerts2.IE()));
&& BrowserVersionClassRunner.isDefined(alerts2.IE())
&& BrowserVersionClassRunner.isDefined(alerts2.EDGE()));

assertNotEquals(BrowserVersion.INTERNET_EXPLORER, alerts2.IE(), alerts2.DEFAULT());
assertNotEquals(BrowserVersion.EDGE, alerts2.EDGE(), alerts2.DEFAULT());
assertNotEquals(BrowserVersion.CHROME, alerts2.CHROME(), alerts2.DEFAULT());
assertNotEquals(BrowserVersion.FIREFOX, alerts2.FF(), alerts2.DEFAULT());
assertNotEquals(BrowserVersion.FIREFOX_78, alerts2.FF78(), alerts2.DEFAULT());
Expand Down
Loading

0 comments on commit f59869b

Please sign in to comment.