zoukankan      html  css  js  c++  java
  • appium之Context切换

    原文地址http://blog.csdn.net/Mandypan/article/details/51396302

    Context切换
    driver.getContextHandles();//获取页面的context
    driver.context("WEBVIEW");
    driver.context("NATIVEAPP");


    eg:
    public void GetResource_Android(){
    set<String> contextSet=wd.getContextHandles();
    for(String context : contextSet){
    System.out.println(context);
    }

    }

    Context切换
    driver.getContextHandles();
    driver.context("WEBVIEW");
    driver.context("NAVTIVEAPP");


    查看当前所有的窗口:
    Set<String> contextNames=driver.getContextHandles();
    System.out.print(contextNames);
    切换到Webview
    <pre name="code"class="java">driver.context("WEBVIEW");
    driver.findElementByID("wd");
    切换到NativeAPP
    <pre name="code" class="java">driver.context("NATIVE_APP");


    demo
    /**
    * Switch to NATIVE_APP or WEBVIEW
    * @param sWindow window name
    */
    private void switchToWindow(String sWindow) {
           LogManager.getLogger(this.getClass()).info("Swith to window: " + sWindow);
           Set<String> contextNames = driver.getContextHandles();
           LogManager.getLogger(this.getClass()).info("Exists windows: " + contextNames.toString());
           for (String contextName : contextNames) {
                  if (contextName.contains(sWindow)) {
                          driver.context(contextName);
                          break;
                   }
           }
    }

    switchToWindow("WEBVIEW_com.test.android");
    switchToWindow("NATIVE_APP");

    页面切换

    String pWindUrl = driver.getCurrentUrl();  获取当前窗口的url
    //跳至新打开的窗口
    if (driver.getWindowHandles().size() != 2) {fail(); }
    for (String handle : driver.getWindowHandles()) {
          driver.switchTo().window(handle);  遍历跳转到每一个打开的窗口
          if (driver.getCurrentUrl().equals(pWindUrl)){  如果这个窗口的url是pWindUrl则表明是当前的窗口
                driver.close(); //关闭当前窗口
          }

    }

  • 相关阅读:
    移动采编app
    分布式自动化测试
    appium --log-timestamp > appium.log
    处理安卓的弹窗
    Sublime text3修改tab键为缩进为四个空格
    安卓自动化测试——rf
    敏捷软件开发
    photoshop怎么旋转图片
    thinkPHP5.0模型实现软删除
    thinkPHP5.0数据查询表达式生成技巧
  • 原文地址:https://www.cnblogs.com/111testing/p/7502951.html
Copyright © 2011-2022 走看看