Using Spock and Geb testing a page with a Frame

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Spock and Geb testing a page with a Frame

Brett Bergquist
I am pretty new to Spock and Geb but am really enjoying both.  I have a Web page that I am writing tests for and the page has a IFRAME with content.  Using the Geb documentation, I understand how to model the IFRAME as a Page object and interact with it using Geb's "withFrame" construct, but I don't know how this interacts with Spock's "when/then" blocks.   For example, I have a test like:

    def "Check that the Add/Edit page is available"() {
        given: "I am at the Account Configuration page"
        at AccountTableConfigPage
        
            when: "I invoke that Add action"
            withFrame(contentFrame)  {
               invokeAddAction()
             }

            then: "Check that I am at the Add/Edit page"
            withFrame(contentFrame) {
                 at AccountTableAddEditPage
                getUsernameDbValue() == "x"
           }
    }

So in the "given", the Page is the container Page with the IFRAME and the "contentFrame" is the what is targeting the IFRAME content Page.   When I do it this way, the assertion "getUsernameDbValue() == "x"' should fail but it does not.   If i change this to an explicit assert 

assert getUsernameDbValue() == "x"'

then this works.   Is this the correct way to nest the "withFrame"?   Initially I tried something like:

    def "Check that the Add/Edit page is available"() {
        given: "I am at the Account Configuration page"
        at AccountTableConfigPage
        
        withFrame(contentFrame) {
            when: "I invoke that Add action"
            invokeAddAction()
                
            then: "Check that I am at the Add/Edit page"
            at AccountTableAddEditPage
            getUsernameDbValue() == "x"
        }
    }

and that did not work either as expected either.   I could not find a good example after searching quite a while so any help will be most appreciated.

Brett

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using Spock and Geb testing a page with a Frame

Brett Bergquist
So I am still stuck.  I try something like this:

    
    def "Check that the Add/Edit page is available"() {
        given: "I am at the Account Configuration page"
        at AccountTableConfigPage
        
        when: "I invoke that Add action"
        withFrame(contentFrame, AccountTableConfigIcePage) {
            invokeAddAction()
        }
                
        then: "Check that I am at the Add/Edit page"
        withFrame(contentFrame, AccountTableAddEditPage) {
            assert at(AccountTableAddEditPage) != null
            assert getUsernameDbValue() == ""
        }
    }

which I believe should work as reading the Spock docs it looks like that if you have any sort of block, then explicit asserts need to be used.  But when I run the test , I get this as output:

------------- ---------------- ---------------
Testcase: Check that the Add/Edit page is available(com.canoga.nms.web.pkg.pkg9145e100g.ui.app.config.accountconfig.AccountTableBurnSpec): Caused an ERROR
startup failed:
Spec expression: 1: unexpected token: assert @ line 1, column 95.
   ountTableAddEditPage) != null assert get
                                 ^

1 error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Spec expression: 1: unexpected token: assert @ line 1, column 95.
   ountTableAddEditPage) != null assert get
                                 ^

1 error

at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:106)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:148)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:359)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:142)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:108)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
at org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)


Test com.canoga.nms.web.pkg.pkg9145e100g.ui.app.config.accountconfig.AccountTableBurnSpec FAILED
Testsuite: com.canoga.nms.web.pkg.pkg9145e100g.ui.device.devicebrowser.DeviceBrowserBurnSpec
Tests run: 0, Failures: 0, Errors: 0, Time elapsed: 2.753 sec

I don't have a clue as what is wrong with this and really could use some help!

Using Groovy 2.2.2, Geb 0.9.2, and Spock spock-core-1.0-groovy-2.0-20131224.084311-25.jar


--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using Spock and Geb testing a page with a Frame

Brett Bergquist
So I googled some more and found this page:


On this page, each of the "withFrame{}" in the look like

withFrame(xxx) {
     assert ...
     assert ...
} || true

Not sure why the "|| true" is needed, but I tried to do the same:

    def "Check that the Add/Edit page is available"() {
        given: "I am at the Account Configuration page"
        at AccountTableConfigPage
        
        when: "I invoke that Add action"
        withFrame(contentFrame, AccountTableConfigIcePage) {
            invokeAddAction()
        }
                
        then: "Check that I am at the Add/Edit page"
        withFrame(contentFrame, AccountTableAddEditPage) {
            assert at(AccountTableAddEditPage)
            assert ! getUsernameDbValue()
        } || true
    }


Now this appears to be working correctly.   Any ideas why the "|| true" is needed?    Just for my own knowledge.

Brett

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using Spock and Geb testing a page with a Frame

Peter Niederwieser
Administrator
Probably `withFrame` returns a value that’s false according to Groovy truth, and so `|| true` is necessary not to fail the condition. (The whole `withFrame` expression is considered a condition because it occurs in a `then` block.)

The `unexpected token: assert` is an unrelated issue with multiline conditions. When a multiline condition fails, it sometimes cannot be rendered and instead throws a parse exception. This is a known issue that will get fixed eventually.

Cheers,
Peter

On 13 Mar 2014, at 02:19, Brett Bergquist <[hidden email]> wrote:

So I googled some more and found this page:


On this page, each of the "withFrame{}" in the look like

withFrame(xxx) {
     assert ...
     assert ...
} || true

Not sure why the "|| true" is needed, but I tried to do the same:

    def "Check that the Add/Edit page is available"() {
        given: "I am at the Account Configuration page"
        at AccountTableConfigPage
        
        when: "I invoke that Add action"
        withFrame(contentFrame, AccountTableConfigIcePage) {
            invokeAddAction()
        }
                
        then: "Check that I am at the Add/Edit page"
        withFrame(contentFrame, AccountTableAddEditPage) {
            assert at(AccountTableAddEditPage)
            assert ! getUsernameDbValue()
        } || true
    }


Now this appears to be working correctly.   Any ideas why the "|| true" is needed?    Just for my own knowledge.

Brett

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using Spock and Geb testing a page with a Frame

Luke Daley-2
withFrame returns the return value of the given closure, and assert is returning “void” I guess.

Not sure what we could do about this. Perhaps when Spock rewrites the assert statement it could rewrite it in such a way so that it returns the result of the assertion.

On 13 March 2014 at 4:33:11 pm, [hidden email] ([hidden email]) wrote:

Probably `withFrame` returns a value that’s false according to Groovy truth, and so `|| true` is necessary not to fail the condition. (The whole `withFrame` expression is considered a condition because it occurs in a `then` block.)

The `unexpected token: assert` is an unrelated issue with multiline conditions. When a multiline condition fails, it sometimes cannot be rendered and instead throws a parse exception. This is a known issue that will get fixed eventually.

Cheers,
Peter

On 13 Mar 2014, at 02:19, Brett Bergquist <[hidden email]> wrote:

So I googled some more and found this page:


On this page, each of the "withFrame{}" in the look like

withFrame(xxx) {
     assert ...
     assert ...
} || true

Not sure why the "|| true" is needed, but I tried to do the same:

    def "Check that the Add/Edit page is available"() {
        given: "I am at the Account Configuration page"
        at AccountTableConfigPage
        
        when: "I invoke that Add action"
        withFrame(contentFrame, AccountTableConfigIcePage) {
            invokeAddAction()
        }
                
        then: "Check that I am at the Add/Edit page"
        withFrame(contentFrame, AccountTableAddEditPage) {
            assert at(AccountTableAddEditPage)
            assert ! getUsernameDbValue()
        } || true
    }


Now this appears to be working correctly.   Any ideas why the "|| true" is needed?    Just for my own knowledge.

Brett

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using Spock and Geb testing a page with a Frame

Peter Niederwieser
Administrator
That’s an interesting option, but also a somewhat scary change to make at this point. It would effectively make satisfied explicit conditions evaluate to `true` rather than `null`, which could break some (odd) code out in the wild.

Cheers,
Peter

On 13 Mar 2014, at 06:34, Luke Daley <[hidden email]> wrote:

withFrame returns the return value of the given closure, and assert is returning “void” I guess.

Not sure what we could do about this. Perhaps when Spock rewrites the assert statement it could rewrite it in such a way so that it returns the result of the assertion.

On 13 March 2014 at 4:33:11 pm, [hidden email] ([hidden email]) wrote:

Probably `withFrame` returns a value that’s false according to Groovy truth, and so `|| true` is necessary not to fail the condition. (The whole `withFrame` expression is considered a condition because it occurs in a `then` block.)

The `unexpected token: assert` is an unrelated issue with multiline conditions. When a multiline condition fails, it sometimes cannot be rendered and instead throws a parse exception. This is a known issue that will get fixed eventually.

Cheers,
Peter

On 13 Mar 2014, at 02:19, Brett Bergquist <[hidden email]> wrote:

So I googled some more and found this page:


On this page, each of the "withFrame{}" in the look like

withFrame(xxx) {
     assert ...
     assert ...
} || true

Not sure why the "|| true" is needed, but I tried to do the same:

    def "Check that the Add/Edit page is available"() {
        given: "I am at the Account Configuration page"
        at AccountTableConfigPage
        
        when: "I invoke that Add action"
        withFrame(contentFrame, AccountTableConfigIcePage) {
            invokeAddAction()
        }
                
        then: "Check that I am at the Add/Edit page"
        withFrame(contentFrame, AccountTableAddEditPage) {
            assert at(AccountTableAddEditPage)
            assert ! getUsernameDbValue()
        } || true
    }


Now this appears to be working correctly.   Any ideas why the "|| true" is needed?    Just for my own knowledge.

Brett

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using Spock and Geb testing a page with a Frame

Luke Daley-2
Lucky it's pre 1.0 :)

On 13 Mar 2014, at 15:50, "[hidden email]" <[hidden email]> wrote:

That’s an interesting option, but also a somewhat scary change to make at this point. It would effectively make satisfied explicit conditions evaluate to `true` rather than `null`, which could break some (odd) code out in the wild.

Cheers,
Peter

On 13 Mar 2014, at 06:34, Luke Daley <[hidden email]> wrote:

withFrame returns the return value of the given closure, and assert is returning “void” I guess.

Not sure what we could do about this. Perhaps when Spock rewrites the assert statement it could rewrite it in such a way so that it returns the result of the assertion.

On 13 March 2014 at 4:33:11 pm, [hidden email] ([hidden email]) wrote:

Probably `withFrame` returns a value that’s false according to Groovy truth, and so `|| true` is necessary not to fail the condition. (The whole `withFrame` expression is considered a condition because it occurs in a `then` block.)

The `unexpected token: assert` is an unrelated issue with multiline conditions. When a multiline condition fails, it sometimes cannot be rendered and instead throws a parse exception. This is a known issue that will get fixed eventually.

Cheers,
Peter

On 13 Mar 2014, at 02:19, Brett Bergquist <[hidden email]> wrote:

So I googled some more and found this page:


On this page, each of the "withFrame{}" in the look like

withFrame(xxx) {
     assert ...
     assert ...
} || true

Not sure why the "|| true" is needed, but I tried to do the same:

    def "Check that the Add/Edit page is available"() {
        given: "I am at the Account Configuration page"
        at AccountTableConfigPage
        
        when: "I invoke that Add action"
        withFrame(contentFrame, AccountTableConfigIcePage) {
            invokeAddAction()
        }
                
        then: "Check that I am at the Add/Edit page"
        withFrame(contentFrame, AccountTableAddEditPage) {
            assert at(AccountTableAddEditPage)
            assert ! getUsernameDbValue()
        } || true
    }


Now this appears to be working correctly.   Any ideas why the "|| true" is needed?    Just for my own knowledge.

Brett

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using Spock and Geb testing a page with a Frame

Brett Bergquist
In reply to this post by Brett Bergquist
Thanks guys for the explanation.  Both Geb and Spock are really a delight to use even with hiccup here and there!

Brett

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using Spock and Geb testing a page with a Frame

Stelios Anastasakis
Actually, you should not use `then ... || true` cause this is not testing anything. From my understanding `withFrame` should return a boolean. the code
        withFrame(....) {
            assert ...
            assert ...
        }
doesnt return a boolean, so that block fails. To resovle this you should (definatelly not use || true, but ) use either sth like :
        withFrame(....) {
            {Boolean-value} && {Boolean-value} && {Boolean-value}
        }
or better, in my opinion:
        withFrame(....) {
            assert ...
            assert ...
            true
        }

On Thursday, 13 March 2014 13:17:53 UTC+2, Brett Bergquist wrote:
Thanks guys for the explanation.  Both Geb and Spock are really a delight to use even with hiccup here and there!

Brett

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.