脚本描述:iOS设备执行fastbot脚本演示
应用范围:UI自动化
脚本内容:
import org.cloud.sonic.agent.tests.LogUtil;
import org.cloud.sonic.agent.common.interfaces.StepType;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import org.cloud.sonic.agent.bridge.ios.SibTool;
import java.io.File;
import org.cloud.sonic.agent.tools.ProcessCommandTool;
def test(){
iosStepHandler.closeIOSDriver()
String udId = iosStepHandler.udId
LogUtil log = iosStepHandler.log
Process ps = null;
String system = System.getProperty("os.name").toLowerCase();
File sib = new File("plugins" + File.separator + "sonic-ios-bridge");
if (system.contains("win")) {
ps = Runtime.getRuntime().exec("cmd /c "+sib.getAbsolutePath()+" run xctest -u "+udId+" -b fastbot的bundleId -e BUNDLEID=被测应用的bundleId -e duration=测试时长 -e throttle=300");
} else {
ps = Runtime.getRuntime().exec("sh -c "+sib.getAbsolutePath()+" run xctest -u "+udId+" -b fastbot的bundleId -e BUNDLEID=被测应用的bundleId -e duration=测试时长 -e throttle=300");
}
InputStreamReader inputStreamReader = new InputStreamReader(ps.getInputStream());
BufferedReader stdInput = new BufferedReader(inputStreamReader);
String s;
while (ps.isAlive()) {
try{
if ((s = stdInput.readLine()) != null) {
log.sendStepLog(StepType.INFO,"ps msg",s)
}
} catch (IOException e) {
e.printStackTrace();
}
}
stdInput.close();
inputStreamReader.close();
iosStepHandler.startIOSDriver(udId, SibTool.startWda(udId)[0]);
}
//懒人版
def test2() {
String udId = iosStepHandler.udId
LogUtil log = iosStepHandler.log
File sib = new File("plugins" + File.separator + "sonic-ios-bridge");
String res = ProcessCommandTool.getProcessLocalCommandStr(sib.getAbsolutePath()+" run xctest -u "+udId+" -b fastbot的bundleId -e BUNDLEID=被测应用的bundleId -e duration=测试时长 -e throttle=300");
log.sendStepLog(StepType.INFO,"ps msg",res)
}
test()
test2()