I am trying to write a really simple CasperJS script to test the login button on a website. After the click event, a modal window is opened on top of the website so you can fill in the login fields.
Using the website, this works pretty well. Using casperjs test my-script-file --engine=slimerjs
also works perfectly fine. Without slimerjs, the code fails.
How the button is defined:
<button class="btn btn-strong-submit" data-action="join">Join</button>
My test:
casper.test.begin('testing', 3, function suite(test)
{
casper.start();
casper.thenOpen("http://the-website-to-test-url", function()
{
casper.wait(5000, function(){
casper.thenClick("button.btn.btn-strong-submit");
});
});
casper.then(function () {
casper.wait(3000);
casper.capture("screen.png");
});
casper.then(function(){
casper.assertVisible("div.join_container");
});
casper.run(function()
{
test.done();
})
});
On the website, clicking the button will go to http://the-website-to-test-url.com/#join since the way the website works is it waits for a click and catches is using jQuery and then finds the [data-action], forms #[data-action] and then builds the URL in that way.
But CasperJS does not seem to understand a click which then gets caught from jQuery on the background. Any ideas?
Update on terminal output:
[info] [phantom] Starting...
[info] [phantom] Running suite: 4 steps
[debug] [phantom] opening url: http://www.MYURL.com/, HTTP GET
[debug] [phantom] Navigation requested: url=http://www.MYURL.com/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://www.MYURL.com/"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/4 http://www.MYURL.com/ (HTTP 200)
[info] [phantom] Step anonymous 2/4: done in 721ms.
[info] [phantom] Step anonymous 3/4 http://www.MYURL.com/ (HTTP 200)
[info] [phantom] Step anonymous 3/4: done in 731ms.
[info] [phantom] Step _step 4/5 http://www.MYURL.com/ (HTTP 200)
[info] [phantom] Step _step 4/5: done in 752ms.
[info] [phantom] wait() finished waiting for 5000ms.
[debug] [phantom] Mouse event 'mousedown' on selector: .btn.btn-strong-submit
[debug] [phantom] Mouse event 'mouseup' on selector: .btn.btn-strong-submit
[debug] [phantom] Mouse event 'click' on selector: .btn.btn-strong-submit
[info] [phantom] Step anonymous 5/5 http://www.MYURL.com/ (HTTP 200)
//After click URL should have changed to http://www.MYURL.com/#login
[info] [phantom] Step anonymous 5/5: done in 5772ms.
[info] [phantom] Step _step 6/6 http://www.MYURL/ (HTTP 200)
[info] [phantom] Step _step 6/6: done in 5792ms.
[info] [phantom] wait() finished waiting for 3000ms.
[debug] [phantom] Capturing page to /home/TEMP/screen.png
[info] [phantom] Capture saved to /home/TEMP/screen.png
[info] [phantom] Done 6 steps in 9367ms