-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/com/testvagrant/ekam/mobile/remote/PerfectoDriver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters