Appium——unknown error: cannot activate web view

测试步骤:

1、 打开必应APP(如果出现欢迎界面和定位服务弹窗,需要点掉)

2、 点击搜索按钮

3、 输入JAVA到搜索框

4、 点击搜索网页

5、 观察显示搜索出来的结果是否含有java

6.   如果失败则截图

 

当用例运行为Fail,提示截图失败:cannot activate webview,这是由于切换到webview并查找到元素之后,没有切换到native导致的

[2016-08-12 17:03:14] [ERROR] [SearchPage_001_SearchDemo_Test] ,截图失败,原因:unknown error: cannot activate web view
(Session info: webview=33.0.0.0)
(Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 41 milliseconds
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'QH-20140222HXUT', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=F:\eclipseworkspace\appiumautotest\res\app\android\bing.apk, appPackage=com.microsoft.bing, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=192.168.26.101:5555, platform=LINUX, appActivity=com.microsoft.clients.bing.app.MainActivity, desired={app=F:\eclipseworkspace\appiumautotest\res\app\android\bing.apk, appPackage=com.microsoft.bing, appActivity=com.microsoft.clients.bing.app.MainActivity, platformVersion=4.4.4, automationName=Appium, sessionOverride=true, unicodeKeyboard=true, platformName=Android, deviceName=appium-test-avd, resetKeyboard=true}, platformVersion=4.4.4, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, browserName=Android, takesScreenshot=true, javascriptEnabled=true, sessionOverride=true, unicodeKeyboard=true, platformName=Android, resetKeyboard=true}]
Session ID: e50d2a5d-6ae2-46d7-b4de-86b3868a4464

 

在截图saveScreenShot(tr, driver)之前,切换到native

    public void onTestFailure(ITestResult tr) {
        super.onTestFailure(tr);
        logger.warn(tr.getName() + " 测试用例执行失败!");
        AppiumDriver<?> driver = (AppiumDriver<?>) testContext.getAttribute("APPIUM_DRIVER"); // 这里就是取driver
        driver.context("NATIVE_APP");
        saveScreenShot(tr, driver);
    }

再次运行,截图成功

 

 

posted @ 2016-08-12 16:57  hjhsysu  阅读(891)  评论(0编辑  收藏  举报