I'm rewriting some tests to check constraint validation on email inputs. I'm trying to check the following JavaScript:
我正在重写一些测试来检查电子邮件输入的约束验证。我正在尝试检查以下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
当我使用普通的旧JavaScript测试时,一切都很好。我得到“true”,这是电子邮件地址无效时的预期答案。当我在Geb中尝试这样做时,我遇到了各种各样的麻烦。当我尝试
def isValid = js.exec("document.getElementById('theEmailAddress')")
with the assertion being that isValid == true
断言是isValid == true
I get the spock comparison error with the following output:
我得到spock比较错误与以下输出:
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错误:
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?
我很茫然。我尝试过browser.driver.executeScript,js.exec,js。,一切都返回null或错误。关于我可以做些什么才能让它发挥作用的任何指示?
1 个解决方案
#1
0
Solved it! Here's what ended up working:
解决了!这是最终的工作:
given: "The customer goes to login page"
to LoginPage
waitFor { LoginPage }
when: "The customer tries to register with an email without domain"
theEmailId.value("anemail@.com")
and: "The customer clicks the continue button"
continueButton.click()
def isValid = js."window.document.getElementById('theEmailAddress').validity['typeMismatch']"
println isValid
then: "The customer should see this error"
assert isValid == true
#1
0
Solved it! Here's what ended up working:
解决了!这是最终的工作:
given: "The customer goes to login page"
to LoginPage
waitFor { LoginPage }
when: "The customer tries to register with an email without domain"
theEmailId.value("anemail@.com")
and: "The customer clicks the continue button"
continueButton.click()
def isValid = js."window.document.getElementById('theEmailAddress').validity['typeMismatch']"
println isValid
then: "The customer should see this error"
assert isValid == true