眼前多少难甘事,自古男儿当自强。这篇文章主要讲述Appium环境的安装以及一路上的坑相关的知识,希望能为你提供帮助。
Appium环境的安装以及一路上的坑
第一步环境的安装
l
javaJDK的安装以及环境变量的配置这个我就不说了网上的教程全都是,搜一个安装一下吧
l
androidSDK的安装也是如此我是直接安装的Studio,直接就安装了SDK
l
Node.js安装下载,网址: http://nodejs.cn/download/
l
Appium的下载以及安装
网址: https://bitbucket.org/appium/appium.app/downloads/
第二步验证环境安装成功:
l
如图:

文章图片
第三步:环境安装遇到问题的排查:
l 执行命令appium-doctor,提示:android_home is not set
如图:

文章图片
l 解决办法:在环境变量配置Appium:
1) APPIUM_HOME D:\\ToolsInstall\\Appium\\node_modules\\appium
2) Path加入: D:\\ToolsInstall\\Appium\\node_modules\\.bin
第四步:运行一个Appium的实例
代码如下:
1 # coding:utf-8 2 import os 3 from selenium import webdriver 4 5 PATH = lambda p: os.path.abspath( 6os.path.join(os.path.dirname(__file__), p) 7 ) 8 desired_caps = { } 9 desired_caps[\'deviceName\'] = \'VBJ4C18607003439\'# adb devices查到的设备名 10 desired_caps[\'platformName\'] = \'Android\' 11 desired_caps[\'platformVersion\'] = \'8.1.0\' #android 系统版本 12 desired_caps[\'appPackage\'] = \'com.aerozhonghuan.serialporttool\'# 被测App的包名 13 desired_caps[\'appActivity\'] = \'com.aerozhonghuan.serialporttool.MainActivity\'# 启动时的Activity 14 driver = webdriver.Remote(\'http://localhost:4723/wd/hub\', desired_caps) 15 el = driver.find_element_by_id("com.aerozhonghuan.serialporttool:id/btn_heartbeat") 16 el.click() 17 print(\'第一个appium脚本运行成功了\') 18 driver.quit()
第五步:脚本中元素的定位工具
- 获取包名和启动activity
如图:

文章图片
2.获取页面id
Sdk自带工具: Android\\Sdk\\tools\\bin\\uiautomatorviewer.bat
如图:

文章图片
第六步:运行脚本过程中遇到的问题:
- 运行脚本过程中出现: A new session could not be created
b) 其次环境变量配置要使用android_home(我之前是sdk_home,修改后便不再报错)
c) 修改后页面正确显示应该显示如下图
如图:

文章图片
2.运行脚本的过程中报错:
"C:\\Users\\sxie\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -s emulator-5554 shell "ps \'uiautomator\'""
l 将\\Appium\\node_modules\\appium\\node_modules\\appium-adb\\lib\\adb.js的1033行左右修改为如下内容:
代码:
1 ADB.prototype.getPIDsByName = function (name, cb) { 2logger.debug("Getting all processes with \'" + name + "\'"); 3this.shell_grep("ps",name,function(err, stdout) { 4if (err) { 5logger.debug("No matching processes found"); 6return cb(null, []); 7} 8var pids = []; 9_.each(procs, function (proc) { 10var match = /[^\\t ]+[\\t ]+([0-9]+)/.exec(proc); 11if (match) { 12pids.push(parseInt(match[1], 10)); 13} 14}); 15if (pids.length !== procs.length) { 16var msg = "Could not extract PIDs from ps output. PIDS: " + 17JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs); 18return cb(new Error(msg)); 19} 20cb(null, pids); 21}); 22 }; 23 24 ADB.prototype.shell_grep = function(cmd,grep,cb){ 25if(cmd.indexOf("") === -1){ 26cmd = ""+ cmd + ""; 27} 28var execCmd = \'shell\' + cmd + \'| grep\' + grep; 29this.exec(execCmd, cb); 30 };
注:在环境的安装这一步我参考了乙醇的博客和一篇简书里的博客:
1) https://www.jianshu.com/p/3eddb5979c69?utm_campaign=maleskine& utm_content=note& utm_medium=seo_notes& utm_source=recommendation
2) http://www.cnblogs.com/nbkhic/p/3803883.html#undefined
【Appium环境的安装以及一路上的坑】
推荐阅读
- android五子棋游戏资讯阅读大学课程表地图拖拽检测小说搜索阅读app等源码
- android thread / udp socket sample
- Android开源库美团等APP城市选择
- android studio 清空缓存插件
- mybatis通用mapper源码解析
- DeepLearning.ai-Week4-Face Recognition for the Happy House
- Android系统的智能指针(轻量级指针强指针和弱指针)的实现原理分析
- Spring Boot 整合 Apache Solr 异常:Expected mime type application/octet-stream but got text/html 的解决.
- 实例化Flask的参数 及 对app的配置