-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriverUtils.java
152 lines (128 loc) · 4.45 KB
/
DriverUtils.java
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.fs.app.automation.DriverUtils;
import com.fs.app.automation.Misc.Params;
import com.fs.app.automation.Misc.Props;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.slf4j.LoggerFactory;
import java.net.MalformedURLException;
import java.net.URL;
public class DriverUtils extends EventFiringWebDriver {
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(DriverUtils.class);
static String platfrm;
private static RemoteWebDriver driver = null;
public DriverUtils(WebDriver driver) {
super(driver);
}
private static final Thread CLOSE_THREAD = new Thread() {
@Override
public void run() {
closeDriver();
}
};
static {
Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
Props.loadRunConfigProps();
platfrm = Params.PLATFORM;
getDriver();
//getAndroidDriver2();
}
public static RemoteWebDriver getDriver() {
//if(Params.PLATFORM.toLowerCase().equals("android")) {
if(platfrm.toLowerCase().equals("android")) {
return getAndroidDriver();
}
else{
return getiOSDriver();
}
}
public static RemoteWebDriver getAndroidDriver() {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("platformName","Android");
//cap.setCapability("platformVersion","7.0");
//cap.setCapability("deviceName","ZX1G42BQHB");
cap.setCapability("udid","ZX1G42BQHB");
cap.setCapability("deviceName","Android");
cap.setCapability("applicationName","Nexus");
//cap.setCapability("deviceName","ce03171312024a3303");applicationName
cap.setCapability("appPackage","com.netcosports.and.foxsports");
cap.setCapability("appActivity",".activities.InitActivity");
cap.setCapability("noReset","true");
cap.setCapability("fullReset","false");
cap.setCapability("newCommandTimeout","30000");
cap.setCapability("clearSystemFiles","true");
cap.setCapability("unlockType", "pin");
cap.setCapability("unlockKey" , "0000");
try {
//driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), cap);
driver = new AndroidDriver(new URL("http://10.22.141.174:4723/wd/hub"), cap);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}
public static RemoteWebDriver getAndroidDriver2() {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("platformName","Android");
cap.setCapability("deviceName","Android");
cap.setCapability("applicationName","Samsung S8");
cap.setCapability("udid","ce03171312024a3303");
cap.setCapability("appPackage","com.netcosports.and.foxsports");
cap.setCapability("appActivity",".activities.InitActivity");
cap.setCapability("noReset","true");
cap.setCapability("fullReset","false");
cap.setCapability("newCommandTimeout","30000");
cap.setCapability("clearSystemFiles","true");
cap.setCapability("unlockType", "pin");
cap.setCapability("unlockKey" , "0000");
try {
//driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), cap);
driver = new AndroidDriver(new URL("http://10.22.141.174:4725/wd/hub"), cap);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}
private static AppiumDriver getiOSDriver(){
System.out.println();
return null;
}
public static RemoteWebDriver getAppDriver(){
return driver;
}
public static void closeDriver() {
try{
driver.quit();
} catch (NoSuchSessionException e) {
LOG.info("The driver is already closed!!");
}
}
@Override
public void close() {
if (Thread.currentThread() != CLOSE_THREAD) {
throw new UnsupportedOperationException(
"Do not close this WebDriver. It's shared and will close when the JVM exits.");
}
super.close();
}
public static void reOpenApp(){
try {
((AndroidDriver)driver).startActivity("com.netcosports.and.foxsports",".activities.InitActivity");
}catch (Exception e){
LOG.error(e.getMessage());
}
}
public static void closeNOpenDriver(){
try {
driver.switchTo().frame(1);
//driver.switchTo().defaultContent();
//driver.resetInputState();
} catch(NoSuchSessionException e){
e.printStackTrace();
}
}
}