获取Selenium请求,响应

时间:2010-09-06 09:44:07

标签: selenium selenium-rc

我尝试了以下代码,但未捕获req / response ??

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();

但在这种情况下没有req / response?

获得

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

2 个答案:

答案 0 :(得分:1)

captureNetworkTraffic将返回通过Selenium Remote Control的流量。当您调用它时,您将获得已发生的流量记录。这可能是你想要的,但如果你想测试JavaScript,可能值得使用像jsTestDriver这样的东西。

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

答案 1 :(得分:0)

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