3
3
import java .io .File ;
4
4
import java .io .IOException ;
5
5
import java .net .URL ;
6
+ import java .util .HashMap ;
7
+ import java .util .Map ;
6
8
import java .util .concurrent .TimeUnit ;
7
9
10
+ import org .apache .commons .exec .CommandLine ;
11
+ import org .apache .commons .exec .DefaultExecuteResultHandler ;
12
+ import org .apache .commons .exec .DefaultExecutor ;
8
13
import org .openqa .selenium .By ;
9
14
import org .openqa .selenium .remote .DesiredCapabilities ;
10
15
import org .testng .annotations .AfterSuite ;
@@ -30,16 +35,33 @@ public class AppTest
30
35
public static By findIcon = By .xpath ("//*[@class='android.support.v7.app.ActionBar$Tab'][1]" );
31
36
public static AppiumDriver driver = null ;
32
37
// public static AppiumServiceBuilder service;
33
-
38
+
39
+
34
40
public static AppiumDriverLocalService service =null ;
35
41
public static String AppiumNodeFilePath ="/usr/local/bin/node" ;
36
42
public static String AppiumJavaScriptServerFile = "/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js" ;
37
43
@ BeforeTest
38
44
// public static void setup(String pVer, String pName, String appLocation, String dName)
39
45
public static void setup () throws IOException {
40
-
41
- stopAppiumServer ();
42
- startAppiumServer ();
46
+
47
+ //Runtime.getRuntime().exec("/bin/bash export ANDROID_HOME=/Users/shanojthekkan/Library/Android/sdk/");
48
+
49
+ CommandLine command = new CommandLine ("/usr/local/bin/node" );
50
+ command .addArgument ("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js" , false );
51
+ command .addArgument ("--address" , false );
52
+ command .addArgument ("0.0.0.0" );
53
+ command .addArgument ("--port" , false );
54
+ command .addArgument ("4723" );
55
+ command .addArgument ("--no-reset" , true );
56
+ DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler ();
57
+ DefaultExecutor executor = new DefaultExecutor ();
58
+ executor .setExitValue (1 );
59
+ executor .execute (command , resultHandler );
60
+
61
+
62
+
63
+ // stopAppiumServer();
64
+ // startAppiumServer();
43
65
44
66
File appDir = new File ("resources" );
45
67
File app = new File (appDir , "Officeworks.apk" );
@@ -65,6 +87,8 @@ public static void setup() throws IOException {
65
87
public static void startAppiumServer () throws IOException {
66
88
67
89
System .out .println ("Starting Appium Server ......" );
90
+
91
+
68
92
69
93
service = AppiumDriverLocalService .buildService (new AppiumServiceBuilder ().usingDriverExecutable (new File (AppiumNodeFilePath )).withAppiumJS (
70
94
new File (AppiumJavaScriptServerFile )));
@@ -103,6 +127,6 @@ public void testsample() throws InterruptedException {
103
127
@ AfterTest
104
128
public static void teardown () throws IOException {
105
129
driver .quit ();
106
- stopAppiumServer ();
130
+ // stopAppiumServer();
107
131
}
108
132
}
0 commit comments