2

I want to write a selenium test that will check that when I log in to my application, and then re-open the browser, I'm automatically logged in using the saved cookie.

I thought that this may be possible to calling clearSession() between two #{selenium} blocks, but that seems to clear the cookie too. I've tested that this functionality works manually.

Any ideas how I'd test this.

For reference: Here's what I've tried.

#{fixture delete:'all', load:'../conf/User.yml' /}

#{selenium}
    deleteAllVisibleCookies()
    // Open the home page, and check that no error occurred
    open('/')
    waitForPageToLoad(1000)
    assertNotTitle('Application error')
    open('/login')
    type('usernameOrEmail', 'marchaos')
    type('password', 'password')
    clickAndWait('css=input[type=submit]')
    assertTextPresent('Welcome marchaos')
    clearSession()
#{/selenium}

#{selenium}
    // Open the home page, and check that no error occurred
    open('/')
    waitForPageToLoad(1000)
    assertTextPresent('Welcome marchaos')
#{/selenium} 

it fails at the last assertTextPresent()

marchaos
  • 3,316
  • 4
  • 26
  • 35
  • Similar topic is here http://stackoverflow.com/questions/8874241/selenium-phpunit-end-a-session-when-re-using-browser-sessions/8877165#8877165 – faramka Jan 19 '12 at 14:31

1 Answers1

0

I don't know about Selenium but you can do this in a functional test.

I do something like this:

Response loginResponse = FunctionalTest.GET("/user/login?login=test&password=test");
Map<String, Cookie> loginResponseCookies = loginResponse.cookies;

....

Request request = FunctionalTest.newRequest();
request.cookies = loginResponseCookies;
request.url = url;
return FunctionalTest.GET(request, url);
nylund
  • 1,105
  • 10
  • 15