App UI自动化测试之Mac环境安装appium

依赖环境:

  • java
✗ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
  • python
$python --version
Python 3.6.4
  • node.js
$node -v
v10.6.0
如果未安装,通过以下命令安装:
$brew install node
  • android sdk、环境配置(网上很多,这里不复述)
$adb
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
Installed as /Users/xxx/Android/sdk/platform-tools/adb

global options:
 -a         listen on all network interfaces, not just localhost
 -d         use USB device (error if multiple devices connected)
 -e         use TCP/IP device (error if multiple TCP/IP devices available)
 -s SERIAL
...
  • Appium

安装Appium有两种方式,
1. 直接去官网下载dmg安装包
2. 命令行安装(也是官方提供)(安装过程有点慢,耐心等待)

> brew install node      # get node.js
> npm install -g appium  # get appium
> npm install wd         # get appium client
> appium &               # start appium

其中,安装appium时,即执行npm install -g appium,会出现一些警告warning,忽略即可。类似如下

/Users/xxx/.node-gyp/10.6.0/include/node/v8.h:7354:3: note: 'GetCpuProfiler' has been explicitly marked deprecated here
  V8_DEPRECATED("CpuProfiler should be created with CpuProfiler::New call.",
  ^
/Users/xxx/.node-gyp/10.6.0/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated))
                            ^
../src/heapdump.cc:106:23: warning: 'Utf8Value' is deprecated [-Wdeprecated-declarations]
    String::Utf8Value filename_string(args[0]);
                      ^
/Users/xxx/.node-gyp/10.6.0/include/node/v8.h:2851:5: note: 'Utf8Value' has been explicitly marked deprecated here
    V8_DEPRECATED("Use Isolate version",
    ^

安装完毕,测试是否安装成功。

$appium -v
1.8.1

启动appium服务

appium或者appium &

$appium  
(node:39581) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[Appium] Welcome to Appium v1.8.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

关闭appium服务。

  • 如果使用appium启动服务,则直接cmd+c即可强制关闭服务:
$appium
(node:40425) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[Appium] Welcome to Appium v1.8.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

^C[Appium] Received SIGINT - shutting down
  • 如果使用appium &启动服务,cmd+c是无效的,可以看到和上边方式的区别,不会收到shut down指令,即Received SIGINT - shutting down。此时服务仍在运行,如果重新启动,则报错,如下:
$appium &         
[1] 40481
$ (node:40481) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[Appium] Welcome to Appium v1.8.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

$appium
(node:40574) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[Appium] Welcome to Appium v1.8.1
[HTTP] Could not start REST http interface listener. The requested port may already be in use. Please make sure there is no other instance of this server running already.
Fatal Error: listen EADDRINUSE 0.0.0.0:4723
    at Server.setupListenHandle [as _listen2] (net.js:1335:14)
    at listenInCluster (net.js:1383:12)
    at doListen (net.js:1509:7)
    at process._tickCallback (internal/process/next_tick.js:63:19)

此时,需要强制kill服务,使用ps获取appium服务进程,然后kill

$ps | grep appium
40481 ttys002    0:02.00 node /usr/local/bin/appium
40668 ttys002    0:00.00 grep --color appium
$kill -9 40481
[1]  + 40481 killed     appium

更多博客,请关注
https://blog.youkuaiyun.com/rflyee/
https://www.jianshu.com/u/ff8bcd76e5a7

### 设置Appium环境用于APP自动化测试 #### 配置要求 为了成功运行基于Appium的应用程序自动化测试,需满足一系列配置需求。设备方面,支持真实移动设备以及模拟器/仿真器;操作系统上,对于Android而言,推荐使用Windows或Mac OS作为开发平台,并确保已安装Java Development Kit (JDK),因为许多构建工具和服务都依赖于它。 #### 安装步骤及所需依赖项 1. **安装Node.js** Appium服务器由JavaScript编写并依靠Node.js来执行。因此,在任何平台上部署前都需要先下载并安装最新稳定版本的Node.js[^1]。 2. **安装Appium Server** 可通过命令行工具npm全局安装Appium server。打开终端窗口输入`npm install -g appium@latest`完成安装过程。这一步骤会自动处理所有必要的依赖关系,使用户能够专注于后续操作而非解决兼容性问题。 3. **启动Appium服务** 使用命令`appium`可以在本地机器上启动默认端口上的Appium服务实例。如果希望指定不同参数,则可以附加更多选项至上述指令之后。值得注意的是,在利用检查器工具之前务必确认该服务已经正常开启。 4. **准备安卓环境(仅限Android)** 对于打算针对Android应用开展工作的开发者来说,还需要额外几步准备工作: * 下载并设置好Android SDK; * 将ANDROID_HOME环境变量指向SDK路径下; * 添加adb、emulator等常用二进制文件所在的目录到系统的PATH中去; 5. **获取页面元素信息** 借助Appium Inspector这类可视化调试工具可以帮助识别应用程序UI组件的信息以便更方便地编写定位表达式。当尝试访问特定控件时,这些数据显得尤为重要。启动此功能的前提条件同样是保证后台存在可用的服务进程。 6. **定义启动活动(Activity)** 当涉及到跨多个应用程序的操作场景时,可能需要明确指出要激活的目标activity名称。例如,在某些情况下可以通过设定desired capabilities里的`appActivity`属性值为待测软件包内的某个具体入口点来进行切换[^2]。 7. **探索Web视图中的DOM结构** 如果目标应用程序包含了WebView组件的话,那么还可以进一步深入研究其内部HTML文档对象模型(DOM)层次。此时可借助浏览器开发者控制台提供的inspect特性实现这一目的[^3]。 8. **Xposed框架集成**(非必需) 虽然不是强制性的组成部分之一,但在某些特殊场合下可能会用到像Xposed这样的第三方插件扩展机制。它们允许修改现有系统行为而无需重新编译源码,从而简化了部分复杂交互逻辑的实现难度。 ```bash # Node.js安装示例(Linux/MacOS) sudo apt-get update && sudo apt-get install nodejs npm # Debian/Ubuntu brew install node # macOS with Homebrew # Appium Server安装 npm install -g appium@latest # 启动Appium Service appium & ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值