Running Tests

Preparing your app for test (iOS)

Test apps run on the simulator have to be compiled specifically for the simulator, for example by executing the following command in the Xcode project:

> xcodebuild -sdk iphonesimulator6.0//创建一个文件夹,存放.app文件

This creates a build/Release-iphonesimulator directory in your Xcode project that contains the .app package that you’ll need to communicate with the Appium server.

If you want, you can zip up the .app directory into a .zip file! Appium will unpack it for you. Nice if you’re not using Appium locally.

Preparing your app for test (Android)

Nothing in particular needs to be done to run your .apk using Appium. If you want to zip it up, you can.//没啥特别的。

 

Running your test app with Appium (iOS)

The best way to see what to do currently is to look at the example tests:

Node.js | Python | PHP | Ruby | Java

Basically, first make sure Appium is running:

node .

Then script your WebDriver test, sending in the following desired capabilities:

1 # python
2 {
3     'platformName': 'iOS',
4     'platformVersion': '7.1',
5     'deviceName': 'iPhone Simulator',
6     'app': myApp
7 }

1 // java
2 DesiredCapabilities capabilities = new DesiredCapabilities();
3 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
4 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
5 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
6 capabilities.setCapability(MobileCapabilityType.APP, myApp);

In this set of capabilities, myApp must be either://myApp参数必须满足下面条件

  • A local absolute path to your simulator-compiled .app directory or .zip
  • A url of a zip file containing your .app package
  • A path to one of the sample app relative to the appium install root

Using your WebDriver library of choice, set the remote session to use these capabilities and connect to the server running at port 4723 of localhost (or whatever host and port you specified when you started Appium). You should be all set now!

Running your test app with Appium (Android)

First, make sure you have one and only one Android emulator or device connected. If you run adb devices, for example, you should see one device connected. This is the device Appium will use for tests. Of course, to have a device connected, you’ll need to have made an Android AVD (see system setup (Windows, Mac, or Linux) for more information). If the Android SDK tools are on your path, you can simply run://保证只有一个安卓仿真器或者设备取得连接。

emulator -avd

And wait for the android emulator to finish launching. Sometimes, for various reasons, adb gets stuck. If it’s not showing any connected devices or otherwise failing, you can restart it by running://有时候虚拟机会无法取得连接,需要反复重启几次

adb kill-server && adb devices

Now, make sure Appium is running:

node .

There are several ways to start an Appium application (it works exactly the same as when the application is started via adb):

  • apk or zip only, the default activity will be launched ('app’ capability)
  • apk + activity ('app’ + 'appActivity’ capabilities)
  • apk + activity + intent ('app’ + 'appActivity’ + 'appIntent’ capabilities)

Activities may be specified in the following way:

  • absolute (e.g. appActivity: 'com.helloworld.SayHello’).
  • relative to appPackage (e.g. appPackage: 'com.helloworld’, appActivity=’.SayHello’)

If the 'appWaitPackage’ and 'appWaitActivity’ caps are specified, Appium automatically spins until those activities are launched. You may specify multiple wait activities for instance:

  • appActivity: 'com.splash.SplashScreen’
  • appPackage: 'com.splash’ appActivity: ’.SplashScreen’
  • appPackage: 'com.splash’ appActivity: ’.SplashScreen,.LandingPage,com.why.GoThere’

If you are not sure what activity are configured in your apk, you can proceed in one of the following ways://查看activity的方法

  • Mac/Linux: 'adb shell dumpsys window windows | grep mFocusedApp’
  • In the Ruby console: 'adb shell dumpsys window windows`.each_line.grep(/mFocusedApp/).first.strip’
  • In Windows terminal run 'adb shell dumpsys window windows’ and manually look for the mFocusedApp line.

Then script your WebDriver test, sending in the following desired capabilities:

1 # python
2 {
3     'platformName': 'Android',
4     'platformVersion': '4.4',
5     'deviceName': 'Android Emulator',
6     'app': myApp
7 }

1 // java
2 DesiredCapabilities capabilities = new DesiredCapabilities();
3 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
4 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4");
5 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
6 capabilities.setCapability(MobileCapabilityType.APP, myApp);

 

In this set of capabilities, myApp must be either://myApp参数必须满足下面条件

  • A local absolute path to your .apk or a .zip of it//绝对路径
  • A url of a zip file containing your .apk//url地址
  • A path to one of the sample app relative to the appium install root//相对于appium安装根目录的相对路径

Using your WebDriver library of choice, set the remote session to use these capabilities and connect to the server running at port 4723 of localhost (or whatever host and port you specified when you started Appium). You should be all set now!//使用自己选择的编程语言,设置session需要的capability,连接到指定的ip和端口。

Running your test app with Appium (Android devices < 4.2, and hybrid tests)

Android devices before version 4.2 (API Level 17) do not have Google’s UiAutomator framework installed. This is what Appium uses to perform the automation behaviors on the device. For earlier devices or tests of hybrid (webview-based) apps, Appium comes bundled with another automation backend called Selendroid.//低版本的安卓系统内没有安装谷歌的UiAutomator framework,所以没法运行appium。测试低版本设备和混合应用需要使用Selendroid工具。

To use Selendroid, all that is required is to slightly change the set of desired capabilities mentioned above, by adding the automationName capability and specifying the Selendroid automation backend. It is usually the case that you also need to use a . before your activity name (e.g., .MainActivity instead of MainActivity for your appActivity capability).//appActivity的值需要加一个点。

# python
{'automationName': 'Selendroid','platformName': 'Android','platformVersion': '2.3','deviceName': 'Android Emulator','app': myApp,'appPackage': 'com.mycompany.package','appActivity': '.MainActivity'
}

1 // java
2 DesiredCapabilities capabilities = new DesiredCapabilities();
3 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Selendroid");
4 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
5 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "2.3");
6 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
7 capabilities.setCapability(MobileCapabilityType.APP, myApp);
8 capabilities.setCapability(MobileCapabilityType.APP_PACKAGE: "com.mycompany.package");
9 capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY: ".MainActivity");

Now Appium will start up a Selendroid test session instead of the default test session. One of the downsides to using Selendroid is that its API differs sometimes significantly with Appium’s. Therefore we recommend you thoroughly read Selendroid’s documentation before writing your scripts for older devices or hybrid apps.

转载于:https://www.cnblogs.com/superbaby11/p/6062277.html

appium(3)-Running Tests相关推荐

  1. pytest Error running ‘tests‘: Can‘t run remote python interpreter: Can‘t get remote credentials for

    pycharm 退出/删除测试模式 (Pytest Doctest)~ Pycharm -> File -> settings -> tools -> python integ ...

  2. appium怎么测试ios_使用Appium,Cucumber和Serenity测试iOS应用程序—质量秘诀

    appium怎么测试ios iOS设备仍占据着移动市场的重要份额,占全球销售额的22%. 随着许多忠实的客户回来购买新的Apple产品,对iOS应用程序的需求也很大. 在本文中,我们将着眼于确保通过A ...

  3. Appium连接手机之Remote

    目录 1.remote 3.通用功能 4.安卓手机功能 5.IOS手机功能 1.remote appium连接手机是通过remote进行的,代码格式如下: 例:打开OPPO手机中自带的计算器 #cod ...

  4. Android多模块覆盖率,Android代码覆盖率初探—问题已解决!

    6月份到时候就要搞Android代码覆盖率,但是当时客户端即将改版,所以就耽搁了.在Android大哥的帮助下,终于完成了初步的代码覆盖率统计. 在github上找到了封装好的jacocoTestHe ...

  5. react vs 2017_我在React Europe 2017上学到了什么

    react vs 2017 by Nicolas Cuillery 由Nicolas Cuillery 我在React Europe 2017上学到了什么 (What I learned at Rea ...

  6. pytest测试框架--fixture的基本使用

    1.fixture的含义 fixture的目的是提供一个测试的基线,在此基线基础上,可以更可靠的进行重复测试. 2.fixture的优势 Pytest的fixture相对于传统的xUnit的setup ...

  7. 【UI 自动化测试平台解决方案】使用 Selenium IDE 录制 UI 自动化测试脚本

    UI 自动化录制:Selenium IDE 通过 Selenium IDE 录制并重播功能,可以快速创建UI 自动化测试用例. 可以直接在界面中点击执行. 也支持在命令行运行测试脚本: $ selen ...

  8. web/app unittest UI自动化测试框架

    框架结构 |-case 存放用例 |-------|_app |--------------|_appDemo.py 演示示例 |-------|_web |--------------|_webDe ...

  9. iOS自动化之WDA(WebDriverAgent)安装及踩坑(本文仅作经验记录,原WDA已经废弃,详细请看更新说明)

    Table of Contents 更新说明 一.WDA介绍 二.部署环境 三.安装步骤 1.安装基础依赖 2.下载WDA 3.执行bootstrap.sh 4.打开WebDriverAgent工程配 ...

最新文章

  1. 【转】使用genstring和NSLocalizedString实现App文本的本地化
  2. linux在所有文件中查找某一个字符
  3. DTC跨境电商白皮书
  4. iOS 16要来了:速度更快、UI改动明显?苹果WWDC大会或将在线下举行
  5. vue组件弹出框点击显示隐藏
  6. 冰点还原精灵Deep Freeze for mac 系统还原工具
  7. 给大家推荐一款冰点文档下载器(免登陆,免积分)下载百度,豆丁,畅享网,mbalib,hp009,mab.book118文库文档
  8. 一些收藏默认网站后缀
  9. Qt中qmake的INSTALLS变量将编译文件拷到运行目录
  10. 如何压缩图片?手把手教你三种图片缩小的办法
  11. 在SQL中修改数据库名称
  12. Sublime Text 3默认临时/缓存文件保存位置
  13. 语音控制垃圾分类箱的制作
  14. 骑行318、 2016.7.30
  15. 网易招财猫(内测版)
  16. Linux 平台下 误删 oracle 数据文件的恢复方法
  17. 换脸方法大汇总:生成对抗网络GAN、扩散模型等
  18. Linux环境问题--Miniconda安装python环境搭建
  19. Java基础匿名内部类
  20. 配置NW330USB无线网卡到FL2440

热门文章

  1. how to check unsolved conflicts file list in git merge?
  2. 取消chrome下input和textarea的聚焦边框
  3. 什么是百度竞价创意断句符
  4. Win7 Tensorflow 安装
  5. GCN代码超详解析Two-stream adaptive graph convolutional network for Skeleton-Based Action Recognition(一)
  6. ubuntu 10.04源 更新源列表
  7. Chrome浏览器不支持字体小于12px的解决办法
  8. freeRtos学习笔记 (5)事件组
  9. Dev C++ 中错误 stray 161' in program
  10. [YTU]_2624( B 结构体--统计投票)