|
Hello all,
I'm trying to right functional tests for my app to prove all the features are implemented as expected. It seems like the grails-functional-test plugin is the recommended way to do this. https://github.com/Grailsrocks/grails-functional-test Please correct me if I'm wrong. With the latest release, I get the following error: | groovy.lang.MissingPropertyException: No such property: source for class: com.grailsrocks.functionaltest.client.ContentChangedEvent at com.grailsrocks.functionaltest.FunctionalTestException$_dumpURLStack_closure1.doCall(FunctionalTestException.groovy:39) at com.grailsrocks.functionaltest.FunctionalTestException.dumpURLStack(FunctionalTestException.groovy:38) at com.grailsrocks.functionaltest.FunctionalTestException.printStackTrace(FunctionalTestException.groovy:59) | Completed 1 functional test, 1 failed in 3293ms I'm using Grails 2.0.4. To get past this, I tried upgrading to the latest release on GitHub. With the latest release, the command to run it changed from "grails test-app -functional" to "grails functional-tests". Now I get the following error: | Error Error executing script FunctionalTests: Run (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.) java.lang.ClassNotFoundException: Run at java_lang_ClassLoader$loadClass.call(Unknown Source) at grails.util.BuildSettings$1.doCall(BuildSettings.groovy:336) at FunctionalTests.run(FunctionalTests:60) at FunctionalTests$run.call(Unknown Source) at gant.Gant.prepareTargets(Gant.groovy:607) | Error Error executing script FunctionalTests: Run Also, it seems like my functional tests are run when I use "grails test-app". This seems to happen to others as noted in this thread: http://grails.1312388.n4.nabble.com/test-app-tries-to-run-functional-test-when-there-are-none-td4629579.html Does anyone a workaround for these issues? If not, what's the recommended solution for functional testing with Grails? Thanks, Matt |
|
I'm not sure about the recommended way but there is a large consensus around Geb for functional testing (http://grails.org/plugin/geb). Coupled to Spock, you have nice readable tests like :
That's said, are you using the github version, or the grails repo version ? I'm not sure Marc has deployed his very latest changes on grails repo. Sorry for the bad experience you get with the plugin, some of them requires work to migrate to grails 2 and I'm not sure if in this case a new version has been deployed.
On Sat, Jun 9, 2012 at 10:45 PM, mraible <[hidden email]> wrote: Hello all, Stéphane MALDINI
-- |
|
I honestly have never had luck with the functional-test plugin. If you are using spock and do not want to use geb (ie testing a REST API, etc), you can use the spock functional plugin -
http://grails.org/plugin/functional-spock.
-Brian
On Sun, Jun 10, 2012 at 2:17 AM, Stephane Maldini <[hidden email]> wrote: I'm not sure about the recommended way but there is a large consensus around Geb for functional testing (http://grails.org/plugin/geb). Coupled to Spock, you have nice readable tests like : |
|
In reply to this post by smaldini
Thanks for the reply. I tried both the github version and the grails repo one. Both had issues.
Thanks for the tip on the Geb plugin. I've tried that and it seems to work pretty well. However, I've run into an issue with trying to test signup for a new user. I have the Spring Security UI Plugin installed and it always seems to fail on the last step after verifying the registration code. Here's my test: def "signup as a new user"() { given: def server = SimpleSmtpServer.start(1025) when: to SignupPage form.username = "[hidden email]" form.email = "[hidden email]" form.password = "IloveGROOVY@2" form.password2 = "IloveGROOVY@2" createAccountButton.click() then: $('form').text().contains("Your account registration email was sent") server.receivedEmailSize == 1 def email = server.receivedEmail.next() String body = email.body int index = body.indexOf('/register/verifyRegistration?t=') index > -1 int index2 = body.indexOf('"', index + 1) String code = body.substring(index + '/register/verifyRegistration?t='.length(), index2) code != null when: go '/register/verifyRegistration?t=' + code then: waitFor { title ==~ /Welcome to Happy Trails!.+/ } userIcon.parent().contains("[hidden email]") } The error: | Failure: signup as a new user(happytrails.AuthenticatedUserSpec) | geb.waiting.WaitTimeoutException: condition did not pass in 5.0 seconds (failed with exception) at geb.waiting.Wait.waitFor(Wait.groovy:128) at geb.waiting.WaitingSupport.doWaitFor(WaitingSupport.groovy:108) at geb.waiting.WaitingSupport.waitFor(WaitingSupport.groovy:66) at geb.waiting.WaitingSupport.waitFor(WaitingSupport.groovy:62) at geb.Browser.methodMissing(Browser.groovy:168) at geb.spock.GebSpec.methodMissing(GebSpec.groovy:51) at org.spockframework.util.GroovyRuntimeUtil.invokeMethod(GroovyRuntimeUtil.java:100) at happytrails.AuthenticatedUserSpec.signup as a new user(AuthenticatedUserSpec.groovy:47) Caused by: Assertion failed: title ==~ /Welcome to Happy Trails!.+/ | | null false at happytrails.AuthenticatedUserSpec.signup as a new user_closure1(AuthenticatedUserSpec.groovy:47) at geb.waiting.Wait.waitFor(Wait.groovy:117) ... 7 more If I look at the HTML page being generated, it has "-- no page source --" in it. Is there anyway to tell Geb to follow redirects? I've gone through everything manually and it works fine in a real browser. Thanks, Matt On Jun 10, 2012, at 2:22 AM, smaldini [via Grails] wrote: I'm not sure about the recommended way but there is a large consensus around Geb for functional testing (http://grails.org/plugin/geb). Coupled to Spock, you have nice readable tests like : |
|
In reply to this post by mraible
On 9 Jun 2012, at 22:45, mraible wrote: > Hello all, > > I'm trying to right functional tests for my app to prove all the features > are implemented as expected. It seems like the grails-functional-test plugin > is the recommended way to do this. > > https://github.com/Grailsrocks/grails-functional-test > > Please correct me if I'm wrong. Hi Matt, Sorry about that. It was a typo in some output that only occurs in an error. By latest build do you mean the last release of the plugin, or have you built from master. I believe I fixed and released this the other day as a snapshot. So, if you're not using version 2.0.M3-SNAPSHOT, please give that one a go. Marc ~ ~ ~ Marc Palmer Freelancer (Grails/Groovy/Java/UX) I offer commercial support for Grails plugins from as low as $50/mo. For details see: http://grailsrocks.com Blog: http://www.anyware.co.uk | Resumé: http://www.anyware.co.uk/marc Contributor @ http://grails.org | Founder @ http://noticelocal.com Developer @ http://weceem.org | Member @ http://spottymushroom.com Twitter: http://twitter.com/wangjammer5 --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by bksaville
On 10 Jun 2012, at 15:27, Brian Saville wrote: > I honestly have never had luck with the functional-test plugin. If you are using spock and do not want to use geb (ie testing a REST API, etc), you can use the spock functional plugin - http://grails.org/plugin/functional-spock. Certainly Spock, Geb etc all great. Functional-test had a long period where it wouldn't work well with newer Grails build (1.3 onwards). The 2.0 snapshots resolve these problems, and introduce API testing as well as "fake browser" testing. Sadly any "fake browser" testing that uses HtmlUnit (including functional test and others using WebDriver that use the HtmlUnit mode) seem pretty doomed for newer jQuery versions, and to my knowledge there does not seem to be any movement on this. The upshot is that currently we can't functional test our apps with htmlunit, but we do functional test our APIs using the new APITestCase base class in functional-test 2.0 - "but look ma, no docs" :( Marc ~ ~ ~ Marc Palmer Freelancer (Grails/Groovy/Java/UX) I offer commercial support for Grails plugins from as low as $50/mo. For details see: http://grailsrocks.com Blog: http://www.anyware.co.uk | Resumé: http://www.anyware.co.uk/marc Contributor @ http://grails.org | Founder @ http://noticelocal.com Developer @ http://weceem.org | Member @ http://spottymushroom.com Twitter: http://twitter.com/wangjammer5 --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by mraible
On 11/06/2012, at 8:19 AM, mraible wrote: Thanks for the reply. I tried both the github version and the grails repo one. Both had issues. It should by default. Are you using the HTMLUnit driver? I'd strongly recommend not doing that as its JavaScript support is not very good. However, I can't see how that would be in play here. What's URL is the browser at before the failed verification? You can get it with `driver.currentUrl`. |
|
On Jun 11, 2012, at 9:07 AM, [hidden email] [via Grails] wrote:
package happytrails import org.openqa.selenium.htmlunit.HtmlUnitDriver import org.openqa.selenium.firefox.FirefoxDriver import org.openqa.selenium.chrome.ChromeDriver driver = { def driver = new HtmlUnitDriver() driver.javascriptEnabled = true driver } environments { chrome { driver = { new ChromeDriver() } } firefox { driver = { new FirefoxDriver() } } } If I print the URL before the failed verification, it seems to be correct, but maybe it's not actually retrieved? when: go '/register/verifyRegistration', t: code then: println driver.currentUrl Here's what's printed: If I try to use the FirefoxDriver instead, I get: java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "javax/xml/namespace/QName" at javax.xml.xpath.XPathConstants.<clinit>(XPathConstants.java:53) at org.openqa.selenium.firefox.internal.FileExtension.readIdFromInstallRdf(FileExtension.java:121) at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:61) at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:64) at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:466) at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:444) at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:74) at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:200) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:94) at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147) at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:85) at happytrails.AuthenticatedUserSpec.signup as a new user(AuthenticatedUserSpec.groovy:24) With Chrome, it seems like I'm supposed to execute the following, but no tests are run. grails test-app -Dwebdriver.chrome.driver="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" |
|
On 11/06/2012, at 6:38 PM, mraible wrote:
I can't recall what happens if the page is plain text. I know at the least that HTMLUnit is prone to freaking out in this case. I would expect the server to be return HTML here though, and regardless the driver should be seeing the 30x. Exactly why I avoid HTMLUnit TBH. Weird stuff like this is too hard to debug.
I think this is the good old xml-apis fiasco. You've likely got some dependency dragging in xerces. That's speculation, but it's often the cause of this kind of thing.
I never have to do that. I just put the native chrome driver binary on my PATH. That's what “webdriver.chrome.driver” is supposed to point to, not chrome itself. See http://code.google.com/p/selenium/wiki/ChromeDriver
|
|
On Jun 11, 2012, at 11:54 AM, [hidden email] [via Grails] wrote:
go 'register/verifyRegistration', t: code |
|
In reply to this post by mraible
Hi Matt,
I think the reason your test doesn't work is because you need to create a Page object for your registration page, and then replace the following line: go '/register/verifyRegistration?t=' + code with when: to RegisterPage, 'verifyRegistration', t: code then: at RegisterPage Your RegisterPage should look something like this: class RegisterPage extends Page { static url = 'register' static at = { title ==~ /Welcome to Happy Trails!.+/ } } Cheers, Antony On 11 June 2012 08:19, mraible <[hidden email]> wrote: > go '/register/verifyRegistration?t=' + code -- ________________________________ ꜽ . antony jones . http://www.enzy.org --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Sorry, a little late with my reply I now realise!
Regardless, you really should be using Page objects and Modules to make your test code more focussed, as it will greatly increase your ability to reuse test code, and get the full benefit of Geb+Spock. Cheers, Antony On 12 June 2012 15:47, Antony Jones <[hidden email]> wrote: > Hi Matt, > > I think the reason your test doesn't work is because you need to > create a Page object for your registration page, and then replace the > following line: > > go '/register/verifyRegistration?t=' + code > > with > > when: > to RegisterPage, 'verifyRegistration', t: code > then: > at RegisterPage > > Your RegisterPage should look something like this: > > class RegisterPage extends Page { > > static url = 'register' > > static at = { > title ==~ /Welcome to Happy Trails!.+/ > } > > } > > Cheers, > Antony > > On 11 June 2012 08:19, mraible <[hidden email]> wrote: >> go '/register/verifyRegistration?t=' + code > > > > -- > ________________________________ > ꜽ . antony jones . http://www.enzy.org -- ________________________________ ꜽ . antony jones . http://www.enzy.org --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
