-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavaAppium
66 lines (57 loc) · 2.43 KB
/
JavaAppium
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
package Appium_lotus_Vikram;
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Setup {
public static void main(String[] args) throws MalformedURLException {
String destDir;
DateFormat dateFormat;
destDir = "screenshots"; // Capture screenshot.
DesiredCapabilities capabilities = new DesiredCapabilities();
File appDir = new File("D:\\Lotus\\Work\\Appium\\App");
File app = new File(appDir, "LotusApp-debug.apk");
capabilities.setCapability("deviceName", "19b801a117");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app-package","com.ge.med.mic.lotus");
capabilities.setCapability("app-activity","com.ge.med.mic.lotus.activities.LotusMonitoringActivity");
capabilities.setCapability("app-wait-activity","com.ge.med.mic.lotus.activities.LotusMonitoringActivity");
capabilities.setCapability("app", app.getAbsolutePath());
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
screenshot(destDir, driver);
}
private static void screenshot(String destDir, AndroidDriver driver) {
DateFormat dateFormat;
// Set date format to set It as screenshot file name.
dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
String destFile = dateFormat.format(new Date()) + ".png";
// Create folder under project with name "screenshots" provided to destDir.
new File(destDir).mkdirs(); // Set file name using current date time.
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
Thread.sleep(500);
}
catch (IOException e){
e.printStackTrace();
}
catch (InterruptedException ie)
{
System.out.println(ie);
ie.printStackTrace();
}
driver.quit();
}
}