Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ private static Map<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<TimelineDto>, Serializable {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down