9
9
import objects .PlatformType ;
10
10
11
11
import java .io .File ;
12
- import java .io .IOException ;
13
12
import java .net .URL ;
14
13
import java .util .concurrent .TimeUnit ;
15
14
16
- /**
17
- * Created by testdroid on 22/07/16.
18
- */
19
15
public abstract class AbstractAppiumTest {
20
16
21
- public static final int SHORT_SLEEP = 1 ;
22
- public static final int MEDIUM_SLEEP = 5 ;
23
- public static final int LONG_SLEEP = 10 ;
24
-
25
17
protected static Logger logger = LoggerFactory .getLogger (AbstractAppiumTest .class );
26
-
27
-
28
-
29
18
protected static AppiumDriver <MobileElement > driver ;
30
19
protected static int defaultWaitTime = 120 ;
31
20
32
- public static String screenshotsFolder = "" ;
33
21
public static String appFile = System .getenv ("APP_FILE" );
34
22
public static PlatformType platform ;
35
23
public static String automationName = System .getenv ("AUTOMATION_NAME" );
@@ -38,10 +26,8 @@ public abstract class AbstractAppiumTest {
38
26
public static String platformVersion = System .getenv ("PLATFORM_VERSION" );
39
27
// Set to false to autoDismiss
40
28
public static boolean autoAccept = true ;
41
- public static boolean idevicescreenshotExists = false ;
42
-
43
29
44
- public static AppiumDriver getIOSDriver () throws Exception {
30
+ public static AppiumDriver < MobileElement > getIOSDriver () throws Exception {
45
31
if (appFile == null ) {
46
32
appFile = "application.ipa" ;
47
33
}
@@ -57,10 +43,6 @@ public static AppiumDriver getIOSDriver() throws Exception {
57
43
// Use default "appium" automation for iOS
58
44
automationName = "appium" ;
59
45
60
- screenshotsFolder = "target/reports/screenshots/ios/" ;
61
- File dir = new File (screenshotsFolder );
62
- dir .mkdirs ();
63
-
64
46
DesiredCapabilities capabilities = new DesiredCapabilities ();
65
47
capabilities .setCapability ("platformName" , platform .getPlatformName ());
66
48
capabilities .setCapability ("deviceName" , deviceName );
@@ -80,15 +62,13 @@ public static AppiumDriver getIOSDriver() throws Exception {
80
62
capabilities .setCapability ("autoDismissAlerts" , true );
81
63
}
82
64
83
- idevicescreenshotCheck ();
84
-
85
65
log ("Creating Appium session, this may take couple minutes.." );
86
66
driver = new IOSDriver <MobileElement >(new URL ("http://localhost:4723/wd/hub" ), capabilities );
87
67
driver .manage ().timeouts ().implicitlyWait (defaultWaitTime , TimeUnit .SECONDS );
88
68
return driver ;
89
69
}
90
70
91
- public static AppiumDriver getAndroidDriver () throws Exception {
71
+ public static AppiumDriver < MobileElement > getAndroidDriver () throws Exception {
92
72
if (appFile == null ) {
93
73
appFile = "application.apk" ;
94
74
}
@@ -101,9 +81,6 @@ public static AppiumDriver getAndroidDriver() throws Exception {
101
81
if (automationName == null ){
102
82
automationName = "appium" ;
103
83
}
104
- screenshotsFolder = "target/reports/screenshots/android/" ;
105
- File dir = new File (screenshotsFolder );
106
- dir .mkdirs ();
107
84
108
85
DesiredCapabilities capabilities = new DesiredCapabilities ();
109
86
capabilities .setCapability ("automationName" , automationName );
@@ -124,51 +101,8 @@ public static AppiumDriver getAndroidDriver() throws Exception {
124
101
return driver ;
125
102
}
126
103
127
-
128
-
129
- //On a test run on the local machine this method will save the Reports folder in different folders on every test run.
130
- public static void savePreviousRunReports () {
131
- long millis = System .currentTimeMillis ();
132
- File dir = new File ("./target/reports" );
133
- File newName = new File ("./target/reports" + millis );
134
- if (dir .isDirectory ()) {
135
- dir .renameTo (newName );
136
- } else {
137
- dir .mkdir ();
138
- dir .renameTo (newName );
139
- }
140
- }
141
-
142
- public static boolean idevicescreenshotCheck () throws IOException , InterruptedException {
143
- String [] cmd = new String []{"idevicescreenshot" , "--help" };
144
- int exitVal = -1 ;
145
- try {
146
- Process p = Runtime .getRuntime ().exec (cmd );
147
- exitVal = p .waitFor ();
148
- } catch (IOException e ) {
149
- log (e .toString ());
150
- }
151
- if (exitVal == 0 ) {
152
- log ("idevicescreenshot exited with value: " + exitVal + ". Using it for screenshots." );
153
- idevicescreenshotExists = true ;
154
- } else {
155
- log ("idevicescreenshot process exited with value: " + exitVal + ". Won't be using it for screenshots." );
156
- idevicescreenshotExists = false ;
157
- }
158
- return idevicescreenshotExists ;
159
- }
160
-
161
- //Stops the script for the given amount of seconds.
162
- public static void sleep (double seconds ) throws Exception {
163
- log ("Waiting for " + seconds + " sec" );
164
- seconds = seconds * 1000 ;
165
- Thread .sleep ((int ) seconds );
166
- }
167
-
168
104
public static void log (String message ) {
169
105
logger .info (message );
170
106
}
171
107
172
-
173
-
174
108
}
0 commit comments