首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Windows计算机中以编程方式启动appium服务器

在Windows计算机中以编程方式启动appium服务器
EN

Stack Overflow用户
提问于 2017-05-23 14:28:31
回答 4查看 3.9K关注 0票数 0

我使用的是Windows8.1和Appium1.4.16,到目前为止,我想升级appium,所以我只是从控制面板卸载了1.4.16,然后用以下命令安装了最新的appium之后安装了node.js

代码语言:javascript
复制
npm install -g appium

当我跑的时候

代码语言:javascript
复制
appium -v

它告诉我到目前为止1.6.4没有问题。之后,在我的Maven项目中,我想以编程方式启动appium服务器,但appium并未保存在

C:/Program Files or C:/ProgramFile(x86)

如何以编程方式启动appium服务器?

我使用下面的代码来运行appium

代码语言:javascript
复制
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");
EN

回答 4

Stack Overflow用户

发布于 2018-06-06 02:26:02

有3种方法可以实现这个场景。1)使用AppiumDriverLocalService

代码语言:javascript
复制
 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

代码语言:javascript
复制
  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服务器

代码语言:javascript
复制
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/

票数 4
EN

Stack Overflow用户

发布于 2017-05-23 15:36:59

您可以尝试以下代码:

代码语言:javascript
复制
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();
票数 1
EN

Stack Overflow用户

发布于 2017-05-24 08:22:12

如果它是通过npm安装的,那么Appium就可以通过编程方式运行。Appium安装在哪里并不重要。下面的代码模仿了我们从命令提示符打开它的手动行为。

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44127307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档