-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathTestConfigurations.java
More file actions
65 lines (56 loc) · 2.71 KB
/
TestConfigurations.java
File metadata and controls
65 lines (56 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.saucedemo;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.TestInfo;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.MutableCapabilities;
public class TestConfigurations {
static final String ANDROID_APP_URL =
"https://github.com/saucelabs/my-demo-app-android/releases/download/2.1.0/mda-2.1.0-24.apk";
static final String SAUCE_CLOUD = System.getProperty("sauce.cloud", "vdc");
static final String BUILD_TIME = String.valueOf(System.currentTimeMillis());
// Best practice would put these constants in a config file and dynamically pull them.
public static Capabilities getCapabilities(TestInfo testInfo) {
if (SAUCE_CLOUD.equalsIgnoreCase("vdc")) {
return androidAppVDC(testInfo);
} else if (SAUCE_CLOUD.equalsIgnoreCase("rdc")) {
return androidAppRDC(testInfo);
} else {
throw new RuntimeException("Must set sauce.cloud property to vdc or rdc");
}
}
// Generate these capabilities with Platform Configurator:
// https://app.saucelabs.com/platform-configurator
private static Capabilities androidAppRDC(TestInfo testInfo) {
Map<String, Object> caps = new HashMap<>();
caps.put("platformName", "Android");
caps.put("appium:automationName", "UiAutomator2");
caps.put("appium:app", ANDROID_APP_URL);
caps.put("appium:deviceName", "Google.*");
Map<String, Object> sauceOptions = new HashMap<>();
sauceOptions.put("username", System.getenv("SAUCE_USERNAME"));
sauceOptions.put("accessKey", System.getenv("SAUCE_ACCESS_KEY"));
sauceOptions.put("appiumVersion", "latest");
sauceOptions.put("name", testInfo.getDisplayName());
sauceOptions.put("build", "Android App RDC: " + BUILD_TIME);
caps.put("sauce:options", sauceOptions);
return new MutableCapabilities(caps);
}
private static Capabilities androidAppVDC(TestInfo testInfo) {
Map<String, Object> caps = new HashMap<>();
caps.put("platformName", "Android");
caps.put("appium:automationName", "UiAutomator2");
caps.put("appium:app", ANDROID_APP_URL);
caps.put("appium:deviceName", "Android GoogleAPI Emulator");
caps.put("appium:platformVersion", "current_major");
caps.put("appium:appPackage", "com.saucelabs.mydemoapp.android");
caps.put("appium:appWaitActivity", "view.activities.MainActivity");
Map<String, Object> sauceOptions = new HashMap<>();
sauceOptions.put("username", System.getenv("SAUCE_USERNAME"));
sauceOptions.put("accessKey", System.getenv("SAUCE_ACCESS_KEY"));
sauceOptions.put("name", testInfo.getDisplayName());
sauceOptions.put("build", "Android App VDC: " + BUILD_TIME);
caps.put("sauce:options", sauceOptions);
return new MutableCapabilities(caps);
}
}