willem
willem

Reputation: 27027

Why does CasperJS form submit not redirect to the next page?

This is my first casper test, so I'm still struggling with the basics. I would like to fill in the username and password on my login form, then submit it. And then confirm if a 'log off' link is rendered on the next page (confirming that the user has been logged in).

But as far as I can tell, when then is called, the url is still the same. Looks like no post or redirect to the next page is happening. What am I doing wrong?

casper.start "http://test.local.mycompany.local/", ->
    @echo 'at ' + @getCurrentUrl()
    @fill 'form', { UserAlias : 'joe', Password : 'password' }, true

casper.then ->
    @echo 'at ' + @getCurrentUrl()
    @test.assertExists '#log-off-link', 'log-off link exists'

casper.run ->
    @test.done()

So the echo of @getCurrentUrl both returns the same URL, which is wrong.

Upvotes: 5

Views: 3886

Answers (3)

Artjom B.
Artjom B.

Reputation: 61892

It is possible that casper doesn't find the fields by name. You could try

casper.start "http://test.local.mycompany.local/", ->
    @echo 'at ' + @getCurrentUrl()
    @fillSelectors 'form', { 'input[name=UserAlias]' : 'joe', 'input[name=Password]' : 'password' }, true

It should mean the same as your code, but sometimes it doesn't.

Upvotes: 1

gimenete
gimenete

Reputation: 2669

I had the same problem. One day my casper tests stopped working. More exactly casperjs stopped following redirects. The problem really was that my server was returning an invalid HTTP set-cookie header (with an invalid date). This was due to a configuration problem with the expiration date. Anyway, it seems that if there is an incorrect value in some header value something makes casperjs to ignore other header values such as the "location" http header for redirects.

Once I fixed the problem with the expiration date in the cookies the HTTP set-cookie header was ok and casperjs started to follow again the redirects.

Hope this helps!

Upvotes: 2

You can try to use chrome extension ressurectio to generate automated tests, for casperjs, in browser. It's very simple to use and useful. May be in a few lines(- part of generated code) you should to make some fixes but anyway it's very useful and convenient.

Upvotes: 6

Related Questions