Appium入门自动化测试(十五)
前言
各位小伙伴们,好久没有更新了,因为近期比较忙。当然啦,忙里偷闲,看了一场《驴得水》的电影,一部比较荒诞的悲情喜剧故事。里面有首歌,听起来不错,分享给大家。 今天我们聊一聊使用Appium Grid,很多用过selenium 的同学应该比较熟悉Grid吧,这里需要指出,Appium所采用的Grid实质上还是selenium的那套Grid,只不过配置有所不同。
首先介绍一下grid ,selenium grid 是一种执行测试用例时使用的包含不同平台(windows、Linux、Android)的框架,并且这些平台是由一个中心点控制,这个中心点称之为HUB,而那些不同的平台称之NODE, 如下图所示:
使用Grid模式有什么好处?
-
case 比较多,需要并行跑
-
需要远程跑
-
需要case在不同平台跑
-
需要支持不同的设备或浏览器
-
实现分布式测试
如何使用Appium Grid?
分三步走:
-
启动hub
-
启动appium server as node
-
testng多线程跑case
第一步,启动hub
-
首先配置jdk
-
去selenium官网或 https://npm.taobao.org/mirrors/selenium 下载selenium standalone server 的jar
-
启动hub
Usage: java -jar selenium-server.jar [-interactive] [options]
-
使用默认启动 java -jar selenium-server-standalone-3.0.1.jar -role hub
其默认监听端口4444,默认IP localhost 如果要修改,只需要加-port 参数和-Hubhost
-
使用自定义端口和ip
java -jar selenium-server-standalone-3.0.1.jar -role hub -port 1235 -Hubhost 192.168.1.23
grid参数简介
-
-role 设置grid角色,有两种 hub 和node
-
-timeout 30 默认300,当没有收到node 交互的超时时间,超过会自动释放node的register。specify -timeout 0 and the hub will never release the node.
-
-maxSession 5 (5 is default) The maximum number of browsers that can run in parallel on the node.
-
-debug: puts you into debug mode, with more trace information and
diagnostics on the console
第二步,启动Appium Server As Node
-
appium作为node启动
appium --nodeconfig nodeconfig.json
这里就需要nodeconfig文件,在这里获取
https://github.com/appium/appium/blob/51285550eadb907e5cf90931a0c72ec7bc4a004d/docs/en/advanced-concepts/grid.md
或自定义ip端口
appium -a 192.168.1.52 -p 4724 --nodeconfig config.json
-
Once you start the appium server and it registers with the grid, you will see your device on the grid console page:
“http://<grid-ip-adress>:<grid-port>/grid/console"
http://localhost:4444/grid/console
在 node 的配置文件里,你需要定义 "browserName","version" 和 "platform"。 基于这些参数,selenium grid 会将你的测试定向到正确的设备上去。你还需要配置你的 host 详细信息和 selenium grid 的详细信息。你可以在 这里 找到详细的参数列表和描述信息。
config.json如下图:
第三步,使用testng执行case
首先需要在case中这样设置:
String url="http://localhost:4444/wd/hub";
driver = new AndroidDriver<MobileElement>(new URL(url), capabilities);
之后testng 配置多线程跑case即可。
问题与总结
目前还无法实现iOS 并发执行case。
也可以使用Jenkins Master/Slave 跑case,不再介绍。
最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走
这些资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助…….
如果你不想再体验一次自学时找不到资料,没人解答问题,坚持几天便放弃的感受的话,可以加入下方我的qq群大家一起讨论交流,里面也有各种软件测试资料和技术交流。