1.Appium Log

清晰记录了所有的请求和结果

 @Test
public void testDebug() throws InterruptedException,IOException{
MobileElement tiaoguo = (MobileElement) driver.findElementByXPath("//*[@text='跳过']");
FileUtils.copyFile(new File("tiaoguo.png"),tiaoguo.getScreenshotAs(OutputType.FILE));
Thread.sleep(15000);
}

IDE执行结果:提示方法没有实现



appium日志

通过log中可以获取更多的信息,如

在screenshot方法执行时,有URL链接,加上IP和port,访问就可以获取到更多信息。

127.0.0.1:4723/wd/hub/session/92fe82c7-02ac-4fca-a8da-eca08027f985/element/1/screenshot

可以看到/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:249:13中方法未实现

{"value":{"error":"unknown method","message":"Method has not yet been implemented","stacktrace":"NotYetImplementedError: Method has not yet been implemented\n    at AndroidDriver.executeCommand$ (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:249:13)\n    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)\n    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)\n    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)\n    at invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)\n    at enqueueResult (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)\n    at Promise (<anonymous>)\n    at F (/usr/local/lib/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)\n    at AsyncIterator.enqueue (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)\n    at AsyncIterator.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)\n    at Object.runtime.async (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)\n    at AndroidDriver.executeCommand (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/build/lib/basedriver/driver.js:271:34)\n    at AppiumDriver.executeCommand$ (/usr/local/lib/node_modules/appium/lib/appium.js:377:50)\n    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)\n    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)\n    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)\n    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:169:7)"}}
cat -n /usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js

2.getPageSource

界面的完整dom结构.xml文件

封装locate方法,加入异常处理,将获取的节点信息在编辑器中打开,检索控件。

    public WebElement locate(String locate){
try {
if (locate.matches("\\/\\/.*")) {
return driver.findElementByXPath(locate);
} else {
return driver.findElementById(locate);
}
}catch (org.openqa.selenium.NoSuchElementException EX){
System.out.println(locate);
System.out.println(driver.getPageSource());
return null;//没有返回值,代码会报错
}
}
@Test
public void TestDriver() throws InterruptedException{
Thread.sleep(5000);
//driver.findElementByXPath("//*[@text=\"允许\"]").click();
locate("//*[@text=\"允许\"]").click();
Thread.sleep(2000);
}

因为locate中返回的null,click找不到会因找不到控件报ava.lang.NullPointerException错误

3.脚本内调试

利用xpath获取所有匹配的元素 driver.findElementByXpath("//*")

    public WebElement locate(String locate) throws InterruptedException{
try {
if (locate.matches("\\/\\/.*")) {
return driver.findElementByXPath(locate);
} else {
return driver.findElementById(locate);
}
}catch (org.openqa.selenium.NoSuchElementException EX){
List<AndroidElement> lists = driver.findElementsByXPath("//*");
for(AndroidElement e:lists){
System.out.print("tag: "+e.getTagName()+"\t");
System.out.print("text: "+e.getText()+"\t");
System.out.println("id: "+e.getAttribute("resourceId"));
//System.out.println(e.getAttribute("contentDesc"));该属性有误,content-desc也不可用
Thread.sleep(500);
}
return null;
}
}

FAQ

1.tagName打印null

   @Test
public void TestDriver() throws InterruptedException{
Thread.sleep(5000);
List<AndroidElement> lists66 = driver.findElementsByXPath("//*");
for(AndroidElement e66:lists66){
System.out.print("tag: "+e66.getTagName()+"\t");
System.out.print("text: "+e66.getText()+"\t");
System.out.println("id: "+e66.getAttribute("resourceId"));
Thread.sleep(500);
}
Thread.sleep(20000);
}

appium 3-31603调试分析方法的更多相关文章

  1. Appium调试分析方法

    在使用appium做自动化测试的时候,发现用例报错,如何排查原因? 查看appium日志 appium日志大概是分为以下部分 culr命令调试 在理解appium协议的基础上,可以直接用shell发送 ...

  2. Appium Server 源码分析之启动运行Express http服务器

    通过上一个系列Appium Android Bootstrap源码分析我们了解到了appium在安卓目标机器上是如何通过bootstrap这个服务来接收appium从pc端发送过来的命令,并最终使用u ...

  3. Appium Android Bootstrap源代码分析之启动执行

    通过前面的两篇文章<Appium Android Bootstrap源代码分析之控件AndroidElement>和<Appium Android Bootstrap源代码分析之命令 ...

  4. Appium Server源码分析之作为Bootstrap客户端

    Appium Server拥有两个主要的功能: 它是个http服务器,它专门接收从客户端通过基于http的REST协议发送过来的命令 他是bootstrap客户端:它接收到客户端的命令后,需要想办法把 ...

  5. iOS 苹果官方 Crash文件分析方法 (iOS系统Crash文件分析方法)

    时间2013-08-20 12:49:20 GoWhich原文  http://www.gowhich.com/blog/view/id/343 苹果官方 Crash文件分析方法 (iOS系统Cras ...

  6. IDA 调试 Android 方法及简单的脱壳实现

    IDA 调试 Android 方法及简单的脱壳实现 标签: android原创逆向调试dalvik 2016-05-24 14:24 9286人阅读 评论(3) 收藏 举报 分类: 原创(25) An ...

  7. WinDbg调试分析 net站点 CPU100%问题

    WinDbg调试分析 asp.net站点 CPU100%问题 公司为了节省成本,最近有一批服务器降了配置,CPU从8核降到了2核.本身是小站点,访问量也不高,CPU总是会飙到100%而且可以一直持续几 ...

  8. 基于appium的常用元素定位方法

    一.元素定位工具 app应用的元素使用的是控件定位,不同于web网页,web网页定位元素通常使用的是F12工具,那么在app当中我们则要借助其它的工具来辅助定位. 1.uiautomatorviewe ...

  9. [Android]第一个cm调试分析

    0x00:写在前面  一直想入门Android安全,当时是极客大挑战出题的时候,被cx表哥甩锅强行去学了点android的开发,之后慢慢接触,感觉还是挺有意思的.cx表哥说先从逆向分析入门吧,之后可以 ...

随机推荐

  1. 关于CentOS 7 下的Oracle11g的proc编译器的一些常见问题

    1.proc编译器配置问题 在使用proc将.pc文件编译成.c文件时出现一堆的错误,网上的答案七杂八杂的,都没有解决我的问题. 如下是我在使用过程中的一些错误: 由于我可能比较笨,实在是受不了网上那 ...

  2. Java虚拟机运行时数据区

    运行时数据区程序计数器Java虚拟机栈本地方法栈Java堆(GC堆)方法区运行时常量池 运行时数据区 Java虚拟机在运行Java程序时,会将它所管理的内存划分为若干个内存区域.这些数据区域有各自的用 ...

  3. apsx 页面 if(!ispostback)其用法和作用 什么时候该用?

    一个页面第一次显示的时候 isPostBack=false 然后你在这个页面上点击按钮或其它东西提交的时候, isPostBack=true 一般这个函数里面的内容是指第一次打开这个页面的时候要做的事 ...

  4. 安装 Repo

    首先确保在当前用户的主目录下创建一个/bin目录(如果没有的话),然后把它(~/bin)加到PATH环境变量中 $ mkdir ~/bin $ PATH=~/bin:$PATH 也可以将 export ...

  5. antd中fomr中resetFields清空输入框

    1.如果没有initValue的情况下,直接使用resetFields可以清空文本框的值 2.如果是有initValue的情况下,直接使用resetFields方法会直接重置为initValue的值 ...

  6. Java中多线程

    引 如果对什么是线程.什么是进程仍存有疑惑,请先Google之,因为这两个概念不在本文的范围之内. 用多线程只有一个目的,那就是更好的利用cpu的资源,因为所有的多线程代码都可以用单线程来实现.说这个 ...

  7. asp.net mvc json数据缓存

    一些虚拟主机资源给的少, 如果直接用框架缓存, 估计内存就爆了吧, 如果不用缓存, 虚拟主机自带的数据库也是限制资源的, 访问多了就直接给timeout了, 用json文件形式缓存查询出来的数据, 虽 ...

  8. LUN挂载到Linux主机后,如何对磁盘进行分区

    将阵列上的LUN挂载到Linux主机后,如何对磁盘进行分区,方法参考https://www.ibm.com/developerworks/cn/linux/l-lpic1-v3-104-1/ fdis ...

  9. Loj 2008 小凸想跑步

    Loj 2008 小凸想跑步 \(S(P,p_0,p_1)<S(P,p_i,p_{i+1})\) 这个约束条件对于 \(P_x,P_y\) 是线性的,即将面积用向量叉积表示,暴力拆开,可得到 \ ...

  10. vue components

    https://github.com/vuejs/awesome-vue#components--libraries