Thanks so much Hernan, the approach works great!

On 8/5/09 10:47 AM, Hernan Castagnola wrote:
I am new on webtest, so I am not sure if this is the correct solution
but it works. This is how I use it. Note that I use the ant.group

public class SeoHomepageAllCountriesTest extends WebtestCase {


     public void testSeoStructure() {
         List dataDriven = new
SeoHomepageAllCountriesTestProvider().getData()
         dataDriven.each(){test ->
             webtest("$test.metatag_id - Testing Title - Meta
Description - MetaKeyword"){
                 config (haltonerror: "false", haltonfailure: "false")
                 checkSeo test.url, test.title, test.metadescription,
test.metakeyword, {}
             }

         }
     }



     private checkSeo (String url , String title, String
metadescription, String metakeyword , Closure verification) {
         ant.group description: "Checking Metatag ID",
         {
             enableJavaScript enable:"false"
             invoke url:"http://$url";, description:"Go to $url",
saveResponse:"false"
             verifyTitle description:"Home Page Title is the correct one
" , text: "$title"
             verifyXPath description:"Checks MetaDescription is the
correct one" , xpath:"//me...@name='description']/@content"  , text:
"$metadescription"
             verifyXPath description:"Checks Meta Keyword is the correct
one" , xpath:"//me...@name='keywords']/@content" , text: "$metakeyword"
             //verifyXPath description:"Checks Header Keyword is the
correct one" , xpath:"//h...@id='header_keywords']/strong" ,
text:headerKeyword
             verification.delegate = ant
             verification()

         }

     }

}



2009/8/5 bestguy <[email protected] <mailto:[email protected]>>


    Hi,

    I've been writing Groovy-only WebTests, which works great.
    However, stumbling on how to define and reuse a "macro" which
    consists of
    other webtest calls.

    In this case, I want to call these two steps:

    invoke(url: "http://validator.w3.org/check?uri=${it}
    <http://validator.w3.org/check?uri=$%7Bit%7D>")
    verifyXPath(xpath: "id('form')/table/tbody/tr[1]/t...@class='valid']")

    and wrap them in a simple call such as
    validator("http://www.blah.com";)

    I'd like to define these somewhere an reuse them.

    However, can't seem to get this to work.  Approaches like this fail:

    class BlahTest extends WebtestCase {

        void testList() {
            def validator = {
                invoke(url:
    
"http://validator.w3.org/check?uri=${it}&charset=%28detect+automatically%29&doctype=Inline&group=0
    
<http://validator.w3.org/check?uri=$%7Bit%7D&charset=%28detect+automatically%29&doctype=Inline&group=0>")
                verifyXPath(xpath:
    "id('form')/table/tbody/tr[1]/t...@class='valid']")
            }

            webtest("List Pages") {
                validator("http://www.wordpress.com";)
            }
        }
    }


    The only way that seems to work is if you embed the closure in the
    webtest
    itself:

            webtest("List Pages") {
                def validator = {
                    invoke(url: "http://validator.w3.org/check?uri=${it}
    <http://validator.w3.org/check?uri=$%7Bit%7D>")
                    verifyXPath(xpath:
    "id('form')/table/tbody/tr[1]/t...@class='valid']")
                }

                validator("http://www.wordpress.com";)
            }


    but that sort of limits the usefulness of this.

    Any ideas?


    Thanks,
    G
    --
    View this message in context:
    http://www.nabble.com/Groovy-equivalent-of-macro--tp24820735p24820735.html
    Sent from the WebTest mailing list archive at Nabble.com.

    _______________________________________________
    WebTest mailing list
    [email protected] <mailto:[email protected]>
    http://lists.canoo.com/mailman/listinfo/webtest



_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest

Reply via email to