0

I'm trying to use FluentLenium in Play with Scala to test our web form authentication. But it seems that the browser instance is not preserving state (or even loading) once the authentication form has been submitted... so, we submit the username and password, but it seems that the browser is not actually authentication. I'm guessing it has something to do with the browser state...?

I noticed there are some @SharedDriver settings documented, but these don't seem to work with our Scala test cases (they generate compiler errors).

The tests look like this:

class TestWebsiteAuthentication extends Specification {
    val loginURL = routes.Application.login().url
    val administrativePortalURL = routes.Application.index().url
    var cookies: Set[Cookie]

    "Application" should {
        "login as an administrative user on the web site" in new WithBrowser with GPAuthenticationTestUtility {
            browser.goTo(loginURL)

            browser.fill("#email").`with`(prerequisiteAccounts.head.userIdentity)
            browser.fill("#password").`with`(prerequisiteAccounts.head.password)
            browser.submit("#submit")
            browser.await().atMost(5, TimeUnit.SECONDS).untilPage().isLoaded

            assert(browser.title().contains("Upload")) // FAILS HERE
        }

        /**
         * This test will attempt to go to the upload page (after logging in, see previous test), and assert that the page has
         * loaded (we assume that means access is granted).
         */
        "go to the upload page after logging in" in new WithBrowser with GPAuthenticationTestUtility {

            browser.goTo(administrativePortalURL)
            browser.await().atMost(5, TimeUnit.SECONDS).untilPage().isLoaded

            Logger.info("page title after login to admin page: " + browser.title()) // PRINTS THE HOME PAGE (NOT AUTHENTICATED PAGE)...?

            assert(browser.title().contains("Upload")) // FAILS HERE
        }

Any ideas what I'm doing wrong?

Zaphod
  • 1,387
  • 2
  • 17
  • 33
  • Are you sure the login was successful at all? Can you get the status code from the first request? – Michael Zajac Apr 17 '15 at 13:00
  • Ok, I traced this back a bit and am now getting the failure when I try to fill the web form, apparently. Not that familiar with FluentLenium, but this is what I'm doing now: browser.fill("#email").`with`(prerequisiteAccounts.head.userIdentity) must equalTo(OK) ... and that results in an error: [error] 'org.fluentlenium.core.action.FillConstructor@1c25c183' is not equal to '200' (TestWebsiteAuthentication.scala:93) [error] Expected: 200 ... Thing is the form is fine, works in a web browser, and has an input field with id and name set to "email". – Zaphod Apr 19 '15 at 18:47
  • Using a `must equalTo(OK)` assertion on that form field doesn't really make sense, though. It just fills the field. – Michael Zajac Apr 20 '15 at 02:55
  • I found the problem regarding filling the form (I created a simple form, no CSS, no javascript, to solve that – seems some js was getting in the way). But, back to ground zero: The submit call works but I end up back on the login page. No authentication. I'm wondering if I need to be using Firefox (versus the HtmlWebDriver) in order for things like login, state, cookies, etc, for work? – Zaphod Apr 27 '15 at 14:09
  • could you emphasize what is prerequisiteAccounts, and where it is coming from (DB, static)? – Khorkhe Dec 11 '15 at 15:18

0 Answers0