dimanche 19 avril 2015

The right way to fill and test a web form in ScalaTest and FluentLenium

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. :-(


Aucun commentaire:

Enregistrer un commentaire