For Running directly in aws device farm:
Modify your existing karate project according to the below documentation:
https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-appium.html
steps are pretty straightforward, updating pom.xml
, creating assembly/zip.xml
, and run mvn package
to create jar files which you have to zip and upload to devicefarm project.
I noted that running on device farm by directly uploading your project only works with Junit4 hence you can only use karate-junit4
in your dependency
For Local:
Refer DeviceFarmTarget
class in https://github.com/ptrthomas/karate-devicefarm-demo and implement a similar one in you existing karate project
public class AwsDeviceFarmMobileTarget implements Target {
private String arn;
private String driverType = "android";
public AwsDeviceFarmMobileTarget(Map<String, Object> options) {
arn = (String) options.get("arn");
if (arn == null) {
throw new RuntimeException("arn is null");
}
// update driver type and browserName if needed
}
@Override
public Map<String, Object> start(ScenarioRuntime sr) {
sr.logger.info("starting driver using: {}", AwsDeviceFarmMobileTarget.class);
DeviceFarmClient client = DeviceFarmClient.builder().region(Region.US_WEST_2).build();
CreateTestGridUrlRequest request = CreateTestGridUrlRequest.builder()
.expiresInSeconds(300)
.projectArn(arn)
.build();
CreateTestGridUrlResponse response = client.createTestGridUrl(request);
String webDriverUrl = response.url();
sr.logger.info("aws url provisioned: {}", webDriverUrl);
Map<String, Object> map = new HashMap();
map.put("type", driverType);
map.put("start", false);
map.put("webDriverUrl", webDriverUrl);
// this is needed because it can take a minute or two for the "desktop" to be provisioned by aws
map.put("httpConfig", Collections.singletonMap("readTimeout", 120000));
// refer: https://docs.aws.amazon.com/devicefarm/latest/testgrid/techref-support.html
Map<String, Object> session = new HashMap();
map.put("webDriverSession", session);
Map<String, Object> capabilities = new HashMap();
session.put("capabilities", capabilities);
// for some reason, both are needed for aws device farm
session.put("desiredCapabilities", capabilities);
return map;
}
@Override
public Map<String, Object> stop(ScenarioRuntime sr) {
return Collections.EMPTY_MAP;
}
}