• appium 3-31603调试分析方法


    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
        at AndroidDriver.executeCommand$ (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:249:13)
        at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
        at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
        at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
        at invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
        at enqueueResult (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
        at Promise (<anonymous>)
        at F (/usr/local/lib/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
        at AsyncIterator.enqueue (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
        at AsyncIterator.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
        at Object.runtime.async (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
        at AndroidDriver.executeCommand (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/build/lib/basedriver/driver.js:271:34)
        at AppiumDriver.executeCommand$ (/usr/local/lib/node_modules/appium/lib/appium.js:377:50)
        at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
        at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
        at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
        at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
        at <anonymous>
        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()+"	");
                    System.out.print("text: "+e.getText()+"	");
                    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()+"	");
                System.out.print("text: "+e66.getText()+"	");
                System.out.println("id: "+e66.getAttribute("resourceId"));
                Thread.sleep(500);
            }
            Thread.sleep(20000);
        }
    
  • 相关阅读:
    paper 89:视频图像去模糊常用处理方法
    paper 88:人脸检测和识别的Web服务API
    paper 87:行人检测资源(下)代码数据【转载,以后使用】
    paper 86:行人检测资源(上)综述文献【转载,以后使用】
    paper 85:机器统计学习方法——CART, Bagging, Random Forest, Boosting
    paper 84:机器学习算法--随机森林
    paper 83:前景检测算法_1(codebook和平均背景法)
    paper 82:边缘检测的各种微分算子比较(Sobel,Robert,Prewitt,Laplacian,Canny)
    paper 81:HDR成像技术
    paper 80 :目标检测的图像特征提取之(一)HOG特征
  • 原文地址:https://www.cnblogs.com/csj2018/p/9747493.html
Copyright © 2020-2023  润新知