zoukankan      html  css  js  c++  java
  • Selenium自动化获取Http报文信息并判断当前API状态

        public int loadingFinishedCount(WebDriver driver){
    LogEntries logs = driver.manage().logs().get("performance");
    // System.out.println(" List of log entries: ");
    int m=0;
    for(Iterator<LogEntry> it = logs.iterator(); it.hasNext();){
    LogEntry entry = it.next();
    try{
    JSONObject json = new JSONObject(entry.getMessage());
    JSONObject message = json.getJSONObject("message");
    // System.out.println(message);
    String method = message.getString("method");
    if(method!=null&&"Network.loadingFinished".equals(method)){
    ++m;
    }
    }catch (JSONException e){
    e.printStackTrace();
    }
    }
    return m;
    }

    public void pageLoadingFinished(WebDriver driver, int loadingFinishedCount){
    loadingFinishedCount(driver);
    // System.out.println(m);
    for(double i=0; i<=1000; i=i+0.1) {
    int n = loadingFinishedCount(driver);
    // System.out.println(n);
    if (n >=loadingFinishedCount) {
    break;
    }
    }
    }

    reference:https://stackoverflow.com/questions/6509628/how-to-get-http-response-code-using-selenium-webdriver-with-java
  • 相关阅读:
    eclipse历史版本下载地址
    注解@SuppressWarnings
    VB创建文件夹
    VB学习生成JavaBean
    C++下的强制转换类型
    Django扩展
    数据查询操作
    深入剖析C++多态、VPTR指针、虚函数表
    快速排序一步一步优化
    cookie与session
  • 原文地址:https://www.cnblogs.com/sushome/p/8670561.html
Copyright © 2011-2022 走看看