Skip to content

Commit

Permalink
Added perfecto driver capability
Browse files Browse the repository at this point in the history
  • Loading branch information
KrishnB committed Nov 7, 2021
1 parent d4cbe64 commit d6307ad
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ publishing {
customizePom(pom)
groupId 'com.testvagrant.ekam'
artifactId 'ekam'
version '1.0.0'
version '1.0.1-perfecto'

from components.java

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public class Hub {
public static final String BROWSERSTACK = "browserstack";
public static final String KOBITON = "kobiton";
public static final String SAUCE_LABS = "saucelabs";
public static final String PERFECTO = "perfecto";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import com.testvagrant.ekam.devicemanager.models.TargetDetails;
import com.testvagrant.ekam.devicemanager.remote.pcloudy.PCloudyDeviceManagerProvider;

import static com.testvagrant.ekam.commons.remote.constants.Hub.P_CLOUDY;
import static com.testvagrant.ekam.commons.remote.constants.Hub.QUALITY_KIOSK;
import static com.testvagrant.ekam.commons.remote.constants.Hub.*;
import static com.testvagrant.ekam.logger.EkamLogger.ekamLogger;

public class DeviceCacheDisposeFactory {
Expand All @@ -35,11 +34,13 @@ private static void releaseRemoteDevice(
cloudConfig.getApiHost(), cloudConfig.getUsername(), cloudConfig.getAccessKey())
.releaseDevice(targetDetails);
break;
default:
case BROWSERSTACK:
BrowserStackDeviceManagerProvider.deviceManager(
cloudConfig.getUsername(), cloudConfig.getAccessKey())
.releaseDevice(targetDetails);
break;
default:
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private MobileDriverDetails createRemoteDriver(MobileConfigParser mobileConfigPa

return MobileDriverDetails.builder()
.driver(driver)
.targetDetails(targetDetails)
.targetDetails(targetDetails) // TODO: Create Target Details from driver object
.capabilities(desiredCapabilities)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.testvagrant.ekam.mobile.remote;

import com.testvagrant.ekam.commons.remote.ConfigLoader;
import com.testvagrant.ekam.commons.remote.RemoteUrlBuilder;
import com.testvagrant.ekam.commons.remote.models.CloudConfig;
import com.testvagrant.ekam.devicemanager.devicefinder.BrowserStackDeviceFinder;
import com.testvagrant.ekam.devicemanager.models.DeviceType;
import com.testvagrant.ekam.devicemanager.models.EkamSupportedPlatforms;
import com.testvagrant.ekam.devicemanager.models.TargetDetails;
import com.testvagrant.ekam.devicemanager.remote.CapabilityMapper;
import com.testvagrant.ekam.mobile.configparser.MobileConfigParser;
import io.appium.java_client.remote.MobileCapabilityType;
import org.apache.commons.lang3.tuple.Triple;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

import static com.testvagrant.ekam.logger.EkamLogger.ekamLogger;

public class PerfectoDriver {

private final DesiredCapabilities desiredCapabilities;
private final CloudConfig cloudConfig;
private final MobileConfigParser mobileConfigParser;

public PerfectoDriver(MobileConfigParser mobileConfigParser) {
this.mobileConfigParser = mobileConfigParser;
this.cloudConfig = new ConfigLoader().loadConfig("perfecto");
this.desiredCapabilities = mobileConfigParser.getDesiredCapabilities();
}

public Triple<URL, DesiredCapabilities, TargetDetails> buildRemoteMobileConfig() {
URL url = RemoteUrlBuilder.build(cloudConfig);
Map<String, Object> browserStackCaps = mapToPerfectoDesiredCaps();
DesiredCapabilities updatedCapabilities =
desiredCapabilities.merge(new DesiredCapabilities(browserStackCaps));
ekamLogger().info("Building remote capabilities {}", updatedCapabilities);
return Triple.of(url, updatedCapabilities, findTarget());
}

private String uploadApp() {
if (!mobileConfigParser.getMobileConfig().isRemote()) return "";
String app =
(String)
mobileConfigParser.getDesiredCapabilities().getCapability(MobileCapabilityType.APP);
boolean isAppPresent = !Objects.isNull(app) && !app.isEmpty();
if (!mobileConfigParser.getMobileConfig().isUploadApp() || !isAppPresent) return "";
return RemoteDriverUploadFactory.uploadUrl(mobileConfigParser.getMobileConfig().getHub(), app);
}

private TargetDetails findTarget() {
return TargetDetails.builder()
.name("Perfecto Device")
.platform(EkamSupportedPlatforms.ANDROID)
.runsOn(DeviceType.DEVICE)
.udid(UUID.randomUUID().toString())
.platformVersion("8.0")
.build();
}

private Map<String, Object> mapToPerfectoDesiredCaps() {
Map<String, Object> capsMap = new HashMap<>();
capsMap.put("securityToken", cloudConfig.getAccessKey());
return capsMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static Triple<URL, DesiredCapabilities, TargetDetails> remoteMobileDriver
return new PCloudyDriver(mobileConfigParser).buildRemoteMobileConfig();
case QUALITY_KIOSK:
return new QualityKioskDriver(mobileConfigParser).buildRemoteMobileConfig();
case PERFECTO:
return new PerfectoDriver(mobileConfigParser).buildRemoteMobileConfig();
case KOBITON:
case SAUCE_LABS:
default:
Expand Down

0 comments on commit d6307ad

Please sign in to comment.