Difference Appium-Server and Appium-Desktop installation and set up of a collection of scripts to make Genymotion simulator based on the Python environment Appium

Appium-Server is configured, before Bowen has been introduced, Python-based environment to build Appium collection , so not described in detail here. The main difference today to share at Appium-Server and Appium desktop in use.

Share this blog how to use the simulator, Genymotion simulator installation script and production , but did not share how to make the code to run up the following detailed description.

When they talk about the code, you need to first understand the following keywords appium

Appium service Keyword

Keyword description Examples
automationName You want to use the automated test engine Appium  (default) or  Selendroid
platformName You want to test mobile phone operating system iOS Android , or  FirefoxOS
platformVersion Mobile phone operating system version For example:  7.1 4.4
deviceName Use of phone type or simulator type Simulator the iPhone the iPad Simulator the iPhone the Retina. 4-inch the Android Emulator the Galaxy S4 , and the like. On iOS, the keyword value must be using  instruments -s devices  one can use to get the device name. On Android, this key does not work at present.
app .ipa  or  .apk local absolute path or remote path to the file is located, may also include one of the two is a .zip . Appium will first try on a suitable real machine or emulator application path corresponding to the installation. For Android system, if you specify the app-package and App-Activity (specifically see below), then you can not specify App And will  browserName  conflict For example /abs/path/to/my.apk or http://myapp.com/app.ipa
browserName The need for automated testing of mobile phone web browser name. If the application is to automate testing, the value of the key should be empty. On iOS system may 'Safari', the system may Android 'Chrome', 'Chromium', or 'Browser'.
newCommandTimeout Set command timeout, unit: seconds. When the timeout period has not yet received a new command Appium assumes that the client exits and then automatically end the session. For example,  60
autoLaunch Whether Appium need to automatically install and launch applications. The default value is true truefalse
language (Sim / Emu-only)  set simulator  (simulator / emulator)  language. 如:  fr
locale (Sim / Emu-only) set simulator (simulator / emulator) locale. 如:  fr_CA
udid A physical device uniquely identifying the device connected Such as:  1ae203187fc012g
orientation (Sim / Emu-only) mode in a direction of starting the test set LANDSCAPE The  (lateral) or  PORTRAIT  (longitudinal)
autoWebview WebView converted directly to the context. The default value is  false , truefalse
Moresheth Do not reset application state before the session. The default value is false . truefalse
full reset (iOS) 删除整个模拟器目录。(Android) 通过卸载——而不是清空数据——来重置应用状态。在 Android 上,这也会在会话结束后自动清除被测应用。默认值 false truefalse

Android特有

关键字 描述 实例
appActivity 你要从你的应用包中启动的 Android Activity 名称。它通常需要在前面添加 . (如:使用.MainActivity 而不是 MainActivity) MainActivity.Settings
appPackage 你想运行的Android应用的包名

比如com.example.android.myApp,

 com.android.settings

appWaitActivity 你想要等待启动的 Android Activity 名称 SplashActivity
deviceReadyTimeout 设置等待一个模拟器或真机准备就绪的超时时间 5
androidCoverage 用于执行测试的 instrumentation 类。作为命令 adb shell am instrument -e coverage true -w 的-w 参数。

com.my.Pkg/

com.my.Pkg.instrumentation.MyInstrumentation

enablePerformanceLogging (仅适用于 Chrome 和 webview) 开启 Chromedriver 的性能日志。 (默认 false) truefalse
androidDeviceReadyTimeout 等待设备在启动应用后准备就绪的超时时间。以秒为单位。 如 30
androidDeviceSocket 开发工具的 socket 名称。只有在被测应用是一个使用 Chromium 内核的浏览器时需要。 socket 会被浏览器打开,然后 Chromedriver 把它作为开发者工具来进行连接。 如 chrome_devtools_remote
avd 需要启动的 AVD (安卓虚拟设备) 名称。 如 api19
avdLaunchTimeout 以毫秒为单位,等待 AVD 启动并连接到 ADB 的超时时间。(默认值120000) 300000
avdReadyTimeout 以毫秒为单位,等待 AVD 完成启动动画的超时时间。(默认值 120000) 300000
avdArgs 启动 AVD 时需要加入的额外的参数。 如 -netfast
useKeystore 使用一个自定义的 keystore 来对 apk 进行重签名。默认值 false true or false
keystorePath 自定义 keystore 的路径。默认: ~/.android/debug.keystore 如 /path/to.keystore
keystorePassword 自定义 keystore 的密码。 如 123456
keyAlias key 的别名 如 androiddebugkey
keyPassword key 的密码 如 123456
chromedriverExecutable webdriver 可执行文件的绝对路径 (如果 Chromium 核心提供了对应的 webdriver, 应该用它代替 Appium 自带的 webdriver) /abs/path/to/webdriver
autoWebviewTimeout 以毫秒为单位,等待 Webview 上下文激活的时间。默认值 2000 如 4
intentAction 用于启动 activity 的 intent action。 (默认值android.intent.action.MAIN)

如 android.intent.action.MAIN,

android.intent.action.VIEW

intentCategory 用于启动 activity 的 intent category。 (默认值android.intent.category.LAUNCHER)

如 android.intent.category.LAUNCHER,

android.intent.category.APP_CONTACTS

intentFlags 用于启动 activity 的标识 ( flags ) (默认值 0x10200000) 如 0x10200000
optionalIntentArguments 用于启动 activity 的额外 intent 参数 如 --esn <EXTRA_KEY>--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE>
stopAppOnReset 在使用 adb 启动应用前停止被测应用的进程 ( process ) 。如果被测应用是被另一个应用创建的,当这个参数被设定为 false 时,允许另一个应用的进程在使用 adb 启动被测应用时继续存活。默认值 true true 或 false
unicodeKeyboard 使用 Unicode 输入法。默认值false true 或 false
resetKeyboard 在设定了 unicodeKeyboard 关键字的 Unicode 测试结束后,重置输入法到原有状态。如果单独使用,将会被忽略。默认值 false true 或 false
noSign 跳过检查和对应用进行 debug 签名的步骤。只能在使用 UiAutomator 时使用,使用 selendroid 是不行。默认值 false true 或 false
ignoreUnimportantViews 调用 uiautomator 的函数setCompressedLayoutHierarchy()。由于 Accessibility 命令在忽略部分元素的情况下执行速度会加快,这个关键字能加快测试执行的速度。被忽略的元素将不能够被找到,因此这个关键字同时也被实现成可以随时改变的 *设置 ( settings ) * 。默认值 false true 或 false

iOS特有

关键字 描述 实例
calendarFormat (Sim-only) 为iOS的模拟器设置日历格式 如 gregorian (公历)
bundleId 被测应用的 bundle ID 。用于在真实设备中启动测试,也用于使用其他需要 bundle ID 的关键字启动测试。在使用 bundle ID 在真实设备上执行测试时,你可以不提供 app 关键字,但你必须提供 udid 。 如 io.appium.TestApp
udid 连接的真实设备的唯一设备编号 ( Unique device identifier ) 如 1ae203187fc012g
launchTimeout 以毫秒为单位,在 Appium 运行失败之前设置一个等待 instruments 的时间 比如: 20000
locationServicesEnabled (Sim-only) 强制打开或关闭定位服务。默认值是保持当前模拟器的设定 true 或 false
locationServicesAuthorized (Sim-only) 通过修改 plist 文件设定是否允许应用使用定位服务,从而避免定位服务的警告出现。默认值是保持当前模拟器的设定。请注意在使用这个关键字时,你同时需要使用 bundleId 关键字来发送你的应用的 bundle ID。 true 或者 false
autoAcceptAlerts 当 iOS 的个人信息访问警告 (如 位置、联系人、图片) 出现时,自动选择接受( Accept )。默认值 false true 或者 false
autoDismissAlerts 当 iOS 的个人信息访问警告 (如 位置、联系人、图片) 出现时,自动选择不接受( Dismiss )。默认值false true 或者 false
nativeInstrumentsLib 使用原生 intruments 库 (即关闭 instruments-without-delay ) true 或者 false
nativeWebTap (Sim-only) 在Safari中允许"真实的",非基于 javascript 的 web 点击 (tap) 。 默认值: false。注意:取决于 viewport 大小/比例, 点击操作不一定能精确地点中对应的元素。 true 或者 false
safariInitialUrl (Sim-only) (>= 8.1) 初始化 safari 的时使用的地址。默认是一个本地的欢迎页面 https://www.github.com
safariAllowPopups (Sim-only) 允许 javascript 在 Safari 中创建新窗口。默认保持模拟器当前设置。 true 或者 false
safariIgnoreFraudWarning (Sim-only) 阻止 Safari 显示此网站可能存在风险的警告。默认保持浏览器当前设置。 true 或者 false
safariOpenLinksInBackground (Sim-only) Safari 是否允许链接在新窗口打开。默认保持浏览器当前设置。 true 或者 false
keepKeyChains (Sim-only) 当 Appium 会话开始/结束时是否保留存放密码存放记录 (keychains) (库(Library)/钥匙串(Keychains)) true 或者 false
localizableStringsDir 从哪里查找本地化字符串。默认值 en.lproj en.lproj
processArguments 通过 instruments 传递到 AUT 的参数 如 -myflag
interKeyDelay 以毫秒为单位,按下每一个按键之间的延迟时间。 如 100
showIOSLog 是否在 Appium 的日志中显示设备的日志。默认值false true 或者 false
sendKeyStrategy 输入文字到文字框的策略。模拟器默认值:oneByOne(一个接着一个) 。真实设备默认值:grouped (分组输入) oneByOnegrouped 或setValue
screenshotWaitTimeout 以秒为单位,生成屏幕截图的最长等待时间。默认值: 10。 如 5
waitForAppScript 用于判断 "应用是否被启动” 的 iOS 自动化脚本代码。默认情况下系统等待直到页面内容非空。结果必须是布尔类型。 例如 true;,target.elements().length > 0;$.delay(5000); true;

Appium-Server

了解了appium的关键字,再来看代码里面的参数,示例如下:

desired_caps = {
    'platformName': 'Android',
    'platformVersion': '4.4.4',
    'deviceName': 'S5',
    'appPackage': '',   #包名
    'appActivity': '',    #app入口
    'udid': '192.168.66.101:5555',  # genymotion设备
    'noReset': 'true',
    'unicodeKeyboard': 'True',
    'resetKeyboard': 'True',
}

这些参数,前六个参数都是必须的,后三个参数可视自己的配置使用。还有更多的参数,看上述的appium关键字即可,也可以参照该文档:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md

参数定位

代码示例如下:

account = driver.find_element_by_id('id/rel_content')
account.find_element_by_id('id/edit_acount')
driver.press_keycode(61)
print("换行操作")

if driver.find_element_by_id('id/img_clear_acount'):
    clr_account = driver.find_element_by_id('id/img_clear_acount').click()
    print("账号清除成功")

account.send_keys('10086')
print("账号输入完毕")
time.sleep(2)

driver.press_keycode(61)
print("换行操作")

password = driver.find_element_by_id('id/rel_content')
password.find_element_by_id('id/edit_pass')
password.send_keys('123456')
print("密码输入完毕")
driver.find_element_by_xpath('//android.widget.TextView[@text="登 录"]').click()
print("点击登录按钮")

上述代码中,使用到的常规定位方式,id,xpath,还有更多的操作api,可参见这篇博文,里面总结的很详细,Appium Python API 中文版

运行appium

代码讲述完毕,那又如何使用appium来运行代码呢?步骤如下:

1.配置appium

打开appium,对参数进行配置,先配置dvices name,获取devices name的方式使用命令adb devices即可,配置如下

2.服务设置

将server address配置为本地ip即可,端口默认为4723,配置如下:

3.启动appium

点击appium界面上的启动按钮,出现如下界面,则说明启动成功。

服务启动成功,则可以运行代码了,在模拟器中可查看到对应的操作。运行代码时,会自动在真机或模拟器上安装两个app,appium settings和unlock,自动安装的,可以忽略。

上述就是Appium-Server使用的配置了,但Appium-Server有一两年没有更新了。Windows版在2015年底止步于的 AppiumForWindows_1_4_16_1.zip 。

于是,新的工具 Appium-desktop 来了! 它来继续 Appium-Server的使命。当然,Appium-Server当前仍然是可用的。接下来则来说说Appium-desktop。

Appium-desktop

下载安装

下载地址: https://github.com/appium/appium-desktop/releases/tag/v1.13.0,依照各自需要的版本下载即可。比如windows版,将下载下来的.exe文件,双击安装即可。

安装配置

在安装好了之后,用appium-doctor来检查是否配置成功,但新版的appium是没有doctor文件的,所以需要通过npm下载并安装,命令如下:

npm install -g appium-doctor

输入命令后,出现如下图所示界面:

安装好了之后,再使用如下命令检查新版的appium是否安装成功,命令如下:

appium-doctor

输入命令后,出现如下界面,则说明安装成功:

启用配置

1.启动服务

打开安装好的appium,出现如下界面

连接本机的话,host可以不配置,就用默认的0.0.0.0,端口也用默认的4723,直接点击start server v1.13.0按钮,出现如下界面,说明服务启动成功

2.新建连接

new session window,进入到如下页面:

输入参数如下:

参数配置好了之后,最好是保存下,避免下次使用的时候,需要再次输入。

3.元素定位

点击start session按钮后,进入到如下页面:

在该页面就可以进行元素定位了,元素定位的详细api,可以参见之前提到的那篇api文档。

将写好的代码,在编译工具中执行即可,便可在模拟器或真机上看到效果,效果图就不上了。

问题总结

1.appium-desktop可支持安卓高版本

在模拟器那一篇博文中,我说我使用模拟器的原因,就是因为老版的appium不支持android8及以上的版本,今天在使用appium-desktop时,发现可以直接使用appium desktop定位元素。

2.'unicodeKeyboard' must be of type boolean; 'resetKeyboard' must be of type boolean

该问题是appium版本的问题,新版本unicodeKeyboard、resetKeyboard是布尔类型,将True的双引号去掉,就可以了,如:

'unicodeKeyboard': True,

'resetKeyboard': True,

以上就是我个人在使用上,对appium-server和appium-desktop认知的区别了,具体其他的区别,还待深入使用后发现。今天分享就到这了,有描述有误的地方,欢迎批评指正。祝大家节日快乐。

 

本文仅代表作者观点,系作者@温一壶清酒发表。
欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
文章出处:http://www.cnblogs.com/hong-fithing/

Guess you like

Origin www.cnblogs.com/hong-fithing/p/11615628.html