【问题标题】:Getting Selenium request, response获取 Selenium 请求,响应
【发布时间】:2010-09-06 09:44:07
【问题描述】:

我尝试了以下代码,但未捕获请求/响应??

String trafficOutput = selenium.captureNetworkTraffic("xml");
selenium.type("q", "selenium rc");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");

selenium.open("/#hl=en&source=hp&q=selenium+rc&btnG=Google
        +Search&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=ff64793e1cab64b9");
selenium.click("//ol[@id='rso']/li[1]/h3/a/em");
selenium.waitForPageToLoad("30000");
selenium.click("link=Selenium Core");
selenium.waitForPageToLoad("30000");
selenium.click("link=our documentation");
selenium.waitForPageToLoad("30000");
selenium.click("link=Projects");
selenium.waitForPageToLoad("30000");
// assertTrue(selenium.isTextPresent("Results * for selenium rc"));

String resposneText = selenium.getHtmlSource();
DataOutputStream  dos = new DataOutputStream(new FileOutputStream("output", true));

System.out.println("value is-------- "+trafficOutput);
System.out.println("val is "+resposneText);

dos.writeBytes(trafficOutput);
dos.close();

但在这种情况下没有请求/响应?

获得价值

System.out.println("val is " + resposneText);

【问题讨论】:

    标签: selenium selenium-rc


    【解决方案1】:

    captureNetworkTraffic 将返回已通过 Selenium 远程控制的流量。当您调用它时,您将获得已发生的流量日志。这可能是您想要的,但如果您想测试 JavaScript,可能值得使用 jsTestDriver 之类的东西。

    当您调用 getHTMLSource() 时,它将返回页面上或 selenium 当前所在框架中的所有 HTML,返回给测试。然后,您可以使用 HTML 进行其他测试。

    【讨论】:

    • 问题是输出是空的,如果我想捕获所有点击请求/响应怎么办??
    • 这听起来像是您想在测试中使用 Wireshark。
    【解决方案2】:

    我不知道您是否还需要答案,但是在您完成某些操作后必须调用 captureNetworkTraffic。您必须执行 selenium.start("captureNetworkTraffic=true"),它会告诉服务器开始捕获,完成所有导航,然后调用 selenium.captureNetworkTraffic("xml")。然后您将获得数据,但据我所知,它不会捕获响应,只是请求。

    【讨论】:

    • 但它并没有给我每次点击
    猜你喜欢
    • 2017-04-26
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 2020-04-16
    • 2012-11-18
    相关资源
    最近更新 更多