Appium的android真机每次启动手机中都会安装Appium settings和Unclock的方法

本文介绍了Appium 1.4.16.1版本真机运行情况,首次运行会自动安装Appium settings和Unclock的apk,再次运行若不手动删除会报错。说明了两个apk的作用,前者用于设置网络状态,后者用于滑动锁屏时自动解锁。给出解决办法,即手动修改appium安装路径下的android.js文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境介绍:

  1、appium版本:1.4.16.1

  2、真机运行

 

实现结果:

  运行appium第一次运行则安装Appium settings和Unclock的apk,再次之后的运行则无需手动卸载,再次安装。

 

问题描述:

  第一次:Android手机运行appium,自动安装Appium settings和Unclock的apk,

  第二次:第一次运行完毕,若不手动删除已经安装的Appium settings和Unclock,将会提示报错信息如下,提示:Appium settings和Unclock不是第一次安装,因此必须每次运行appium脚本,都需要手动删除此2个apk,重新运行则不会报错。

 

 WebDriverException: Message: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c "D:\AutoTest\adt-bundle-windows-x86-20140702\sdk\platform-tools\adb.exe -s GWY0216A22013956 install "D:\AutoTest\appium\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk""
 Failed to install D:\AutoTest\appium\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
)

根据以上报错信息,可以看到Appium settings和Unclock的安装路径。

 

 

apk作用说明:

  1、Appium settings:用于设置网络状态

  2、Unclock:用于自动解锁(使用场景:手机是滑动锁屏的情况下,则会自动解锁并启动apk,注意:图案锁屏与数字锁则不可以哦,只能是滑动锁屏)

 

解决方法:

  1、需要手动去修改appium安装路径下的android.js文件,来实现运行首次安装Appium settings和Unclock,之后的运行则无需再次卸载的操作。

  2、android.js的存放路径:D:\Auto Test\appium\Appium\node_modules\appium\lib\devices\android\android.js,说明:D:\Auto Test\appium\为本人的appium存放路径。

  3、android.js文件中找到如下代码

 

...
Android.prototype.start = function (cb, onDie) {
  this.launchCb = cb;
  this.uiautomatorExitCb = onDie;
  logger.info("Starting android appium");
  async.series([
    this.initJavaVersion.bind(this),
    this.initAdb.bind(this),
    this.packageAndLaunchActivityFromManifest.bind(this),
    this.initUiautomator.bind(this),
    this.prepareDevice.bind(this),
    this.checkApiLevel.bind(this),
    this.pushStrings.bind(this),
    this.processFromManifest.bind(this),
    this.uninstallApp.bind(this),
    this.installAppForTest.bind(this),
    this.forwardPort.bind(this),
    this.pushAppium.bind(this),
    this.initUnicode.bind(this),
    //this.pushSettingsApp.bind(this),    #手动注释此2行代码,即可解决问题
    //this.pushUnlock.bind(this),         

环境介绍:

  1、appium版本:1.4.16.1

  2、真机运行

 

实现结果:

  运行appium第一次运行则安装Appium settings和Unclock的apk,再次之后的运行则无需手动卸载,再次安装。

 

问题描述:

  第一次:Android手机运行appium,自动安装Appium settings和Unclock的apk,

  第二次:第一次运行完毕,若不手动删除已经安装的Appium settings和Unclock,将会提示报错信息如下,提示:Appium settings和Unclock不是第一次安装,因此必须每次运行appium脚本,都需要手动删除此2个apk,重新运行则不会报错。

 

 WebDriverException: Message: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c "D:\AutoTest\adt-bundle-windows-x86-20140702\sdk\platform-tools\adb.exe -s GWY0216A22013956 install "D:\AutoTest\appium\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk""
 Failed to install D:\AutoTest\appium\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
)

根据以上报错信息,可以看到Appium settings和Unclock的安装路径。

 

 

apk作用说明:

  1、Appium settings:用于设置网络状态

  2、Unclock:用于自动解锁(使用场景:手机是滑动锁屏的情况下,则会自动解锁并启动apk,注意:图案锁屏与数字锁则不可以哦,只能是滑动锁屏)

 

解决方法:

  1、需要手动去修改appium安装路径下的android.js文件,来实现运行首次安装Appium settings和Unclock,之后的运行则无需再次卸载的操作。

  2、android.js的存放路径:C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js,说明:为本人的appium存放路径。

  3、android.js文件中找到如下代码

 

...
Android.prototype.start = function (cb, onDie) {
  this.launchCb = cb;
  this.uiautomatorExitCb = onDie;
  logger.info("Starting android appium");
  async.series([
    this.initJavaVersion.bind(this),
    this.initAdb.bind(this),
    this.packageAndLaunchActivityFromManifest.bind(this),
    this.initUiautomator.bind(this),
    this.prepareDevice.bind(this),
    this.checkApiLevel.bind(this),
    this.pushStrings.bind(this),
    this.processFromManifest.bind(this),
    this.uninstallApp.bind(this),
    this.installAppForTest.bind(this),
    this.forwardPort.bind(this),
    this.pushAppium.bind(this),
    this.initUnicode.bind(this),
    //this.pushSettingsApp.bind(this),    #手动注释此2行代码,即可解决问题
    //this.pushUnlock.bind(this),         #手动注释此2行代码,即可解决问题
    function (cb) {this.uiautomator.start(cb);}.bind(this),
    this.wakeUp.bind(this),
    this.unlock.bind(this),
    this.getDataDir.bind(this),
    this.setupCompressedLayoutHierarchy.bind(this),
    this.startAppUnderTest.bind(this),
    this.initAutoWebview.bind(this),
    this.setActualCapabilities.bind(this)
  ], function (err) {
    if (err) {
      this.shutdown(function () {
        this.launchCb(err);
      }.bind(this));
    } else {
      this.didLaunch = true;
      this.launchCb(null, this.proxySessionId);
    }
  }.bind(this));
};
    function (cb) {this.uiautomator.start(cb);}.bind(this),
    this.wakeUp.bind(this),
    this.unlock.bind(this),
    this.getDataDir.bind(this),
    this.setupCompressedLayoutHierarchy.bind(this),
    this.startAppUnderTest.bind(this),
    this.initAutoWebview.bind(this),
    this.setActualCapabilities.bind(this)
  ], function (err) {
    if (err) {
      this.shutdown(function () {
        this.launchCb(err);
      }.bind(this));
    } else {
      this.didLaunch = true;
      this.launchCb(null, this.proxySessionId);
    }
  }.bind(this));
};
Mac上使用Appium连接真机启动应用通常需要以下几个步骤: 1. **安装依赖**: - 安装Appium CLI:首先确保已安装Homebrew,然后通过`brew install appium`命令安装Appium服务器。 2. **配置环境**: - 配置`appium.json`:这是Appium的基本配置文件,你需要提供设备信息(如平台、设备名称、UDID等)、应用程序路径以及是否启用自动化权限。 ```json { "platformName": "iOS", "platformVersion": "14.6", "deviceName": "iPhone 12 Pro Max", "app": "/path/to/your/ios/app.ipa", "automationName": "XCUITest" } ``` 3. **启动Appium服务**: - 打开终端,运行`appium`命令,如果首次使用,可能会提示安装一些缺失的包,按照指示操作即可。 4. **连接真机**: - 如果你有Apple Developer账号并且启用了开发者模式,可以将手机连接到电脑上并通过USB连接。在手机上接受信任这个新的设备。 - 使用Appium的`connect`命令指定设备名称,如`appium --udid <your_device_udid>` 5. **启动应用**: - 启动Appium服务后,通过API调用或Appium客户端工具(如Appium Desktop)发送请求,告诉Appium开始测试目标应用。 ```sh curl -s -X POST "http://localhost:4723/wd/hub/session" \ --header 'Content-Type: application/json;charset=utf-8' \ -d '{"desiredCapabilities":{"platformName":"iOS","app":"/path/to/your/ios/app.ipa"}}' ``` 完成上述步骤后,你应该能看到Appium控制台输出新建立的会话,并且应用应该已经在真机启动了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值