3

I'm attempting to use grunt-contrib-qunit to run a pre-existing suite of qunit tests (testing parsing of ajax request results) in headless mode with Phantom on Windows 8.

The tests complete fine in these scenarios:

  • When the remote page is accessed directly from any browser without Fiddler or another proxy running
  • When Phantom runs the tests from a command prompt with Fiddler open and running

Oddly if I don't have fiddler open monitoring the requests, the AJAX requests I'm testing never seem to initialize. I've checked my default IE LAN Settings and there is no proxy enabled, I've also tried flipping the Auto Detect Settings checkbox there and no change.

Any thoughts??

Details on my setup:

  • Node v0.10.4
  • Latest grunt-contrib-qunit
  • Windows 8
  • QUnit is divided into 4 or 5 modules with setup and teardown tasks in some modules, asynchronous and synchronous tests, and autorun is set to false.

Update:

If I turn off the options in Fiddler for "Reuse client connections" and "Reuse connections to servers" I seem to get the same failure behavior as when Fiddler is off. This led me to believe its a problem with connections being closed prematurely, so I tried setting a custom keep-alive header -- but it still errors out.

Update 2:

I still question this because the page itself loads fine, but the requests fail, but it looks like this could possibly be related to NTLM authentication. Fiddler might somehow facilitating the handshake. There is an open issue for NTLM on the Phantom github page.

Update 3:

After continued troubleshooting this evening it looks like the issue is only with authentication on POST requests. GET requests seem to work fine. I'm working around this for now by routing all requests through an ASHX handler and thus dropping the auth component. Only thing I had to change was to disable web security on phantom to allow the cross-domain requests through.

GotDibbs
  • 3,068
  • 1
  • 23
  • 29
  • Just noticed we had overridden window.alert in a couple of the tests, but changing that doesn't seem to have helped. – GotDibbs May 05 '13 at 22:26
  • Updating from QUnit v1.1 to v1.4 fixed part of my issue without timeouts on completion (still only using Fiddler though). – GotDibbs May 06 '13 at 03:02
  • I know that this isn't an answer, and I'm not saying you should do things one way or another, but for all of my JS tests that use ajax I'll use [Mockjax](https://github.com/appendto/jquery-mockjax) to fake those (thus not relying on my server being up or present at all). Just something to think about. – Jordan Kasper May 29 '13 at 15:01
  • @jakerella Thanks for your thoughts. We've thought about doing that before, but due to fact that we don't own the API code we're interfacing with, we'd prefer to have the requests actually execute against a live server. – GotDibbs May 29 '13 at 15:15

1 Answers1

0

I was going to say you need to turn off security, which is done by passing --web-security=no to phantomjs. This will sort out the CORS issues. However I see in your Update#2 that you've already discovered this.

For the POST authentication problem, I blogged about the workaround here: http://darrendev.blogspot.jp/2013/04/phantomjs-post-auth-and-timeouts.html

I've heard the most recent version has fixed this, so upgrading might be the actual answer?

BTW, be careful with auth in PhantomJS, as the auth details are sent on all requests. E.g. if your test page fetches JQuery from a CDN, the CDN will be sent your authentication headers. (SlimerJS has some new features in place for getting around this; AFAIK PhantomJS does not yet.)

Darren Cook
  • 27,837
  • 13
  • 117
  • 217