如果选择npm安装的最新版appium 1.8.0以上版本,启动appium的时候,你会发现无法使用Node.js命令

这里给出两种方法来启动appim:

方法一:

/**
* 使用AppiumServiceBuilder+AppiumDriverLocalService 开启appium服务(可以添加appium参数)
*/
public void startAppiumServer() {
//Set Capabilities
cap = new DesiredCapabilities();
cap.setCapability("noReset", "false");
cap.setCapability("noSign", "true");
cap.setCapability("unicodeKeyboard", true);
cap.setCapability("resetKeyboard", true); //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 stopAppiumServer() {
service.stop();
Log.logInfo("Appium stopped!!");
} public boolean checkIfServerIsRunnning(int port) { boolean isServerRunning = false;
ServerSocket serverSocket;
try {
serverSocket = new ServerSocket(port);
serverSocket.close();
} catch (IOException e) {
//If control comes here, then it means that the port is in use
isServerRunning = true;
} finally {
serverSocket = null;
}
return isServerRunning;
}

方法二:

/**
* 命令行模式启动appium, 发现又是每次需要安装appium键盘,unlock 等等
* 暂时没有很好的办法解决这个问题
*
*/
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\"\": \"\"true\"\"}\"\"");
Thread.sleep(Constant.LONGTIME_IN_MS);
} 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();
}
}

方法三:(注意别有中午路径,可以自行转换下)

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();
}
}

通过代码启动appium服务的更多相关文章

  1. jenkins启动appium服务

    想在jenkins中,自动定时启动appium服务,shell命令已准备如下: BUILD_ID=dontKillMe echo "" > appium.log nohup ...

  2. appium--python启动appium服务

    前戏 前面我们都是在cmd下通过输入appium加端口号来启动服务的,在我们做自动化的时候,我们当然不希望我们手动启动appium服务,而是希望通过脚本自动启动appium服务. 我们可以使用subp ...

  3. 命令行启动appium服务

    Android终端 appium --avd test -a 127.0.0.1 -p 4723 --language "zh_CN" --locale "CN" ...

  4. Appium+Python app自动化测试之脚本启动和停止Appium服务

    研究了一段时间的Appium android app的自动化测试,工作中需要连接多台手机终端同时执行测试用例,我实现的方式是获取用例中需要执行用例的设备id个数以及实际连接到的设备数(通过adb de ...

  5. 启动多个appium服务(同时运行多台设备)

    准备: 一台真机一台模拟器(使用的是“夜神模拟器”) 先查看是否检测到设备  adb devices    由上图可看出没有检测到模拟器(夜神模拟器已开启) 可通过以下配置完成: 第一步:找到adb的 ...

  6. appium+python自动化60-windows上同时启动多个appium服务,让多个android机器并行运行

    前言 做android自动化的时候,启动一个appium服务,只能匹配一个手机去自动化执行.有时候想同一套代码,可以在不同的手机上执行,测下app在不同手机上兼容性. 这就需要启动多个appium服务 ...

  7. Appium+python自动化(三十六)- 士兵突击许三多 - 多个appium服务启动,多个设备启动,多进程并发启动设备-并发测试 - 上(超详解)

    简介 前面课程只是启动了单个appium服务,只能控制单台设备.如果需要针对多台设备测试那么该如何处理?而且发现群里的小伙伴们也在时不时地在讨论这个问题,想知道怎么实现的,于是宏哥就决定写一片这样的文 ...

  8. Appium+python自动化(三十七)- 士兵突击许三多 - 多个appium服务启动,多个设备启动,多进程并发启动设备-并发测试 - 下(超详解)

    简介 接着上一篇继续看一下如何并发测试以及并发测试的过程中,可能遇到的问题,在这里宏哥把宏哥遇到的和小伙伴或者童鞋们,一起分享一下. Appium端口检测 问题思考 经过前面学习,我们已经能够使用py ...

  9. Appium+python自动化(三十五)- 命令启动appium之 appium服务命令行参数(超详解)

    简介 前边介绍的都是通过按钮点击启动按钮来启动appium服务,有的小伙伴或者童鞋们乍一听可能不信,或者会问如何通过命令行启动appium服务呢?且听宏哥一一道来. 一睹为快 其实相当的简单,不看不知 ...

随机推荐

  1. no module named win32api

    1 首先下载pywin32 https://sourceforge.net/projects/pywin32/files/pywin32/ 2进入虚拟环境 D:\env\jdscrapy\Lib\si ...

  2. jail-break-rule

    switchOmega plugin for firefox and chrome https://raw.githubusercontent.com/gfwlist/gfwlist/master/g ...

  3. C# 获取指定路径下的文件结构(树形结构)

    namespace Vue.Content { public class FileNames { public int id { get; set; } public string text { ge ...

  4. mongoexport 导出需要授权数据库中的集合 报错 Authentication failed.

    当 mongo数据库启动服务时,使用了 认证机制,在使用mongoexport导出集合文件时,需要用户权限认证. 开启数据库认证服务: mongod --auth 导出mongo中集合文件: mong ...

  5. IntelliJ IDEA 集成 SVN

    在idea中使用subversion提交代码需要使用SVN SVN下载官网:https://tortoisesvn.net/downloads.html 可以根据自己电脑下载相应的版本,如果安装了的需 ...

  6. windowNoTitle 无效

    在开发Dialog 时候如采用 Dialog Activity 方式可能会出现取消标题栏失效 以下针对两种情况说明 1.如果 extends AppCompatActivity 需要在setConte ...

  7. 分组密码算法AES-128,192,256 C语言实现第一版

    AES的C语言实现入门版 AES分组密码算法中明文分组位128bits,密钥分组可以为128,192,256bits.AES也是由最基本的变换单位——“轮”多次迭代而成的.我们将 AES 中的轮变换计 ...

  8. SpringMVC参数绑定总结

    springMvc作用:    a) 接收请求中的参数    b) 将处理好的数据返回给页面参数绑定(就是从请求中接收参数):    a) 默认支持的类型: request, response, se ...

  9. 7Linux存储结构和磁盘划分

    FHS yum的.repo的配置文件多个的话,是依次生效吗? /boot 开机所需文件—内核.开机菜单以及所需配置文件等/dev 以文件形式存放任何设备与接口/etc 配置文件/home 用户主目录/ ...

  10. Javascript中用来实现继承的几种方式

    一.原型链继承 原理:修改子类型的原型,使其指向父类型的实例: 缺点: 1,不能以字面量方式在子类型的原型上添加新方法:这回重新改写子类型的原型: 2  创建子类型的实例时无法向父类型的构造函数传参. ...