我使用的是Windows8.1和Appium1.4.16,到目前为止,我想升级appium,所以我只是从控制面板卸载了1.4.16,然后用以下命令安装了最新的appium之后安装了node.js
npm install -g appium当我跑的时候
appium -v它告诉我到目前为止1.6.4没有问题。之后,在我的Maven项目中,我想以编程方式启动appium服务器,但appium并未保存在
C:/Program Files or C:/ProgramFile(x86)。
如何以编程方式启动appium服务器?
我使用下面的代码来运行appium
Process p = Runtime.getRuntime().exec("\"C:/Program Files/Appium/node.exe\" \"C:/Program Files/Appium/node_modules/appium/bin/Appium.js\" --full-reset --local-timezone");发布于 2018-06-06 02:26:02
有3种方法可以实现这个场景。1)使用AppiumDriverLocalService
public void startServer() {
//Set Capabilities
cap = new DesiredCapabilities();
cap.setCapability("noReset", "false");
//Build the Appium service
builder = new AppiumServiceBuilder();
builder.withIPAddress("127.0.0.1");
builder.usingPort(4723);
builder.withCapabilities(cap);
builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
builder.withArgument(GeneralServerFlag.LOG_LEVEL,"error");
//Start the server with the builder
service = AppiumDriverLocalService.buildService(builder);
service.start();
}
public void stopServer() {
service.stop();
}2)在Node.exe中使用Appium.js
public void startServer() {
CommandLine cmd = new CommandLine("C:\\Program Files (x86)\\Appium\\node.exe");
cmd.addArgument("C:\\Program Files (x86)\\Appium\\node_modules\\appium\\bin\\Appium.js");
cmd.addArgument("--address");
cmd.addArgument("127.0.0.1");
cmd.addArgument("--port");
cmd.addArgument("4723");
DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(cmd, handler);
Thread.sleep(10000);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
public void stopServer() {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("taskkill /F /IM node.exe");
} catch (IOException e) {
e.printStackTrace();
}
}3)使用命令提示符启动Appium服务器
public void startServer() {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("cmd.exe /c start cmd.exe /k \"appium -a 127.0.0.1 -p 4723 --session-override -dc \"{\"\"noReset\"\": \"\"false\"\"}\"\"");
Thread.sleep(10000);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
public void stopServer() {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("taskkill /F /IM node.exe");
runtime.exec("taskkill /F /IM cmd.exe");
} catch (IOException e) {
e.printStackTrace();
}
}我发现它helpful.Hope它有帮助。来源:http://www.automationtestinghub.com/3-ways-to-start-appium-server-from-java/
发布于 2017-05-23 15:36:59
您可以尝试以下代码:
AppiumServiceBuilder builder = new AppiumServiceBuilder()
.withAppiumJS(new File("C:\Users\<Username>\node_modules\appium\build\lib\main.js"))
.withArgument(GeneralServerFlag.APP, path of your app );
appiumDriverLocalService = builder.build();
appiumDriverLocalService.start();发布于 2017-05-24 08:22:12
如果它是通过npm安装的,那么Appium就可以通过编程方式运行。Appium安装在哪里并不重要。下面的代码模仿了我们从命令提示符打开它的手动行为。
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("cmd.exe /c start cmd.exe /k \"appium -a 127.0.0.1 -p 4723 --session-override -dc \"{\"\"noReset\"\": \"\"false\"\"}\"\"");
Thread.sleep(10000);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}根据您安装Appium的方式,还有其他几种方法。您可以在此处查看这些内容- Start Appium Server Programatically
https://stackoverflow.com/questions/44127307
复制相似问题