开发者

Getting Selenium request, response

开发者 https://www.devze.com 2023-01-14 19:19 出处:网络
I tried the below code but req/response is not captured?? String trafficOutput = selenium.captureNetworkTraffic(\"xml\");

I tried the below code but req/response is not captured??

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");
selen开发者_StackOverflowium.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();

But no req/response in this case?

Getting value for

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


captureNetworkTraffic will return the traffic that has passed through Selenium Remote Control. When you call it you will get the log of traffic that has occured. This is probably what you want but if you want to be testing JavaScript it might be worth using something like jsTestDriver.

When you call getHTMLSource() it will return all the HTML that is on the page, or in the frame selenium is currently in, back to the test. You can then do other tests with the HTML.


I don't know if you still need an answer, but captureNetworkTraffic has to be called after you have done something. You have to do a selenium.start("captureNetworkTraffic=true") which will tell the server to start capturing, do all of your navigation and then call selenium.captureNetworkTraffic("xml"). Then you will have data, but from what I have seen it doesn't capture responses, just Requests.

0

精彩评论

暂无评论...
验证码 换一张
取 消