I am trying to use CasperJS for testing a web app and my plan was to write tests that drove the web api and then used the app's API to check the results where recorded correctly.
So I was trying to make ajax requests from the test script: *not* within the page context.
However, after several hours of trying they always fail:
FAIL Error: NETWORK_ERR: XMLHttpRequest Exception 101
# type: uncaughtError
# file: v3-test.js:118
# error: NETWORK_ERR: XMLHttpRequest Exception 101
# send@[native code]
# phantomjs://code/v3-test.js:118:18
# runStep@phantomjs://platform/casper.js:1577:31
# checkStep@phantomjs://platform/casper.js:404:28
# stack: not provided
I am launching casperjs with:
--web-security=no --verbose --log-level=debug --local-to-remote-url-access=true
The server's response includes a Access-Control-Allow-Origin: * header
I have a simple snippet that creates an XMLHttpRequest and posts to the local server which works fine when run with "phantomjs --web-security=no" but the same snippet fails in CasperJS (using the same phantomjs engine v2.1.1 under Windows)
If I evaluate the fragments in the page context using casper.evaluate(...) then they work.
Is this pattern supposed to work? Can I make an AJAX request from the test script itself to check results on a remote server?
Thanks