Page Content From a list

44 views
Skip to first unread message

Adam Gilbert

unread,
Oct 13, 2017, 12:32:15 PM10/13/17
to Geb User Mailing List
Hello, 

All the web elements I'm going to access have ID's, so I was hoping to define the content using just a list of expected ID's. 

for example: 
static def ids = ['header', 'title', 'element1', 'etc']
static content = {
    ids.each {[it: {$(By.id(it))}]}
}

However, it is unable to resolve any of them "as content or as a property on its navigator context". 

How should I be defining content through a list? 

Thanks, 
Adam

Marcin Erdmann

unread,
Oct 14, 2017, 5:57:05 AM10/14/17
to Geb User Mailing List
Content defintions are method calls and not map entries. You should use the following:

static def ids = ['header', 'title', 'element1', 'etc']
static content = {
    ids.each { id ->
        "$id"({ $(id: id) })
    }
}

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+unsubscribe@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/ee85325a-8e23-4aed-8270-9cfb69e134ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Gilbert

unread,
Oct 14, 2017, 9:24:22 AM10/14/17
to Geb User Mailing List
That works perfectly! Thanks for the quick and correct response!


On Saturday, October 14, 2017 at 4:57:05 AM UTC-5, Marcin Erdmann wrote:
Content defintions are method calls and not map entries. You should use the following:

static def ids = ['header', 'title', 'element1', 'etc']
static content = {
    ids.each { id ->
        "$id"({ $(id: id) })
    }
}
On Fri, Oct 13, 2017 at 5:32 PM, Adam Gilbert <michael.ad...@gmail.com> wrote:
Hello, 

All the web elements I'm going to access have ID's, so I was hoping to define the content using just a list of expected ID's. 

for example: 
static def ids = ['header', 'title', 'element1', 'etc']
static content = {
    ids.each {[it: {$(By.id(it))}]}
}

However, it is unable to resolve any of them "as content or as a property on its navigator context". 

How should I be defining content through a list? 

Thanks, 
Adam

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.

Samuel Rossinovic

unread,
Oct 18, 2017, 12:34:14 AM10/18/17
to Geb User Mailing List
Can templates declared in this method be used as targets of assignment (e.g. when their elements are form inputs)?

Marcin Erdmann

unread,
Oct 18, 2017, 2:29:21 AM10/18/17
to geb-...@googlegroups.com
If you’re asking whether content defined in this dynamic way can be used with form control shortcuts (used as target of assignements) then yes. There is nothing special to content defined that way from Geb’s point of view.

Samuel Rossinovic

unread,
Oct 18, 2017, 11:19:03 PM10/18/17
to Geb User Mailing List
Actually, was thinking more along the lines of:

def fillForm() {
    ids
.each { /* it */ << 'foo' }
}

Marcin Erdmann

unread,
Oct 19, 2017, 3:48:28 PM10/19/17
to Geb User Mailing List
You could probably simply do:

ids.each { $(id: it) << 'foo' }

and if you really need to go through content definitions then you can do:

ids.each { this."$it" = 'foo' }

or 

ids.each { this[it] = 'foo' }

because form shortcuts are implemented using propertyMissing() on Page and Module:



To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+unsubscribe@googlegroups.com.

To post to this group, send email to geb-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages