From 8d69c49e0fda3699855b9285cd2d1539eaba18d1 Mon Sep 17 00:00:00 2001 From: Scott Babcock Date: Tue, 2 Dec 2025 00:02:44 -0800 Subject: [PATCH] Fix test config override; add Edge presonality --- build.gradle | 48 ++++++++++--------- chromeDeps.gradle | 6 +-- edgeDeps.gradle | 6 +-- espressoDeps.gradle | 9 ++-- firefoxDeps.gradle | 6 +-- htmlunitDeps.gradle | 6 +-- mac2Deps.gradle | 10 ++-- operaDeps.gradle | 6 +-- phantomjsDeps.gradle | 6 +-- safariDeps.gradle | 6 +-- selenium4Deps.gradle | 4 +- .../selenium/AbstractSeleniumConfig.java | 5 ++ .../selenium/plugins/HtmlUnitCaps.java | 12 +++-- uiautomator2Deps.gradle | 7 ++- windowsDeps.gradle | 8 ++-- xcuitestDeps.gradle | 7 ++- 16 files changed, 81 insertions(+), 71 deletions(-) diff --git a/build.gradle b/build.gradle index 2cf922a1..a064c262 100644 --- a/build.gradle +++ b/build.gradle @@ -31,8 +31,15 @@ if (project.hasProperty('browsers')) { } } +// if "personality" is specified if (project.hasProperty('personality')) { - System.setProperty('selenium.browser.name', ext.personality) + // store "injected" browser name setting + System.setProperty('injected.selenium.browser.name', ext.personality) + // if target is a mobile browser + if ([".chrome", ".safari"].any { ext.personality.endsWith(it) }) { + // specify "web-app" as the injected default context platform + System.setProperty('injected.selenium.context.platform', 'web-app') + } } def archiveVer = null @@ -123,30 +130,33 @@ javadocJar { destinationDirectory = libsDir } +tasks.withType(Test).configureEach { + // iterate over system properties + System.getProperties().each { key, val -> + // if this is a property that should be propagated to the test task + if (key.endsWith('.binary.path') || ['injected.', 'selenium.', 'appium.', 'testng.', 'junit.'].any { key.startsWith(it) }) { + // if running on Windows and this property defines JSON browser capabilities + if (OperatingSystem.current().isWindows() && key.endsWith('selenium.browser.caps')) { + // escape double quotes + val = val.replace('"', '\\\\"') + } + // propagate property + systemProperty key, val + } + } +} + + 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 { @@ -259,11 +269,3 @@ test { "-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 index 14a2d974..b7c4193b 100644 --- a/chromeDeps.gradle +++ b/chromeDeps.gradle @@ -1,7 +1,7 @@ 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') +System.setProperty('injected.selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.ChromePlugin' + File.pathSeparator) +System.setProperty('injected.selenium.browser.name', 'chrome') +System.setProperty('injected.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 index 9bb6df3b..86d1064c 100644 --- a/edgeDeps.gradle +++ b/edgeDeps.gradle @@ -1,7 +1,7 @@ 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') +System.setProperty('injected.selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.EdgePlugin' + File.pathSeparator) +System.setProperty('injected.selenium.browser.name', 'MicrosoftEdge') +System.setProperty('injected.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 index 1562b51e..93320654 100644 --- a/espressoDeps.gradle +++ b/espressoDeps.gradle @@ -1,9 +1,8 @@ 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') +System.setProperty('injected.selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.EspressoPlugin' + File.pathSeparator) +System.setProperty('injected.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('injected.selenium.context.platform', 'android') +System.setProperty('injected.selenium.grid.examples', 'false') dependencies { api('io.appium:java-client') { exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' diff --git a/firefoxDeps.gradle b/firefoxDeps.gradle index 2b75920d..c9ab7fdb 100644 --- a/firefoxDeps.gradle +++ b/firefoxDeps.gradle @@ -1,7 +1,7 @@ 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') +System.setProperty('injected.selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.FirefoxPlugin' + File.pathSeparator) +System.setProperty('injected.selenium.browser.name', 'firefox') +System.setProperty('injected.selenium.context.platform', 'web-app') dependencies { testImplementation('org.seleniumhq.selenium:selenium-firefox-driver') { exclude module: 'selenium-remote-driver' diff --git a/htmlunitDeps.gradle b/htmlunitDeps.gradle index 9e422ed3..e14385d3 100644 --- a/htmlunitDeps.gradle +++ b/htmlunitDeps.gradle @@ -1,7 +1,7 @@ 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') +System.setProperty('injected.selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.HtmlUnitPlugin' + File.pathSeparator) +System.setProperty('injected.selenium.browser.name', 'htmlunit') +System.setProperty('injected.selenium.context.platform', 'web-app') dependencies { if ("${profile}" == "selenium4") { testImplementation 'com.nordstrom.ui-tools:htmlunit-remote' diff --git a/mac2Deps.gradle b/mac2Deps.gradle index 4eb9c8ef..72950a71 100644 --- a/mac2Deps.gradle +++ b/mac2Deps.gradle @@ -1,9 +1,9 @@ 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') +System.setProperty('injected.selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.Mac2Plugin' + File.pathSeparator) +System.setProperty('injected.selenium.browser.caps', '{"platformName":"Mac","appium:automationName":"Mac2","appium:bundleId":"com.apple.TextEdit"}') +System.setProperty('injected.selenium.context.platform', 'mac-app') +System.setProperty('injected.selenium.grid.examples', 'false') +System.setProperty('injected.appium.with.pm2', 'true') dependencies { api('io.appium:java-client') { exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' diff --git a/operaDeps.gradle b/operaDeps.gradle index fc2bf4c3..d91b5e61 100644 --- a/operaDeps.gradle +++ b/operaDeps.gradle @@ -1,7 +1,7 @@ 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') +System.setProperty('injected.selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.OperaPlugin' + File.pathSeparator) +System.setProperty('injected.selenium.browser.name', 'opera') +System.setProperty('injected.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 index 6f3adac2..c5c60482 100644 --- a/phantomjsDeps.gradle +++ b/phantomjsDeps.gradle @@ -1,7 +1,7 @@ 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') +System.setProperty('injected.selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.PhantomJsPlugin' + File.pathSeparator) +System.setProperty('injected.selenium.browser.name', 'phantomjs') +System.setProperty('injected.selenium.context.platform', 'web-app') dependencies { testImplementation('com.codeborne:phantomjsdriver') { exclude group: 'org.seleniumhq.selenium', module: 'selenium-remote-driver' diff --git a/safariDeps.gradle b/safariDeps.gradle index b05c06cd..28ba7dd2 100644 --- a/safariDeps.gradle +++ b/safariDeps.gradle @@ -1,7 +1,7 @@ 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') +System.setProperty('injected.selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.SafariPlugin' + File.pathSeparator) +System.setProperty('injected.selenium.browser.name', 'safari') +System.setProperty('injected.selenium.context.platform', 'web-app') dependencies { testImplementation('org.seleniumhq.selenium:selenium-safari-driver') { exclude module: 'selenium-remote-driver' diff --git a/selenium4Deps.gradle b/selenium4Deps.gradle index 833e819b..fcb2fdce 100644 --- a/selenium4Deps.gradle +++ b/selenium4Deps.gradle @@ -32,8 +32,8 @@ dependencies { api 'org.seleniumhq.selenium:selenium-firefox-driver:4.38.0' api 'org.seleniumhq.selenium:selenium-opera-driver:4.4.0' api 'org.seleniumhq.selenium:selenium-safari-driver:4.38.0' - api 'com.nordstrom.ui-tools:htmlunit-remote:4.38.0' - api 'org.seleniumhq.selenium:htmlunit3-driver:4.38.0' + api 'com.nordstrom.ui-tools:htmlunit-remote:4.39.0-SNAPSHOT' + api 'org.seleniumhq.selenium:htmlunit3-driver:4.39.0-SNAPSHOT' api 'org.htmlunit:htmlunit:4.18.0' api 'com.codeborne:phantomjsdriver:1.5.0' api 'org.apache.httpcomponents:httpclient:4.5.14' diff --git a/src/main/java/com/nordstrom/automation/selenium/AbstractSeleniumConfig.java b/src/main/java/com/nordstrom/automation/selenium/AbstractSeleniumConfig.java index 828566da..c9702b28 100644 --- a/src/main/java/com/nordstrom/automation/selenium/AbstractSeleniumConfig.java +++ b/src/main/java/com/nordstrom/automation/selenium/AbstractSeleniumConfig.java @@ -563,6 +563,11 @@ protected Map getDefaults() { defaults.put(SeleniumSettings.NODE_BINARY_PATH.key(), nodePath); } + // propagate "injected" settings, which take precedence over default values + System.getProperties().entrySet().stream() + .filter(e -> e.getKey().toString().startsWith("injected.")) + .collect(Collectors.toMap(e -> e.getKey().toString().substring(9), e -> e.getValue())); + return defaults; } diff --git a/src/main/java/com/nordstrom/automation/selenium/plugins/HtmlUnitCaps.java b/src/main/java/com/nordstrom/automation/selenium/plugins/HtmlUnitCaps.java index e290ca6d..ffc61d6e 100644 --- a/src/main/java/com/nordstrom/automation/selenium/plugins/HtmlUnitCaps.java +++ b/src/main/java/com/nordstrom/automation/selenium/plugins/HtmlUnitCaps.java @@ -30,17 +30,22 @@ private HtmlUnitCaps() { "\"pluginClass\":\"com.nordstrom.automation.selenium.plugins.HtmlUnitPlugin\"}}"; private static final String CHROME = - "{\"browserName\":\"htmlunit\",\"browserVersion\":\"chrome\"," + + "{\"browserName\":\"htmlunit\",\"garg:browserVersion\":\"chrome\"," + "\"nord:options\":{\"personality\":\"htmlunit.chrome\"," + "\"pluginClass\":\"com.nordstrom.automation.selenium.plugins.HtmlUnitPlugin\"}}"; + private static final String EDGE = + "{\"browserName\":\"htmlunit\",\"garg:browserVersion\":\"edge\"," + + "\"nord:options\":{\"personality\":\"htmlunit.edge\"," + + "\"pluginClass\":\"com.nordstrom.automation.selenium.plugins.HtmlUnitPlugin\"}}"; + private static final String FIREFOX = - "{\"browserName\":\"htmlunit\",\"browserVersion\":\"firefox\"," + + "{\"browserName\":\"htmlunit\",\"garg:browserVersion\":\"firefox\"," + "\"nord:options\":{\"personality\":\"htmlunit.firefox\"," + "\"pluginClass\":\"com.nordstrom.automation.selenium.plugins.HtmlUnitPlugin\"}}"; private static final String INT_EXP = - "{\"browserName\":\"htmlunit\",\"browserVersion\":\"ie\"," + + "{\"browserName\":\"htmlunit\",\"garg:browserVersion\":\"ie\"," + "\"nord:options\":{\"personality\":\"htmlunit.ie\"," + "\"pluginClass\":\"com.nordstrom.automation.selenium.plugins.HtmlUnitPlugin\"}}"; @@ -55,6 +60,7 @@ private HtmlUnitCaps() { Map personalities = new HashMap<>(); personalities.put(DRIVER_NAME, BASELINE); personalities.put(DRIVER_NAME + ".chrome", CHROME); + personalities.put(DRIVER_NAME + ".edge", EDGE); personalities.put(DRIVER_NAME + ".firefox", FIREFOX); personalities.put(DRIVER_NAME + ".ie", INT_EXP); personalities.put(DRIVER_NAME + ".nojs", NO_JS); diff --git a/uiautomator2Deps.gradle b/uiautomator2Deps.gradle index 5813eb77..8b7fb327 100644 --- a/uiautomator2Deps.gradle +++ b/uiautomator2Deps.gradle @@ -1,9 +1,8 @@ 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') +System.setProperty('injected.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('injected.selenium.context.platform', 'android') +System.setProperty('injected.selenium.grid.examples', 'false') dependencies { api('io.appium:java-client') { exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' diff --git a/windowsDeps.gradle b/windowsDeps.gradle index 593a9016..4b7cbf45 100644 --- a/windowsDeps.gradle +++ b/windowsDeps.gradle @@ -1,9 +1,9 @@ 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') +System.setProperty('injected.selenium.browser.caps', '{"platformName":"Windows","appium:automationName":"Windows","appium:app":"C:/Windows/system32/notepad.exe"}') +System.setProperty('injected.selenium.context.platform', 'windows') +System.setProperty('injected.selenium.grid.examples', 'false') +System.setProperty('injected.appium.with.pm2', 'true') dependencies { api('io.appium:java-client') { exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' diff --git a/xcuitestDeps.gradle b/xcuitestDeps.gradle index 3c0d5f97..68301599 100644 --- a/xcuitestDeps.gradle +++ b/xcuitestDeps.gradle @@ -1,9 +1,8 @@ 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') +System.setProperty('injected.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('injected.selenium.context.platform', 'ios-app') +System.setProperty('injected.selenium.grid.examples', 'false') dependencies { api('io.appium:java-client') { exclude group: 'org.seleniumhq.selenium', module: 'selenium-java'