script跟appium server溝通主要有兩個重點:
1.Capabilities
2.ip
如果把這兩個變數都寫死在全部的腳本裡面,會造成想要修改參數時非常麻煩
例如:你有50個script,當想要修改ip的時候得把50個script檔案都打開來修改...
可以寫一個總設定檔,把設定寫成function在裡面,當腳本需要連線時呼叫函數回傳設定
範例:
總設定檔:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| public class AllSettings {
public static DesiredCapabilities Set(){
DesiredCapabilities set = new DesiredCapabilities();
set.setCapability("appium-version", "1.3.1");
set.setCapability("device", "iOS Simulator");
set.setCapability("deviceName", "iPad Air");
set.setCapability("platformName", "iOS");
set.setCapability("platformVersion", "8.1");
set.setCapability("showSimulatorLog", "true");
set.setCapability("app","/Users/blabla/blabla");
return set;
}
public static String URL(){
return "http://127.0.0.1:4725/wd/hub";
}
}
|
腳本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| import AllSettings;
public class sample {
AppiumDriver wd = null;
@Test
public void test() throws MalformedURLException, InterruptedException {
wd = new AppiumDriver(new URL(AllSettings.URL()),AllSettings.Set());
wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
}
|
這樣對於管理全部的腳本非常方便,也不用每個腳本都去確認設定是否正確
沒有留言:
張貼留言