From f69b180f43308af979fffdbea42ad4dc08646ff7 Mon Sep 17 00:00:00 2001 From: rconner46 Date: Thu, 31 Jul 2025 10:36:31 -0500 Subject: [PATCH] Update app autodetection checks to look for appium:app property --- .../plugins/ApplauseFrameworkPlugin.java | 11 +++++-- .../selenium/EnhancedCapabilities.java | 7 +++++ .../auto/helpers/AutoBuildHelper.java | 28 +++++------------ .../auto/helpers/AutoBuildHelperTest.java | 31 ------------------- .../FrameworkConfigurationListener.java | 7 ++++- 5 files changed, 29 insertions(+), 55 deletions(-) diff --git a/auto-sdk-java-cucumber/src/main/java/com/applause/auto/cucumber/plugins/ApplauseFrameworkPlugin.java b/auto-sdk-java-cucumber/src/main/java/com/applause/auto/cucumber/plugins/ApplauseFrameworkPlugin.java index f048d9f..c1a5f77 100644 --- a/auto-sdk-java-cucumber/src/main/java/com/applause/auto/cucumber/plugins/ApplauseFrameworkPlugin.java +++ b/auto-sdk-java-cucumber/src/main/java/com/applause/auto/cucumber/plugins/ApplauseFrameworkPlugin.java @@ -40,6 +40,7 @@ import com.applause.auto.logging.LogOutputSingleton; import com.applause.auto.logging.ResultPropertyMap; import com.applause.auto.templates.TemplateManager; +import com.google.api.client.util.Strings; import com.google.common.collect.Sets; import io.cucumber.plugin.ConcurrentEventListener; import io.cucumber.plugin.event.EventPublisher; @@ -147,14 +148,20 @@ private void performDriverChecks() throws BadJsonFormatException { return; } - // For every driver that we are aware of at this time, check to see if we might need an app for + // For every driver that we are aware of at this time, check to see if we might + // need an app for // any of them for (var driver : expectedDrivers) { final var expectedDriverCaps = ContextManager.INSTANCE.lookupDriver(driver).evaluate(); if (!expectedDriverCaps.getApplauseOptions().isMobileNative()) { continue; } - if (!expectedDriverCaps.getCapabilityNames().contains("app")) { + + // If the app is not specified in the capabilities or in the environment + // configuration, + // we need to auto-detect the build and perform the app push if necessary + if (Strings.isNullOrEmpty(expectedDriverCaps.getApp()) + && Strings.isNullOrEmpty(EnvironmentConfigurationManager.INSTANCE.get().app())) { ApplauseAppPushHelper.autoDetectBuildIfNecessary(); ApplauseAppPushHelper.performApplicationPushIfNecessary(); } diff --git a/auto-sdk-java-framework/src/main/java/com/applause/auto/framework/selenium/EnhancedCapabilities.java b/auto-sdk-java-framework/src/main/java/com/applause/auto/framework/selenium/EnhancedCapabilities.java index e319d7a..09e97d1 100644 --- a/auto-sdk-java-framework/src/main/java/com/applause/auto/framework/selenium/EnhancedCapabilities.java +++ b/auto-sdk-java-framework/src/main/java/com/applause/auto/framework/selenium/EnhancedCapabilities.java @@ -140,6 +140,13 @@ private static Map asMapDeep(@NonNull final Capabilities caps) { AbstractMap.SimpleImmutableEntry::getValue)); } + public String getApp() { + return Optional.ofNullable(resolvedCaps) + .map(caps -> caps.getCapability("appium:app")) + .map(Object::toString) + .orElse(null); + } + @Override public Object getCapability(final @NonNull String capabilityName) { return resolvedCaps.getCapability(capabilityName); diff --git a/auto-sdk-java-integrations/src/main/java/com/applause/auto/helpers/AutoBuildHelper.java b/auto-sdk-java-integrations/src/main/java/com/applause/auto/helpers/AutoBuildHelper.java index 2808c97..78b63a3 100644 --- a/auto-sdk-java-integrations/src/main/java/com/applause/auto/helpers/AutoBuildHelper.java +++ b/auto-sdk-java-integrations/src/main/java/com/applause/auto/helpers/AutoBuildHelper.java @@ -39,7 +39,6 @@ import java.util.Comparator; import java.util.List; import java.util.Optional; -import javax.annotation.Nullable; import lombok.AccessLevel; import lombok.NonNull; import lombok.Setter; @@ -118,8 +117,13 @@ public static AttachmentWithHashesDto getLatestBuild(final @NonNull ApplausePubl * @param appCaps : The Applause Capabilities */ public static void autoDetectAppBuilds(final @NonNull EnhancedCapabilities appCaps) { - final String definedApp = getApp(appCaps); - // if app already specified, do nothing + // First, attempt to pull the app from the capabilities + // If it is not defined there, we can check the EnvironmentConfiguration + final String definedApp = + Optional.ofNullable(appCaps.getApp()) + .orElseGet(EnvironmentConfigurationManager.INSTANCE.get()::app); + + // if app already specified, we do not need to auto-detect the app if (!Strings.isNullOrEmpty(definedApp)) { return; } @@ -322,24 +326,6 @@ public int compare( } } - // Separating this out - it will likely need to change later - - /** - * Identify the best value for the "app" parameter from an (optional) capabilities file and a - * configuration - * - * @param appCaps A possible capabilities file (could be null) - * @return The best app file we can find. Null if a value can't be determined - */ - public static String getApp(final @Nullable EnhancedCapabilities appCaps) { - // if using the ExtendedCapabilities, get app from there or else retrieve using the config - // property - return Optional.ofNullable(appCaps) - .map(caps -> caps.getCapability("app")) - .map(Object::toString) - .orElseGet(EnvironmentConfigurationManager.INSTANCE.get()::app); - } - static class TimelineComparator implements Comparator, Serializable { @Override diff --git a/auto-sdk-java-integrations/src/test/java/com/applause/auto/helpers/AutoBuildHelperTest.java b/auto-sdk-java-integrations/src/test/java/com/applause/auto/helpers/AutoBuildHelperTest.java index cc217e6..fadaefa 100644 --- a/auto-sdk-java-integrations/src/test/java/com/applause/auto/helpers/AutoBuildHelperTest.java +++ b/auto-sdk-java-integrations/src/test/java/com/applause/auto/helpers/AutoBuildHelperTest.java @@ -24,8 +24,6 @@ import static org.mockito.Mockito.when; import com.applause.auto.config.ApplauseEnvironmentConfigurationManager; -import com.applause.auto.config.EnvironmentConfigurationManager; -import com.applause.auto.framework.selenium.EnhancedCapabilities; import com.applause.auto.util.applausepublicapi.ApplausePublicApi; import com.applause.auto.util.applausepublicapi.api.BuildApi; import com.applause.auto.util.applausepublicapi.dto.AttachmentWithHashesDto; @@ -40,35 +38,6 @@ public class AutoBuildHelperTest { - @Test - public void testGetApp() { - // test null input with no EnvironmentConfig - Object actualValue = AutoBuildHelper.getApp(null); - Assert.assertNull(actualValue, "null appCaps, return null from Bean"); - - // test non-null input with no EnvironmentConfig.override - EnhancedCapabilities caps = mock(EnhancedCapabilities.class); - when(caps.getCapability("app")).thenReturn("app-from-cfg1"); - Assert.assertEquals( - "app-from-cfg1", - AutoBuildHelper.getApp(caps), - "with appCaps, return 'app-from-cfg1' from Bean"); - - // test null input with EnvironmentConfig.override - EnvironmentConfigurationManager.INSTANCE.override(Map.of("app", "app-from-cfg2")); - actualValue = AutoBuildHelper.getApp(null); - Assert.assertEquals( - "app-from-cfg2", actualValue, "null appCaps, return 'app-from-cfg2' from Bean"); - - // Finally, ensure we prioritize input over EnvironmentConfig.override - when(caps.getCapability("app")).thenReturn("preferred-app"); - EnvironmentConfigurationManager.INSTANCE.override(Map.of("app", "app-from-cfg3")); - Assert.assertEquals( - "preferred-app", - AutoBuildHelper.getApp(caps), - "with appCaps, return 'preferred-app' from Bean"); - } - @Test public void testGetAllBuilds() { // Mock the response from the public API client diff --git a/auto-sdk-java-testng/src/main/java/com/applause/auto/testng/listeners/FrameworkConfigurationListener.java b/auto-sdk-java-testng/src/main/java/com/applause/auto/testng/listeners/FrameworkConfigurationListener.java index b7631c6..c246fb1 100644 --- a/auto-sdk-java-testng/src/main/java/com/applause/auto/testng/listeners/FrameworkConfigurationListener.java +++ b/auto-sdk-java-testng/src/main/java/com/applause/auto/testng/listeners/FrameworkConfigurationListener.java @@ -30,6 +30,7 @@ import com.applause.auto.logging.ResultPropertyMap; import com.applause.auto.templates.TemplateManager; import com.applause.auto.testng.TestNgContextUtils; +import com.google.api.client.util.Strings; import com.google.common.collect.Sets; import java.net.MalformedURLException; import java.net.URISyntaxException; @@ -151,7 +152,11 @@ private void performDriverChecks(final ISuite suite) throws BadJsonFormatExcepti if (!expectedDriverCaps.getApplauseOptions().isMobileNative()) { continue; } - if (!expectedDriverCaps.getCapabilityNames().contains("app")) { + + // If the app is not specified in the capabilities or in the environment configuration, + // we need to auto-detect the build and perform the app push if necessary + if (Strings.isNullOrEmpty(expectedDriverCaps.getApp()) + && Strings.isNullOrEmpty(EnvironmentConfigurationManager.INSTANCE.get().app())) { ApplauseAppPushHelper.autoDetectBuildIfNecessary(); ApplauseAppPushHelper.performApplicationPushIfNecessary(); break;