1.1Appium日志分析
启动APPium服务:
这里配置的是雪球app:
配置如下:
{
"platformName": "Android",
"platformVersion": "10",
"deviceName ": "ELE-AL00",
"appPackage": "com.huawei.calculator",
"appActivity": ".Calculator"
}
启动APPium服务器成功
[Appium] Welcome to Appium v1.17.1
Appium REST http interface listener started on 0.0.0.0:4723
post请求,数据是自己配置的其他的是默认的,将desiredCapabilities参数全部传递给服务器
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"appActivity":".view.WelcomeActivityAlias","appPackage":"com.xueqiu.android","deviceName ":"ELE-AL00","platformName":"Android","platformVersion":"10","newCommandTimeout":0,"connectHardwareKeyboard":true}}
[MJSONWP] Calling AppiumDriver.createSession() with args: [{"appActivity":".view.WelcomeActivityAlias","appPackage":"com.xueqiu.android","deviceName ":"ELE-AL00","platformName":"Android","platformVersion":"10","newCommandTimeout":0,"connectHardwareKeyboard":true},null,null]
[BaseDriver] Event 'newSessionRequested' logged at 1603543722539 (20:48:42 GMT+0800 (中国标准时间))
//创建session
[Appium] Appium v1.17.1 creating new AndroidUiautomator2Driver (v1.44.2) session
[BaseDriver] Creating session with MJSONWP desired capabilities: {
[BaseDriver] "appActivity": ".view.WelcomeActivityAlias",
[BaseDriver] "appPackage": "com.xueqiu.android",
[BaseDriver] "deviceName ": "ELE-AL00",
[BaseDriver] "platformName": "Android",
[BaseDriver] "platformVersion": "10",
[BaseDriver] "newCommandTimeout": 0,
[BaseDriver] "connectHardwareKeyboard": true
[BaseDriver] }
//生成sessionid
[BaseDriver] Session created with session id: 1ce5e6a4-e24c-4bb6-b19c-e0c86afcd5f9
检查查看adb
[ADB] Using 'adb.exe' from 'C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe'
//通过adb devices查看当前连接的设备
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...
[ADB] Connected devices: [{"udid":"8KE5T19711002800","state":"device"}]
[AndroidDriver] Looking for a device with Android '10.0.0'
[ADB] Setting device id to 8KE5T19711002800
[ADB] Getting device platform version
之后会检测手机是否安装APPium Setting APP是否安装
检测手机端是否存在雪球app,之后会通过Bootstrap.jar来建立Appium服务器和手机端的通信,Bootstrap.jar负责运行测试命令。
1.2常见定位方式:
- Name属性 findElementByName("Text控件")//该方法已经取消
- Id属性 findEle,mentById("resource-id属性")
- ClassName属性 findElementByClassName("class属性")
- AccessibilityId属性 findElementByAccessibilityId("content-desc属性")
- 通过Xpath识别 findElement(By.xpath("路径"))
xpath识别分为绝对路径和相对路径:
绝对路径使用/ 如/html/body/div[1]/nav/div[1]/div[1]/div/a[2]
相对路径使用//如://*[@id="app"]/nav/div[1]/div[1]/div/a[2]
这里讲解其他的Xpath使用方法:
使用contains关键字进行定位 driver.findElement(By.xpath("//android.widget.Button[contains(@text,'show progress')]"));这句话是寻找页面中text属性包含show progress这个单词的所有android.widget.Button元素
使用start-with关键字进行定位driver.findElement(By.xpath("//android.widget.Button[start-with(@text,''show progress')]"))
使用text关键字进行定位driver.findElement(By.xpath("//*[text()=''show progress]"))
还有UIAutomator cssSelector LinkText PartialLinkText 等这里主要是针对webapp测试的
Uiaotomator:
text文本定位:
new UiSelector().text("text文本")
new UiSelector().textContains("包含text文本")
new UiSelector().textStartsWith("以text文本开头")
new UiSelector().textMatches("正则表达式")
resourceId id定位
new UiSelector().resourceId("id")
class属性
new UiSelector().className("className")
contenet-des属性
new UiSelector().description("contenet-des属性")
本文详细解读了如何通过Appium启动Android应用,并介绍常见的定位元素方法,包括XPath、UIAutomator和CSS选择器。重点讲解了XPath的关键字使用和Uiautomator2的选择器实例。
2115

被折叠的 条评论
为什么被折叠?



