• Appium混合应用测试


    Appium测试混合应用

    混合应用即是原生应用中间混着html页面,需要在两种类型的页面之间跳转。

    测试Android混合应用

    前期设置

    1. 4.4以下版本使用automationName:Selendroid
    2. 4.4及其以上的版本使用automationName:Appium
    3. 需要设置webview的debug模式为true,默认是false

    元素定位

    Selendroid模式:selendroid inspector
    Appium模式:chrome://inspect

    代码示例

    设置webview的debug模式,需要插入在android源码当中:

    if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.KITKAT){
        WebView.setWebContentsDebuggingEnabled(true);
    }
    

    Selendroid代码示例,appium模式替换automationName:Appium即可:

    //配置 webdriver 并启动 webview 应用。
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability("device", "Selendroid");
    desiredCapabilities.setCapability("app", "/path/to/some.apk");  
    URL url = new URL("http://127.0.0.1:4723/wd/hub");
    RemoteWebDriver remoteWebDriver = new RemoteWebDriver(url, desiredCapabilities);
    
    // 切换到最新的web视图
    remoteWebDriver.switchTo().window("WEBVIEW");
    
    //在 guinea-pig 页面用 id 和 元素交互。
    WebElement div = remoteWebDriver.findElement(By.id("i_am_an_id"));
    Assert.assertEquals("I am a div", div.getText()); //验证得到的文本是否正确。
    remoteWebDriver.findElement(By.id("comments")).sendKeys("My comment"); //填写评论。
    
    //离开 webview,回到原生应用。
    remoteWebDriver.switchTo().window("NATIVE_APP");
    
    //关闭应用。
    remoteWebDriver.quit();
    

    测试iOS混合应用

    前期设置

    1. 模拟器和本地应用相同
    2. 测试真机时需要ios_webkit_debug_proxy工具
    brew install ios_webkit_debug_proxy
    
    ios_webkit_debug_proxy -c [udid]:27753 -d
    

    元素定位

    使用Safari或者chrome的开发者工具

    代码示例

    //配置 webdriver 并启动 webview 应用。
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability("device", "iPhone Simulator");
    desiredCapabilities.setCapability("app", "http://appium.s3.amazonaws.com/WebViewApp6.0.app.zip");  
    URL url = new URL("http://127.0.0.1:4723/wd/hub");
    RemoteWebDriver remoteWebDriver = new RemoteWebDriver(url, desiredCapabilities);
    
    // 切换到最新的web视图
    for(String context : driver.getContextHandles()){
    	if (context.contains("WEBVIEW")) {
    		driver.context(context);
    	}
    }
    
    //在 guinea-pig 页面用 id 和 元素交互。
    WebElement div = remoteWebDriver.findElement(By.id("i_am_an_id"));
    Assert.assertEquals("I am a div", div.getText()); //验证得到的文本是否正确。
    remoteWebDriver.findElement(By.id("comments")).sendKeys("My comment"); //填写评论。
    
    //离开 webview,回到原生应用。
    remoteWebDriver.executeScript("mobile: leaveWebView");
    
    //关闭应用。
    remoteWebDriver.quit();
    

    参考官方文档

  • 相关阅读:
    解决svn中文乱码的问题
    C#使用SQLite出错:无法加载 DLL“SQLite.Interop.dll”,找不到指定的模块
    手把手教你使用C#操作SQLite数据库,新建数据库,创建表,插入,查询,删除,运算符,like
    c# 串口SerialPort
    spy++使用指南
    FindWindow用法
    其他信息: 线程间操作无效: 从不是创建控件“控件名”的线程访问它。
    SVN设置必须锁定
    利用webBrowser获取页面iframe中的内容
    谨慎注意WebBrowser控件的DocumentCompleted事件
  • 原文地址:https://www.cnblogs.com/xiaomingtx/p/5619287.html
Copyright © 2020-2023  润新知