Is there any reason why a Selenium test should always fail unless the development tools in Internet Explorer (F12) are turned on?
A page that performs an Ajax call periodically is being tested and fails because no calls are being made. But the test runs successfully when I open the F12 Dev tools.
When the page is accessed manually, the everything works as expected, too. I've tried different versions of the IE WebDriver and the MS Update for WebDriver. But nothing helps. I suspect it is an issue with Selenium somehow intercepting the AJAX call.
Here is a simple HTML and Selenium test that fails with Internet Explorer 11 and Selenium IEServerDriver 2.44.0
<html>
<body>
<h1>Test</h1>
<div id="count">count placeholder</div>
<div id="thediv">div placeholder</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var count = 1;
document.getElementById("thediv").innerHTML = "Test";
$(document).ready(function () {
doIt();
});
function doIt() {
$.ajax({url: "http://localhost:8000/my_app/counter", success: function (result) {
$("#thediv").html(result);
$("#count").html(count);
count++;
}});
setTimeout(function(){
doIt();
}, 1000);
}
</script>
</body>
</html>
And the test:
@Test
public void runTest() throws Exception {
final InternetExplorerDriver internetExplorerDriver = new InternetExplorerDriver();
internetExplorerDriver.get("http://localhost:8000/test.html");
Assert.assertTrue(internetExplorerDriver.findElement(By.id("thediv")).getText().contains("1"));
Thread.sleep(5000);
Assert.assertTrue(Integer.parseInt(internetExplorerDriver.findElement(By.id("thediv")).getText()) > 1);
internetExplorerDriver.quit();
}
The service just returns a number and it increases by 1 every time it is called. It sets the returned value to the #thediv. This test fails because the subsequent calls are not being made (the first one is). I used a program called Fiddler to check this. When this test is run with the Development Tools ON (F12) it works and the service is being called periodically. The second div #counter is being updated just fine.