Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathRemoteWebDriverTest.java
More file actions
Latest commit
120 lines (102 loc) · 5.2 KB
/
Copy pathRemoteWebDriverTest.java
File metadata and controls
120 lines (102 loc) · 5.2 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
importjava.io.*;
importjava.net.*;
importjava.util.*;
importjava.util.concurrent.ExecutorService;
importjava.util.concurrent.Executors;
importjava.util.concurrent.TimeUnit;
importorg.openqa.selenium.*;
importorg.openqa.selenium.html5.*;
importorg.openqa.selenium.logging.*;
importorg.openqa.selenium.remote.*;
importorg.openqa.selenium.Cookie.Builder;
/**
* For programming samples and updated templates refer to the Perfecto GitHub at: https://github.com/PerfectoCode
*/
publicclassRemoteWebDriverTestimplementsRunnable {
privateStringdeviceID;
publicRemoteWebDriverTest(StringdeviceId) throwsMalformedURLException, InterruptedException {
deviceID=deviceId;
}
publicstaticvoidmain(String[] args) throwsMalformedURLException, InterruptedException {
List<String> deviceIds = newLinkedList<>();
deviceIds.add("1115FBD16FEF0303");
deviceIds.add("C37BAE1934AE7DD0AE3355F77146C7A65579CAA3");
ExecutorServiceexecutor = Executors.newFixedThreadPool(deviceIds.size());
for (StringdeviceId : deviceIds) {
RemoteWebDriverTesttest = newRemoteWebDriverTest(deviceId);
System.err.println("starting execute test "+deviceId);
executor.execute(test);
System.err.println("started execute test+deviceId");
}
executor.shutdown();
}
@Override
publicvoidrun() {
// TODO Auto-generated method stub
StringbrowserName = "mobileOS";
DesiredCapabilitiescapabilities = newDesiredCapabilities(browserName, "", Platform.ANY);
Stringhost = "demo.perfectomobile.com";
capabilities.setCapability("user", "");
capabilities.setCapability("password", "");
//TODO: Change your device ID
capabilities.setCapability("deviceName", deviceID);
// Use the automationName capability to define the required framework - Appium (this is the default) or PerfectoMobile.
// capabilities.setCapability("automationName", "PerfectoMobile");
// Call this method if you want the script to share the devices with the Perfecto Lab plugin.
// PerfectoLabUtils.setExecutionIdCapability(capabilities, host);
// Add a persona to your script (see https://community.perfectomobile.com/posts/1048047-available-personas)
//capabilities.setCapability(WindTunnelUtils.WIND_TUNNEL_PERSONA_CAPABILITY, WindTunnelUtils.GEORGIA);
// Name your script
// capabilities.setCapability("scriptName", "RemoteWebDriverTest");
RemoteWebDriverdriver = null;
try {
driver = newRemoteWebDriver(newURL("https://" + host + "/nexperience/perfectomobile/wd/hub"), capabilities);
} catch (MalformedURLExceptione1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
try
{
//#####Write the test code
//for example
driver.get("bbc.co.uk");
driver.findElementByXPath("//*[@id=\"idcta-link\"]").click();
Thread.sleep(5000);
driver.findElementByXPath("//*[@id=\"username-input\"]").sendKeys("aUser");
driver.findElementByXPath("//*[@id=\"password-input\"]").sendKeys("apassword");
} catch (Exceptione) {
e.printStackTrace();
} finally {
try {
// Retrieve the URL of the Single Test Report, can be saved to your execution summary and used to download the report at a later point
StringreportURL = (String)(driver.getCapabilities().getCapability(WindTunnelUtils.SINGLE_TEST_REPORT_URL_CAPABILITY));
driver.close();
// In case you want to download the report or the report attachments, do it here.
// PerfectoLabUtils.downloadReport(driver, "pdf", "C:\\test\\report");
// PerfectoLabUtils.downloadAttachment(driver, "video", "C:\\test\\report\\video", "flv");
// PerfectoLabUtils.downloadAttachment(driver, "image", "C:\\test\\report\\images", "jpg");
} catch (Exceptione) {
e.printStackTrace();
}
driver.quit();
System.err.println(deviceID+ "driver quit");
}
}
privatestaticvoidswitchToContext(RemoteWebDriverdriver, Stringcontext) {
RemoteExecuteMethodexecuteMethod = newRemoteExecuteMethod(driver);
Map<String,String> params = newHashMap<String,String>();
params.put("name", context);
executeMethod.execute(DriverCommand.SWITCH_TO_CONTEXT, params);
}
privatestaticStringgetCurrentContextHandle(RemoteWebDriverdriver) {
RemoteExecuteMethodexecuteMethod = newRemoteExecuteMethod(driver);
Stringcontext = (String) executeMethod.execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE, null);
returncontext;
}
privatestaticList<String> getContextHandles(RemoteWebDriverdriver) {
RemoteExecuteMethodexecuteMethod = newRemoteExecuteMethod(driver);
List<String> contexts = (List<String>) executeMethod.execute(DriverCommand.GET_CONTEXT_HANDLES, null);
returncontexts;
}
}