在Play中使用FluentLenium提交表单并测试身份验证

时间:2015-04-17 05:06:12

标签: scala testing browser playframework fluentlenium

我正在尝试在Play with Scala中使用FluentLenium来测试我们的Web表单身份验证。但是,一旦提交了身份验证表单,浏览器实例似乎并未保留状态(甚至加载)...因此,我们提交了用户名和密码,但似乎浏览器实际上并不是身份验证。我猜这与浏览器状态有关......?

我注意到记录了一些@SharedDriver设置,但这些设置似乎不适用于我们的Scala测试用例(它们会产生编译器错误)。

测试看起来像这样:

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
        }

任何想法我做错了什么?

0 个答案:

没有答案