Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Selenium monitor XHR requests

Tags:

ajax

selenium

Is there any way in Selenium to monitor the XHR requests from an application. I want to create a test where the test clicks a button then checks to see if a correct Ajax request is made.

Edit, I am using PHP Unit if that matters.

like image 241
Zachary K Avatar asked Feb 24 '11 10:02

Zachary K


1 Answers

You can capture the network traffic with Selenium and then try get what you need for that

Selenium s = new DefaultSelenium(...);
s.start("captureNetworkTraffic=true");
s.open("http://www.google.com");
String traffic = s.captureNetworkTraffic("json");

And then do your asserts by finding what you want in the traffic.

like image 71
AutomatedTester Avatar answered Oct 20 '22 21:10

AutomatedTester