From 1dcfd170d14f94a35a7d3787a19e9902e5f00bff Mon Sep 17 00:00:00 2001 From: Scott Babcock Date: Sun, 15 Jan 2023 15:02:24 -0800 Subject: [PATCH] Add browser profiles to Gradle project (#256) --- build.gradle | 34 ++++- chromeDeps.gradle | 9 ++ edgeDeps.gradle | 9 ++ espressoDeps.gradle | 12 ++ firefoxDeps.gradle | 9 ++ gradle.properties | 3 - htmlunitDeps.gradle | 9 ++ mac2Deps.gradle | 12 ++ operaDeps.gradle | 9 ++ phantomjsDeps.gradle | 9 ++ pom.xml | 8 +- safariDeps.gradle | 9 ++ selenium3Deps.gradle | 7 + .../selenium/AbstractSeleniumConfig.java | 14 +- .../selenium/core/SeleniumGrid.java | 6 +- .../selenium/examples/ExamplePage.java | 13 ++ .../selenium/model/ComponentContainer.java | 6 +- .../selenium/platform/TargetTypeName.java | 2 +- src/main/resources/ExamplePage.html | 8 +- .../selenium/SeleniumConfigTest.java | 7 + .../selenium/core/ModelTestCore.java | 120 ++++++++++++------ .../selenium/junit/JUnitModelTest.java | 56 ++++++++ .../model/ComponentContainerTest.java | 76 ----------- .../automation/selenium/model/ModelTest.java | 51 +++++++- uiautomator2Deps.gradle | 12 ++ windowsDeps.gradle | 12 ++ xcuitestDeps.gradle | 12 ++ 27 files changed, 393 insertions(+), 141 deletions(-) create mode 100644 chromeDeps.gradle create mode 100644 edgeDeps.gradle create mode 100644 espressoDeps.gradle create mode 100644 firefoxDeps.gradle create mode 100644 htmlunitDeps.gradle create mode 100644 mac2Deps.gradle create mode 100644 operaDeps.gradle create mode 100644 phantomjsDeps.gradle create mode 100644 safariDeps.gradle create mode 100644 uiautomator2Deps.gradle create mode 100644 windowsDeps.gradle create mode 100644 xcuitestDeps.gradle diff --git a/build.gradle b/build.gradle index 37d0ee11..3d2c9e72 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ +import org.gradle.internal.os.OperatingSystem import org.apache.tools.ant.filters.ReplaceTokens plugins { @@ -20,6 +21,15 @@ if (!project.hasProperty('profile')) { apply from: "${profile}Deps.gradle" +if (project.hasProperty('browsers')) { + ext.browsers.split(',').each { + def browser = it.trim() + if (browser) { + apply from: "${browser}Deps.gradle" + } + } +} + def archiveVer = null def verBits = scmVersion.version.split('-') def seleniumApi = 's' + profile.charAt(8) @@ -112,12 +122,26 @@ task testNG(type: Test) { useTestNG() reports.html.destination = file("${buildDir}/reports/testng") testLogging.showStandardStreams = true + + systemProperty 'selenium.grid.plugins', System.getProperty('selenium.grid.plugins') + systemProperty 'selenium.browser.name', System.getProperty('selenium.browser.name') + systemProperty 'selenium.browser.caps', getBrowserCaps() + systemProperty 'selenium.context.platform', System.getProperty('selenium.context.platform', 'support') + systemProperty 'selenium.grid.examples', System.getProperty('selenium.grid.examples', 'true') + systemProperty 'appium.with.pm2', System.getProperty('appium.with.pm2', 'false') } test { dependsOn testNG reports.html.destination = file("${buildDir}/reports/junit") testLogging.showStandardStreams = true + + systemProperty 'selenium.grid.plugins', System.getProperty('selenium.grid.plugins') + systemProperty 'selenium.browser.name', System.getProperty('selenium.browser.name') + systemProperty 'selenium.browser.caps', getBrowserCaps() + systemProperty 'selenium.context.platform', System.getProperty('selenium.context.platform', 'support') + systemProperty 'selenium.grid.examples', System.getProperty('selenium.grid.examples', 'true') + systemProperty 'appium.with.pm2', System.getProperty('appium.with.pm2', 'false') } scmVersion { @@ -213,7 +237,7 @@ dependencies { api 'com.nordstrom.tools:junit-foundation:17.0.2' api 'com.github.sbabcoc:logback-testng:2.0.0' api 'org.hamcrest:hamcrest-core:2.2' - api 'org.yaml:snakeyaml:1.32' + api 'org.yaml:snakeyaml:1.33' } api 'com.nordstrom.tools:java-utils' api 'com.nordstrom.tools:settings' @@ -228,3 +252,11 @@ dependencies { test { jvmArgs "-javaagent:${classpath.find { it.name.contains('junit-foundation') }.absolutePath}" } + +def getBrowserCaps() { + def browserCaps = System.getProperty('selenium.browser.caps') + if (browserCaps && OperatingSystem.current().isWindows()) { + return browserCaps.replaceAll('"', '\\\\"') + } + return browserCaps +} diff --git a/chromeDeps.gradle b/chromeDeps.gradle new file mode 100644 index 00000000..14a2d974 --- /dev/null +++ b/chromeDeps.gradle @@ -0,0 +1,9 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.ChromePlugin' + File.pathSeparator) +System.setProperty('selenium.browser.name', 'chrome') +System.setProperty('selenium.context.platform', 'web-app') +dependencies { + testImplementation('org.seleniumhq.selenium:selenium-chrome-driver') { + exclude module: 'selenium-remote-driver' + } +} diff --git a/edgeDeps.gradle b/edgeDeps.gradle new file mode 100644 index 00000000..9bb6df3b --- /dev/null +++ b/edgeDeps.gradle @@ -0,0 +1,9 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.EdgePlugin' + File.pathSeparator) +System.setProperty('selenium.browser.name', 'MicrosoftEdge') +System.setProperty('selenium.context.platform', 'web-app') +dependencies { + testImplementation('org.seleniumhq.selenium:selenium-edge-driver') { + exclude module: 'selenium-remote-driver' + } +} diff --git a/espressoDeps.gradle b/espressoDeps.gradle new file mode 100644 index 00000000..05bc9ed3 --- /dev/null +++ b/espressoDeps.gradle @@ -0,0 +1,12 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.EspressoPlugin' + File.pathSeparator) +System.setProperty('selenium.browser.caps', '{"platformName":"Android","appium:automationName":"Espresso","appium:forceEspressoRebuild":true,"appium:showGradleLog":true,"appium:app":"https://github.com/appium/appium/raw/master/packages/appium/sample-code/apps/ApiDemos-debug.apk"}') +System.setProperty('selenium.context.platform', 'android') +System.setProperty('selenium.grid.examples', 'false') +System.setProperty('appium.with.pm2', 'true') +dependencies { + testImplementation('io.appium:java-client') { + exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' + exclude group: 'org.seleniumhq.selenium', module: 'selenium-support' + } +} diff --git a/firefoxDeps.gradle b/firefoxDeps.gradle new file mode 100644 index 00000000..2b75920d --- /dev/null +++ b/firefoxDeps.gradle @@ -0,0 +1,9 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.FirefoxPlugin' + File.pathSeparator) +System.setProperty('selenium.browser.name', 'firefox') +System.setProperty('selenium.context.platform', 'web-app') +dependencies { + testImplementation('org.seleniumhq.selenium:selenium-firefox-driver') { + exclude module: 'selenium-remote-driver' + } +} diff --git a/gradle.properties b/gradle.properties index b5f0205e..ad1bf57b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,2 @@ profile=selenium3 version=26.7.0-SNAPSHOT -org.gradle.java.installations.auto-detect=false -org.gradle.java.installations.auto-download=false -org.gradle.java.installations.fromEnv=JDK8_HOME,JDK11_HOME diff --git a/htmlunitDeps.gradle b/htmlunitDeps.gradle new file mode 100644 index 00000000..fea46854 --- /dev/null +++ b/htmlunitDeps.gradle @@ -0,0 +1,9 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.HtmlUnitPlugin' + File.pathSeparator) +System.setProperty('selenium.browser.name', 'htmlunit') +System.setProperty('selenium.context.platform', 'web-app') +dependencies { + testImplementation('org.seleniumhq.selenium:htmlunit-driver') { + exclude module: 'selenium-support' + } +} diff --git a/mac2Deps.gradle b/mac2Deps.gradle new file mode 100644 index 00000000..f80fe0d0 --- /dev/null +++ b/mac2Deps.gradle @@ -0,0 +1,12 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.Mac2Plugin' + File.pathSeparator) +System.setProperty('selenium.browser.caps', '{"platformName":"Mac","appium:automationName":"Mac2","appium:bundleId":"com.apple.TextEdit"}') +System.setProperty('selenium.context.platform', 'mac-app') +System.setProperty('selenium.grid.examples', 'false') +System.setProperty('appium.with.pm2', 'true') +dependencies { + testImplementation('io.appium:java-client') { + exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' + exclude group: 'org.seleniumhq.selenium', module: 'selenium-support' + } +} diff --git a/operaDeps.gradle b/operaDeps.gradle new file mode 100644 index 00000000..fc2bf4c3 --- /dev/null +++ b/operaDeps.gradle @@ -0,0 +1,9 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.OperaPlugin' + File.pathSeparator) +System.setProperty('selenium.browser.name', 'opera') +System.setProperty('selenium.context.platform', 'web-app') +dependencies { + testImplementation('org.seleniumhq.selenium:selenium-opera-driver') { + exclude module: 'selenium-remote-driver' + } +} diff --git a/phantomjsDeps.gradle b/phantomjsDeps.gradle new file mode 100644 index 00000000..6f3adac2 --- /dev/null +++ b/phantomjsDeps.gradle @@ -0,0 +1,9 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.PhantomJsPlugin' + File.pathSeparator) +System.setProperty('selenium.browser.name', 'phantomjs') +System.setProperty('selenium.context.platform', 'web-app') +dependencies { + testImplementation('com.codeborne:phantomjsdriver') { + exclude group: 'org.seleniumhq.selenium', module: 'selenium-remote-driver' + } +} diff --git a/pom.xml b/pom.xml index 805ef621..5d96e6e2 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,7 @@ 3.2.0 2.2 - 1.32 + 1.33 @@ -408,6 +408,12 @@ org.seleniumhq.selenium selenium-chrome-driver + + + org.seleniumhq.selenium + selenium-remote-driver + + diff --git a/safariDeps.gradle b/safariDeps.gradle new file mode 100644 index 00000000..b05c06cd --- /dev/null +++ b/safariDeps.gradle @@ -0,0 +1,9 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.SafariPlugin' + File.pathSeparator) +System.setProperty('selenium.browser.name', 'safari') +System.setProperty('selenium.context.platform', 'web-app') +dependencies { + testImplementation('org.seleniumhq.selenium:selenium-safari-driver') { + exclude module: 'selenium-remote-driver' + } +} diff --git a/selenium3Deps.gradle b/selenium3Deps.gradle index e87a4739..72aeeb17 100644 --- a/selenium3Deps.gradle +++ b/selenium3Deps.gradle @@ -37,6 +37,13 @@ dependencies { api 'org.eclipse.jetty.websocket:websocket-client:9.4.46.v20220331' api 'org.jetbrains.kotlin:kotlin-stdlib:1.7.0' api 'org.jetbrains.kotlin:kotlin-stdlib-common:1.7.0' + testImplementation 'org.seleniumhq.selenium:selenium-chrome-driver:3.141.59' + testImplementation 'org.seleniumhq.selenium:selenium-edge-driver:3.141.59' + testImplementation 'io.appium:java-client:7.6.0' + testImplementation 'org.seleniumhq.selenium:selenium-firefox-driver:3.141.59' + testImplementation 'org.seleniumhq.selenium:selenium-opera-driver:3.141.59' + testImplementation 'com.codeborne:phantomjsdriver:1.4.4' + testImplementation 'org.seleniumhq.selenium:selenium-safari-driver:3.141.59' testImplementation 'org.seleniumhq.selenium:htmlunit-driver:2.67.0' testImplementation 'org.mockito:mockito-core:4.6.1' } diff --git a/src/main/java/com/nordstrom/automation/selenium/AbstractSeleniumConfig.java b/src/main/java/com/nordstrom/automation/selenium/AbstractSeleniumConfig.java index 11335692..999cbc55 100644 --- a/src/main/java/com/nordstrom/automation/selenium/AbstractSeleniumConfig.java +++ b/src/main/java/com/nordstrom/automation/selenium/AbstractSeleniumConfig.java @@ -52,11 +52,7 @@ public abstract class AbstractSeleniumConfig extends SettingsCore { private static final String SETTINGS_FILE = "settings.properties"; - private static final String CAPS_PATTERN = "{\"browserName\":\"%s\"}"; - /** value: {"browserName":"htmlunit"} */ - private static final String DEFAULT_CAPS = String.format(CAPS_PATTERN, "htmlunit"); - protected static final String NODE_MODS_SUFFIX = ".node.mods"; private static final String CAPS_MODS_SUFFIX = ".caps.mods"; @@ -222,9 +218,9 @@ public enum SeleniumSettings implements SettingsCore.SettingsAPI { * requests. This can be either a file path (absolute, relative, or simple filename) or a direct value. *

* name: selenium.browser.caps
- * default: {@link #DEFAULT_CAPS} + * default: {@code null} */ - BROWSER_CAPS("selenium.browser.caps", DEFAULT_CAPS), + BROWSER_CAPS("selenium.browser.caps", null), /** * This setting specifies the maximum allowed interval for a page to finish loading. @@ -735,9 +731,9 @@ public Capabilities getCurrentCapabilities() { Capabilities capabilities = null; String browserName = getString(SeleniumSettings.BROWSER_NAME.key()); String browserCaps = resolveString(SeleniumSettings.BROWSER_CAPS.key()); - if (browserName != null) { + if (!Strings.isNullOrEmpty(browserName)) { capabilities = getSeleniumGrid().getPersonality(getConfig(), browserName); - } else if (browserCaps != null) { + } else if (!Strings.isNullOrEmpty(browserCaps)) { capabilities = getCapabilitiesForJson(browserCaps)[0]; } else { throw new IllegalStateException("Neither browser name nor capabilities are specified"); @@ -799,7 +795,7 @@ protected Capabilities getModifications(final Capabilities capabilities, final S * @return list of {@link Capabilities} objects */ public Capabilities[] getCapabilitiesForName(final String browserName) { - return getCapabilitiesForJson(String.format(CAPS_PATTERN, browserName)); + return getCapabilitiesForJson(String.format("{\"browserName\":\"%s\"}", browserName)); } /** diff --git a/src/main/java/com/nordstrom/automation/selenium/core/SeleniumGrid.java b/src/main/java/com/nordstrom/automation/selenium/core/SeleniumGrid.java index 2c2b6e37..d12cca91 100644 --- a/src/main/java/com/nordstrom/automation/selenium/core/SeleniumGrid.java +++ b/src/main/java/com/nordstrom/automation/selenium/core/SeleniumGrid.java @@ -36,13 +36,13 @@ import com.nordstrom.common.base.UncheckedThrow; /** - *

The {@code SeleniumGrid} Object

+ * The {@code SeleniumGrid} Object *

* The {@code SeleniumGrid} object provides an interface to * Selenium Grid collections - both local and remote. * A standard grid object is available through the configuration, and independent instances can be created as needed. - * - *

Using the standard {@code SeleniumGrid} object

+ *

+ * Using the standard {@code SeleniumGrid} object *

* By default, Selenium Foundation acquires its browser sessions from an instance of the * Selenium Grid. If no remote Grid instance is specified in diff --git a/src/main/java/com/nordstrom/automation/selenium/examples/ExamplePage.java b/src/main/java/com/nordstrom/automation/selenium/examples/ExamplePage.java index b7879aef..4859c8a1 100644 --- a/src/main/java/com/nordstrom/automation/selenium/examples/ExamplePage.java +++ b/src/main/java/com/nordstrom/automation/selenium/examples/ExamplePage.java @@ -16,6 +16,7 @@ import com.nordstrom.automation.selenium.SeleniumConfig; import com.nordstrom.automation.selenium.annotations.PageUrl; import com.nordstrom.automation.selenium.core.ByType; +import com.nordstrom.automation.selenium.core.JsUtility; import com.nordstrom.automation.selenium.model.Page; import com.nordstrom.automation.selenium.model.RobustWebElement; @@ -201,6 +202,10 @@ public boolean setInputValue(String value) { return updateValue(findElement(Using.INPUT), value); } + public boolean setInputValue(boolean value) { + return updateValue(findElement(Using.INPUT), value); + } + public String getInputValue() { return findElement(Using.INPUT).getAttribute("value"); } @@ -217,6 +222,14 @@ public boolean setCheckValue(boolean value) { return updateValue(findElement(Using.CHECK), value); } + public boolean setCheckValue(String value) { + return updateValue(findElement(Using.CHECK), value); + } + + public void resetForm() { + JsUtility.run(driver, "document.getElementById('form').reset()"); + } + public boolean hasCssOptional() { return findOptional(By.cssSelector(ByType.cssLocatorFor(Using.FORM))).hasReference(); } diff --git a/src/main/java/com/nordstrom/automation/selenium/model/ComponentContainer.java b/src/main/java/com/nordstrom/automation/selenium/model/ComponentContainer.java index 3065681f..fe38e495 100644 --- a/src/main/java/com/nordstrom/automation/selenium/model/ComponentContainer.java +++ b/src/main/java/com/nordstrom/automation/selenium/model/ComponentContainer.java @@ -432,10 +432,8 @@ public static boolean updateValue(final WebElement element, final String value) if ("checkbox".equals(element.getAttribute("type"))) { return updateValue(element, Boolean.parseBoolean(value)); } else if (!valueEquals(element, value)) { - if (value == null) { - element.clear(); - } else { - WebDriverUtils.getExecutor(element).executeScript("arguments[0].select();", element); + element.clear(); + if (value != null) { element.sendKeys(value); } return true; diff --git a/src/main/java/com/nordstrom/automation/selenium/platform/TargetTypeName.java b/src/main/java/com/nordstrom/automation/selenium/platform/TargetTypeName.java index 9f1631de..d53f1f5e 100644 --- a/src/main/java/com/nordstrom/automation/selenium/platform/TargetTypeName.java +++ b/src/main/java/com/nordstrom/automation/selenium/platform/TargetTypeName.java @@ -1,6 +1,6 @@ package com.nordstrom.automation.selenium.platform; -interface TargetTypeName extends PlatformEnum { +public interface TargetTypeName extends PlatformEnum { String SUPPORT_NAME = "support"; String WEB_APP_NAME = "web-app"; String ANDROID_NAME = "android"; diff --git a/src/main/resources/ExamplePage.html b/src/main/resources/ExamplePage.html index f6b2c7a6..c4b9d06c 100644 --- a/src/main/resources/ExamplePage.html +++ b/src/main/resources/ExamplePage.html @@ -45,6 +45,7 @@ var div_a = document.createElement('div'); div_a.id = 'form-div-a'; var form_a = document.createElement('form'); + form_a.id = 'form_a'; var label_1_a = document.createElement('label'); label_1_a.for = 'input-field-a'; label_1_a.textContent = '[A] Input: '; @@ -52,6 +53,7 @@ input_field_a.type = 'text'; input_field_a.id = 'input-field-a'; input_field_a.name = 'input-field-a'; + input_field_a.value = 'Poshmark'; var label_2_a = document.createElement('label'); label_2_a.for = 'checkbox-a'; label_2_a.textContent = '[A] Check: '; @@ -87,6 +89,7 @@ var div_b = document.createElement('div'); div_b.id = 'form-div-b'; var form_b = document.createElement('form'); + form_b.id = 'form_b'; var label_1_b = document.createElement('label'); label_1_b.for = 'input-field-b'; label_1_b.textContent = '[B] Input: '; @@ -94,6 +97,7 @@ input_field_b.type = 'text'; input_field_b.id = 'input-field-b'; input_field_b.name = 'input-field-b'; + input_field_b.value = 'RealReal'; var label_2_b = document.createElement('label'); label_2_b.for = 'checkbox-b'; label_2_b.textContent = '[B] Check: '; @@ -145,9 +149,9 @@

-
+ -
+

diff --git a/src/test/java/com/nordstrom/automation/selenium/SeleniumConfigTest.java b/src/test/java/com/nordstrom/automation/selenium/SeleniumConfigTest.java index 927c4da7..fa3ad4d0 100644 --- a/src/test/java/com/nordstrom/automation/selenium/SeleniumConfigTest.java +++ b/src/test/java/com/nordstrom/automation/selenium/SeleniumConfigTest.java @@ -5,11 +5,13 @@ import static org.testng.Assert.assertNotEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import static com.nordstrom.automation.selenium.platform.TargetTypeName.SUPPORT_NAME; import java.net.URI; import org.openqa.selenium.Capabilities; import org.openqa.selenium.SearchContext; +import org.testng.SkipException; import org.testng.annotations.Test; import com.nordstrom.automation.selenium.AbstractSeleniumConfig.SeleniumSettings; @@ -59,6 +61,11 @@ public void testTargetUri() { @Test public void testBrowserCaps() { SeleniumConfig config = SeleniumConfig.getConfig(); + String contextPlatform = config.getContextPlatform(); + if ((contextPlatform == null) || contextPlatform.equals(SUPPORT_NAME)) { + throw new SkipException("Current target platform doesn't provide browser capabilities"); + } + Capabilities browserCaps = config.getCurrentCapabilities(); assertNotNull(browserCaps.getBrowserName()); } diff --git a/src/test/java/com/nordstrom/automation/selenium/core/ModelTestCore.java b/src/test/java/com/nordstrom/automation/selenium/core/ModelTestCore.java index a51c2fd6..ab324dde 100644 --- a/src/test/java/com/nordstrom/automation/selenium/core/ModelTestCore.java +++ b/src/test/java/com/nordstrom/automation/selenium/core/ModelTestCore.java @@ -26,11 +26,53 @@ public static void testBasicPage(TestBase instance) { assertTrue(page instanceof Enhanced); } + public static void updateTextInputSameValue(TestBase instance) { + ExamplePage page = instance.getInitialPage(); + assertFalse(page.setInputValue("Nordstrom")); + } + + public static void updateTextInputNewValue(TestBase instance) { + ExamplePage page = instance.getInitialPage(); + assertTrue(page.setInputValue("HauteLook")); + } + + public static void updateTextInputBoolValue(TestBase instance) { + ExamplePage page = instance.getInitialPage(); + assertTrue(page.setInputValue(true)); + assertEquals("true", page.getInputValue()); + } + + public static void updateTextInputNullValue(TestBase instance) { + ExamplePage page = instance.getInitialPage(); + assertTrue(page.setInputValue(null)); + assertEquals("", page.getInputValue()); + } + + public static void updateCheckboxSameValue(TestBase instance) { + ExamplePage page = instance.getInitialPage(); + assertFalse(page.setCheckValue(false)); + } + + public static void updateCheckboxNewValue(TestBase instance) { + ExamplePage page = instance.getInitialPage(); + assertTrue(page.setCheckValue(true)); + } + + public static void updateCheckboxStringValue(TestBase instance) { + ExamplePage page = instance.getInitialPage(); + assertTrue(page.setCheckValue("true")); + } + + public static void updateCheckboxNullValue(TestBase instance) { + ExamplePage page = instance.getInitialPage(); + assertFalse(page.setCheckValue(null)); + } + public static void testParagraphs(TestBase instance) { ExamplePage page = instance.getInitialPage(); List paraList = page.getParagraphs(); assertEquals(paraList.size(), 3); - assertArrayEquals(paraList.toArray(), PARAS); + assertArrayEquals(PARAS, paraList.toArray()); } public static void testTable(TestBase instance) { @@ -45,40 +87,40 @@ public static void testTable(TestBase instance) { * @param component table component to be verified */ private static void verifyTable(TableComponent component) { - assertArrayEquals(component.getHeadings().toArray(), HEADINGS); + assertArrayEquals(HEADINGS, component.getHeadings().toArray()); List> content = component.getContent(); assertEquals(content.size(), 3); - assertArrayEquals(content.get(0).toArray(), CONTENT[0]); - assertArrayEquals(content.get(1).toArray(), CONTENT[1]); - assertArrayEquals(content.get(2).toArray(), CONTENT[2]); + assertArrayEquals(CONTENT[0], content.get(0).toArray()); + assertArrayEquals(CONTENT[1], content.get(1).toArray()); + assertArrayEquals(CONTENT[2], content.get(2).toArray()); assertTrue(component instanceof Enhanced); } public static void testFrameByLocator(TestBase instance) { ExamplePage page = instance.getInitialPage(); FrameComponent component = page.getFrameByLocator(); - assertEquals(component.getPageContent(), FRAME_A); + assertEquals(FRAME_A, component.getPageContent()); assertTrue(component instanceof Enhanced); } public static void testFrameByElement(TestBase instance) { ExamplePage page = instance.getInitialPage(); FrameComponent component = page.getFrameByElement(); - assertEquals(component.getPageContent(), FRAME_B); + assertEquals(FRAME_B, component.getPageContent()); assertTrue(component instanceof Enhanced); } public static void testFrameByIndex(TestBase instance) { ExamplePage page = instance.getInitialPage(); FrameComponent component = page.getFrameByIndex(); - assertEquals(component.getPageContent(), FRAME_C); + assertEquals(FRAME_C, component.getPageContent()); assertTrue(component instanceof Enhanced); } public static void testFrameById(TestBase instance) { ExamplePage page = instance.getInitialPage(); FrameComponent component = page.getFrameById(); - assertEquals(component.getPageContent(), FRAME_D); + assertEquals(FRAME_D, component.getPageContent()); assertTrue(component instanceof Enhanced); } @@ -97,28 +139,28 @@ public static void testComponentMap(TestBase instance) { public static void testFrameList(TestBase instance) { ExamplePage page = instance.getInitialPage(); List frameList = page.getFrameList(); - assertEquals(frameList.size(), 4); - assertEquals(frameList.get(0).getPageContent(), FRAME_A); + assertEquals(4, frameList.size()); + assertEquals(FRAME_A, frameList.get(0).getPageContent()); assertTrue(frameList.get(0) instanceof Enhanced); - assertEquals(frameList.get(1).getPageContent(), FRAME_B); + assertEquals(FRAME_B, frameList.get(1).getPageContent()); assertTrue(frameList.get(1) instanceof Enhanced); - assertEquals(frameList.get(2).getPageContent(), FRAME_C); + assertEquals(FRAME_C, frameList.get(2).getPageContent()); assertTrue(frameList.get(2) instanceof Enhanced); - assertEquals(frameList.get(3).getPageContent(), FRAME_D); + assertEquals(FRAME_D, frameList.get(3).getPageContent()); assertTrue(frameList.get(3) instanceof Enhanced); } public static void testFrameMap(TestBase instance) { ExamplePage page = instance.getInitialPage(); Map frameMap = page.getFrameMap(); - assertEquals(frameMap.size(), 4); - assertEquals(frameMap.get(FRAME_A).getPageContent(), FRAME_A); + assertEquals(4, frameMap.size()); + assertEquals(FRAME_A, frameMap.get(FRAME_A).getPageContent()); assertTrue(frameMap.get(FRAME_A) instanceof Enhanced); - assertEquals(frameMap.get(FRAME_B).getPageContent(), FRAME_B); + assertEquals(FRAME_B, frameMap.get(FRAME_B).getPageContent()); assertTrue(frameMap.get(FRAME_B) instanceof Enhanced); - assertEquals(frameMap.get(FRAME_C).getPageContent(), FRAME_C); + assertEquals(FRAME_C, frameMap.get(FRAME_C).getPageContent()); assertTrue(frameMap.get(FRAME_C) instanceof Enhanced); - assertEquals(frameMap.get(FRAME_D).getPageContent(), FRAME_D); + assertEquals(FRAME_D, frameMap.get(FRAME_D).getPageContent()); assertTrue(frameMap.get(FRAME_D) instanceof Enhanced); } @@ -129,7 +171,7 @@ public static Runnable testShadowRootByLocator(final TestBase instance) { @Override public void run() { ShadowRootComponent shadowRoot = page.getShadowRootByLocator(); - assertEquals(shadowRoot.getHeading(), SHADOW_DOM_A); + assertEquals(SHADOW_DOM_A, shadowRoot.getHeading()); assertTrue(shadowRoot instanceof Enhanced); } }; @@ -142,7 +184,7 @@ public static Runnable testShadowRootByElement(final TestBase instance) { @Override public void run() { ShadowRootComponent shadowRoot = page.getShadowRootByElement(); - assertEquals(shadowRoot.getHeading(), SHADOW_DOM_B); + assertEquals(SHADOW_DOM_B, shadowRoot.getHeading()); assertTrue(shadowRoot instanceof Enhanced); } }; @@ -156,9 +198,9 @@ public static Runnable testShadowRootList(final TestBase instance) { public void run() { List shadowRootList = page.getShadowRootList(); assertEquals(shadowRootList.size(), 2); - assertEquals(shadowRootList.get(0).getHeading(), SHADOW_DOM_A); + assertEquals(SHADOW_DOM_A, shadowRootList.get(0).getHeading()); assertTrue(shadowRootList.get(0) instanceof Enhanced); - assertEquals(shadowRootList.get(1).getHeading(), SHADOW_DOM_B); + assertEquals(SHADOW_DOM_B, shadowRootList.get(1).getHeading()); assertTrue(shadowRootList.get(1) instanceof Enhanced); } }; @@ -172,9 +214,9 @@ public static Runnable testShadowRootMap(final TestBase instance) { public void run() { Map shadowRootMap = page.getShadowRootMap(); assertEquals(shadowRootMap.size(), 2); - assertEquals(shadowRootMap.get(SHADOW_DOM_A).getHeading(), SHADOW_DOM_A); + assertEquals(SHADOW_DOM_A, shadowRootMap.get(SHADOW_DOM_A).getHeading()); assertTrue(shadowRootMap.get(SHADOW_DOM_A) instanceof Enhanced); - assertEquals(shadowRootMap.get(SHADOW_DOM_B).getHeading(), SHADOW_DOM_B); + assertEquals(SHADOW_DOM_B, shadowRootMap.get(SHADOW_DOM_B).getHeading()); assertTrue(shadowRootMap.get(SHADOW_DOM_B) instanceof Enhanced); } }; @@ -198,10 +240,10 @@ public static void testRefresh(TestBase instance) { int[] bodyRefreshCounts = component.getBodyRefreshCounts(); // verify no initial refresh requests - assertEquals(pageRefreshCount, 0); - assertEquals(tableRefreshCount, 0); - assertEquals(headRefreshCount, 0); - assertArrayEquals(bodyRefreshCounts, new int[] {0, 0, 0}); + assertEquals(0, pageRefreshCount); + assertEquals(0, tableRefreshCount); + assertEquals(0, headRefreshCount); + assertArrayEquals(new int[] {0, 0, 0}, bodyRefreshCounts); // refresh page to force DOM rebuild page.getWrappedDriver().navigate().refresh(); @@ -216,13 +258,13 @@ public static void testRefresh(TestBase instance) { bodyRefreshCounts = component.getBodyRefreshCounts(); // 1 page refresh request from its table context - assertEquals(pageRefreshCount, 1); + assertEquals(1, pageRefreshCount); // 1 table refresh request from each of its four row contexts - assertEquals(tableRefreshCount, 4); + assertEquals(4, tableRefreshCount); // 1 head row refresh request from one of its web element contexts - assertEquals(headRefreshCount, 1); + assertEquals(1, headRefreshCount); // 1 refresh request per body row from one of its web element contexts - assertArrayEquals(bodyRefreshCounts, new int[] {1, 1, 1}); + assertArrayEquals(new int[] {1, 1, 1}, bodyRefreshCounts); // verify table contents again // NOTE: No additional refresh requests are expected @@ -235,10 +277,10 @@ public static void testRefresh(TestBase instance) { bodyRefreshCounts = component.getBodyRefreshCounts(); // verify no additional refresh requests - assertEquals(pageRefreshCount, 1); - assertEquals(tableRefreshCount, 4); - assertEquals(headRefreshCount, 1); - assertArrayEquals(bodyRefreshCounts, new int[] {1, 1, 1}); + assertEquals(1, pageRefreshCount); + assertEquals(4, tableRefreshCount); + assertEquals(1, headRefreshCount); + assertArrayEquals(new int[] {1, 1, 1}, bodyRefreshCounts); } public static void testCssOptional(TestBase instance) { @@ -264,7 +306,7 @@ public static Runnable testShadowParagraphs(final TestBase instance) { public void run() { ShadowRootComponent shadowRoot = page.getShadowRootByLocator(); List paraList = shadowRoot.getParagraphs(); - assertEquals(paraList.size(), 3); + assertEquals(3, paraList.size()); String[] expect = new String[3]; String heading = shadowRoot.getHeading(); @@ -272,7 +314,7 @@ public void run() { for (int i = 0; i < 3; i++) { expect[i] = marker + PARAS[i]; } - assertArrayEquals(paraList.toArray(), expect); + assertArrayEquals(expect, paraList.toArray()); } }; } diff --git a/src/test/java/com/nordstrom/automation/selenium/junit/JUnitModelTest.java b/src/test/java/com/nordstrom/automation/selenium/junit/JUnitModelTest.java index 9c76c13b..e0e9f171 100644 --- a/src/test/java/com/nordstrom/automation/selenium/junit/JUnitModelTest.java +++ b/src/test/java/com/nordstrom/automation/selenium/junit/JUnitModelTest.java @@ -22,6 +22,62 @@ public void testBasicPage() { ModelTestCore.testBasicPage(this); } + @Test + @Ignore + @TargetPlatform(WEB_APP_NAME) + public void updateTextInputSameValue() { + ModelTestCore.updateTextInputSameValue(this); + } + + @Test + @Ignore + @TargetPlatform(WEB_APP_NAME) + public void updateTextInputNewValue() { + ModelTestCore.updateTextInputNewValue(this); + } + + @Test + @Ignore + @TargetPlatform(WEB_APP_NAME) + public void updateTextInputBoolValue() { + ModelTestCore.updateTextInputBoolValue(this); + } + + @Test + @Ignore + @TargetPlatform(WEB_APP_NAME) + public void updateTextInputNullValue() { + ModelTestCore.updateTextInputNullValue(this); + } + + @Test + @Ignore + @TargetPlatform(WEB_APP_NAME) + public void updateCheckboxSameValue() { + ModelTestCore.updateCheckboxSameValue(this); + } + + @Test + @Ignore + @TargetPlatform(WEB_APP_NAME) + public void updateCheckboxNewValue() { + ModelTestCore.updateCheckboxNewValue(this); + } + + @Test + @Ignore + @TargetPlatform(WEB_APP_NAME) + public void updateCheckboxStringValue() { + ModelTestCore.updateCheckboxStringValue(this); + } + + @Test + @Ignore + @TargetPlatform(WEB_APP_NAME) + public void updateCheckboxNullValue() { + ModelTestCore.updateCheckboxNullValue(this); + } + @Test @Ignore @TargetPlatform(WEB_APP_NAME) diff --git a/src/test/java/com/nordstrom/automation/selenium/model/ComponentContainerTest.java b/src/test/java/com/nordstrom/automation/selenium/model/ComponentContainerTest.java index fdd86d1a..3ea108d2 100644 --- a/src/test/java/com/nordstrom/automation/selenium/model/ComponentContainerTest.java +++ b/src/test/java/com/nordstrom/automation/selenium/model/ComponentContainerTest.java @@ -2,7 +2,6 @@ import static org.mockito.Mockito.*; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import java.io.File; @@ -16,60 +15,11 @@ import org.testng.annotations.Test; import com.nordstrom.automation.selenium.annotations.PageUrl; -import com.nordstrom.automation.selenium.interfaces.WrapsDriver; public class ComponentContainerTest { private static final URI targetUri = URI.create("http://target.com/basepath/"); - @Test - public void updateTextInputSameValue() { - WebElement elementWithValue = mockElement("input", "Nordstrom", false); - assertFalse(ComponentContainer.updateValue(elementWithValue, "Nordstrom")); - } - - @Test - public void updateTextInputNewValue() { - WebElement elementWithValue = mockElement("input", "Nordstrom", false); - assertTrue(ComponentContainer.updateValue(elementWithValue, "HauteLook")); - } - - @Test - public void updateTextInputBoolValue() { - WebElement elementWithValue = mockElement("input", "Nordstrom", false); - assertTrue(ComponentContainer.updateValue(elementWithValue, true)); - } - - @Test - public void updateTextInputNullValue() { - WebElement elementWithValue = mockElement("input", "Nordstrom", false); - assertTrue(ComponentContainer.updateValue(elementWithValue, null)); - } - - @Test - public void updateCheckboxSameValue() { - WebElement elementWithValue = mockElement("input", "false", true); - assertFalse(ComponentContainer.updateValue(elementWithValue, false)); - } - - @Test - public void updateCheckboxNewValue() { - WebElement elementWithValue = mockElement("input", "false", true); - assertTrue(ComponentContainer.updateValue(elementWithValue, true)); - } - - @Test - public void updateCheckboxStringValue() { - WebElement elementWithValue = mockElement("input", "false", true); - assertTrue(ComponentContainer.updateValue(elementWithValue, "true")); - } - - @Test - public void updateCheckboxNullValue() { - WebElement elementWithValue = mockElement("input", "false", true); - assertFalse(ComponentContainer.updateValue(elementWithValue, null)); - } - @Test(expectedExceptions = {NullPointerException.class}, expectedExceptionsMessageRegExp = "\\[element\\] must be non-null") public void updateElementNullWithString() { @@ -155,32 +105,6 @@ public void verifyLandingPage() { ComponentContainer.verifyLandingPage(page, PageUrlExample.class, pageUrl, targetUri); } - /** - * Create mocked {@link WebElement} object. - * - * @param type element type - * @param value element value - * @param isCheckbox 'true' is checkbox is desired; otherwise 'false' - * @return mocked WebElement object - */ - private static WebElement mockElement(String type, String value, boolean isCheckbox) { - WebElement element = mock(WebElement.class, withSettings().extraInterfaces(WrapsDriver.TYPE)); - when(element.getTagName()).thenReturn(type); - if (isCheckbox) { - when(element.getAttribute("type")).thenReturn("checkbox"); - when(element.getAttribute("value")).thenReturn("isSelected: " + value); - when(element.isSelected()).thenReturn(Boolean.parseBoolean(value)); - } else { - when(element.getAttribute("type")).thenReturn("text"); - when(element.getAttribute("value")).thenReturn(value); - when(element.isSelected()).thenReturn(false); - } - - WebDriver driver = mockDriver(); - when(WrapsDriver.getWrappedDriver.apply(element)).thenReturn(driver); - return element; - } - /** * Create mocked {@link WebDriver} object. * diff --git a/src/test/java/com/nordstrom/automation/selenium/model/ModelTest.java b/src/test/java/com/nordstrom/automation/selenium/model/ModelTest.java index 84c31e92..370772b0 100644 --- a/src/test/java/com/nordstrom/automation/selenium/model/ModelTest.java +++ b/src/test/java/com/nordstrom/automation/selenium/model/ModelTest.java @@ -1,9 +1,8 @@ package com.nordstrom.automation.selenium.model; -import static com.nordstrom.automation.selenium.platform.TargetType.WEB_APP_NAME; - import org.testng.SkipException; import org.testng.annotations.Test; +import static com.nordstrom.automation.selenium.platform.TargetType.WEB_APP_NAME; import com.nordstrom.automation.selenium.annotations.InitialPage; import com.nordstrom.automation.selenium.core.ModelTestCore; @@ -21,6 +20,54 @@ public void testBasicPage() { ModelTestCore.testBasicPage(this); } + @Test + @TargetPlatform(WEB_APP_NAME) + public void updateTextInputSameValue() { + ModelTestCore.updateTextInputSameValue(this); + } + + @Test + @TargetPlatform(WEB_APP_NAME) + public void updateTextInputNewValue() { + ModelTestCore.updateTextInputNewValue(this); + } + + @Test + @TargetPlatform(WEB_APP_NAME) + public void updateTextInputBoolValue() { + ModelTestCore.updateTextInputBoolValue(this); + } + + @Test + @TargetPlatform(WEB_APP_NAME) + public void updateTextInputNullValue() { + ModelTestCore.updateTextInputNullValue(this); + } + + @Test + @TargetPlatform(WEB_APP_NAME) + public void updateCheckboxSameValue() { + ModelTestCore.updateCheckboxSameValue(this); + } + + @Test + @TargetPlatform(WEB_APP_NAME) + public void updateCheckboxNewValue() { + ModelTestCore.updateCheckboxNewValue(this); + } + + @Test + @TargetPlatform(WEB_APP_NAME) + public void updateCheckboxStringValue() { + ModelTestCore.updateCheckboxStringValue(this); + } + + @Test + @TargetPlatform(WEB_APP_NAME) + public void updateCheckboxNullValue() { + ModelTestCore.updateCheckboxNullValue(this); + } + @Test @TargetPlatform(WEB_APP_NAME) public void testParagraphs() { diff --git a/uiautomator2Deps.gradle b/uiautomator2Deps.gradle new file mode 100644 index 00000000..c71c8a7d --- /dev/null +++ b/uiautomator2Deps.gradle @@ -0,0 +1,12 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.UiAutomator2Plugin' + File.pathSeparator) +System.setProperty('selenium.browser.caps', '{"platformName":"Android","appium:automationName":"UiAutomator2","appium:app":"https://github.com/appium/appium/raw/master/packages/appium/sample-code/apps/ApiDemos-debug.apk"}') +System.setProperty('selenium.context.platform', 'android') +System.setProperty('selenium.grid.examples', 'false') +System.setProperty('appium.with.pm2', 'true') +dependencies { + testImplementation('io.appium:java-client') { + exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' + exclude group: 'org.seleniumhq.selenium', module: 'selenium-support' + } +} diff --git a/windowsDeps.gradle b/windowsDeps.gradle new file mode 100644 index 00000000..180dbb81 --- /dev/null +++ b/windowsDeps.gradle @@ -0,0 +1,12 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.WindowsPlugin' + File.pathSeparator) +System.setProperty('selenium.browser.caps', '{"platformName":"Windows","appium:automationName":"Windows","appium:app":"C:/Windows/system32/notepad.exe"}') +System.setProperty('selenium.context.platform', 'windows') +System.setProperty('selenium.grid.examples', 'false') +System.setProperty('appium.with.pm2', 'true') +dependencies { + testImplementation('io.appium:java-client') { + exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' + exclude group: 'org.seleniumhq.selenium', module: 'selenium-support' + } +} diff --git a/xcuitestDeps.gradle b/xcuitestDeps.gradle new file mode 100644 index 00000000..94d476f8 --- /dev/null +++ b/xcuitestDeps.gradle @@ -0,0 +1,12 @@ +def driverPlugins = System.getProperty('selenium.grid.plugins', '') +System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.XCUITestPlugin' + File.pathSeparator) +System.setProperty('selenium.browser.caps', '{"platformName":"iOS","appium:automationName":"XCUITest","appium:app":"https://github.com/appium/appium/raw/master/packages/appium/sample-code/apps/TestApp.app.zip"}') +System.setProperty('selenium.context.platform', 'ios-app') +System.setProperty('selenium.grid.examples', 'false') +System.setProperty('appium.with.pm2', 'true') +dependencies { + testImplementation('io.appium:java-client') { + exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' + exclude group: 'org.seleniumhq.selenium', module: 'selenium-support' + } +}