-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathRWDDownloadReport
More file actions
83 lines (64 loc) · 2.71 KB
/
RWDDownloadReport
File metadata and controls
83 lines (64 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class RWDDownloadReport {
public static void main(String[] args) throws MalformedURLException, UnsupportedEncodingException {
System.out.println("Run started");
String browserName = "chrome";
DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY);
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.*");
capabilities.setCapability("manufacturer", "Samsung");
capabilities.setCapability("model", "Galaxy Nexus");
// dev = TA64803XSN
String host = Constants.PM_CLOUD;
String user = URLEncoder.encode(Constants.PM_USER, "UTF-8");
String password = URLEncoder.encode(Constants.PM_PASSWORD, "UTF-8");
RemoteWebDriver driver = new RemoteWebDriver(new URL("https://" + user + ':' + password + '@' + host + "/nexperience/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
capabilities = (DesiredCapabilities) driver.getCapabilities();
String reportkey = (String) capabilities.getCapability("reportKey");
String executionId = (String) capabilities.getCapability("executionId");
try {
driver.get("google.com");
driver.findElement(By.xpath("//input[@id=\"lst-ib\"]")).sendKeys("PerfectoMobile");
driver.findElement(By.xpath("//*[@type=\"submit\"]")).click();
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.quit();
}
downloadReport(reportkey);
}
private static void downloadReport(String reportId)
{
URL Repurl;
try {
Repurl = new URL("https://"+Constants.PM_CLOUD+"/services/reports/"+reportId+"?operation=download&user="+Constants.PM_USER+"&password="+Constants.PM_PASSWORD+"&format=html");
ReadableByteChannel rbc = Channels.newChannel(Repurl.openStream());
FileOutputStream fos = new FileOutputStream("C:\\test\\PerfectoRep.html");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
}