0

I'm trying to fill, submit, and test a web form in Play Framework, using ScalaTest and FluentLenium. It seems like it should be very straightforward, but I'm having all kinds of problems.

First, part of the web form in question:

<form class="signin" id="loginform" method="POST" action="/login">
    <div class="form-group">
        <label for="name">Email Address:</label>
        <input type="email" class="form-control" placeholder="Enter Email Address" id="email" name="email"  required />
        ...

This works fine from a real web browser. Now the problem comes when I try to fill in and submit the form:

@RunWith(classOf[JUnitRunner])
@SharedDriver(deleteCookies = false)
@SharedDriver(`type` = SharedDriver.SharedType.PER_CLASS)
class TestWebsiteAuthentication extends Specification {
    "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) must equalTo(OK)
            ...

At that last line, I get an exception:

[info] x login as an administrative user on the web site [error] 'org.fluentlenium.core.action.FillConstructor@1c25c183' is not equal to '200' (TestWebsiteAuthentication.scala:93) [error] Expected: 200 [error] Actual: org.fluentlenium.core.action.FillConstructor@1c25c183

Any ideas what I'm doing wrong here?

I've tried taking out the "must equalTo(OK)" but this just causes the form to fail on submit -- unfortunately, I haven't been able to find ANY documentation on how to do this, so I'm basically piecing it together bit by bit. Pointers to relevant documentation would be appreciated -- there doesn't seem to be anything complete at Tyrpesafe... just "teasers" that get you started, but no depth. :-(

Khorkhe
  • 1,024
  • 1
  • 11
  • 26
Zaphod
  • 1,387
  • 2
  • 17
  • 33

1 Answers1

0

When you write browser.fill("#email").``with``("x@y.com"), all you're really doing is telling Fluentlenium to edit the template to add a value attribute inside the input tag. On the other hand, OK is an HTTP status code, so comparing them will naturally yield false.

When you say you tried to submit the form and it failed, i am assuming you did something such as:

browser.fill("#email").`with`("x@y.com")
browser.fill("#password").`with`("myPass")
browser.click("#button")   // this should submit the form and load the page after login

and then tried to make an assertion such as:

browser.title() must equalTo("next page") // fails because "next page" != "login page"

one suggestion is to try something like this, Before browser.click:

browser.pageSource() must contain("xyz") // this will fail

When the above assertion fails, it will print the content of browser.pageSource() to your terminal, and you'll be able to see the modifications the Fill function did to the HTML.

In my case, I observed that my pageSource() now contained the following:

<input type="text" id="email" name="email" value="x@y.com"/>
<input type="password" id="password" name="password"/>

Notice how the first input has a value="x@y.com", but the second input is still empty. It turns out the second one is empty because it is an input of type password, however I eventually made the form login work.

Here is a list of things you can look into:

  • have a database enabled in that Spec
  • have it populated with Users (in case your form validation connects to a DB, that is)
  • from what I have experienced, using browser.goTo more than once in a test will not work well with form submission (anyone can confirm?)

Hope this helps

Khorkhe
  • 1,024
  • 1
  • 11
  • 26