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

半世苍凉 提交于 2019-12-10 14:24:11

问题


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.


回答1:


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.




回答2:


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!




回答3:


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.



来源:https://stackoverflow.com/questions/12181669/why-does-casperjs-form-submit-not-redirect-to-the-next-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!