mercredi 25 mai 2016

How can I check for an input's constraint validity within Geb?

I'm rewriting some tests to check constraint validation on email inputs. I'm trying to check the following JavaScript:

document.getElementById('theEmailId').validity.typeMismatch

When I test this with plain old JavaScript, everything is fine. I get "true", which is the expected answer when the email address is invalid. When I try to do this within Geb, I get all sorts of trouble. When I try

    def isValid = js.exec("document.getElementById('theEmailAddress')")

with the assertion being that isValid == true

I get the spock comparison error with the following output:

Condition not satisfied:

isValid == true
|       |
null    false

When I try

         def isValid = js.exec(theEmailAddress,
            """
                return \$(this).validity;
            """
    )

I get a java.lang.IllegalArgumentException error with the following report:

java.lang.IllegalArgumentException: Argument is of an illegal type: geb.content.TemplateDerivedPageContent
at org.openqa.selenium.remote.internal.WebElementToJsonConverter.apply(WebElementToJsonConverter.java:81)
at com.google.common.collect.Iterators$8.transform(Iterators.java:817)
at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
at com.google.common.collect.Iterators.addAll(Iterators.java:365)
at com.google.common.collect.Lists.newArrayList(Lists.java:162)
at com.google.common.collect.Lists.newArrayList(Lists.java:146)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:572)
at geb.js.JavascriptInterface.execjs(JavascriptInterface.groovy:37)
at geb.js.JavascriptInterface.exec(JavascriptInterface.groovy:67)
at com.ag.functionaltest.crs.specs.LoginGebSpec.The customer can not register using an email without @(LoginGebSpec.groovy:33)

I'm at a loss. I've tried browser.driver.executeScript, js.exec, js., everything returns null or an error. Any pointers on what I could possibly do to get this to work?

Aucun commentaire:

Enregistrer un commentaire