Different navigator per page content item

74 views
Skip to first unread message

Jose Badeau

unread,
Jul 4, 2016, 11:59:57 AM7/4/16
to Geb User Mailing List
Given the following markup:

<div id="bootstrapDropdown" class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
</ul>
</div>

<ul id="zurbDropdown" class="dropdown menu" data-dropdown-menu>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
</ul>
and the following page content

static content = {
bootstrapDropdown(wait: true) { $("#bootstrapDropdown") }
zurbDropdown(wait: true) { $("#zurbDropdown") }`
}
I would like to be able to select an item like:

bootstrapDropdown.select("Item 2")
zurbDropdown.select("Item 2")
I would like to have 2 custom navigators

BootstrapNavigator implements Selectable {

void select(String value) {
browser.js.exec(firstElement(), value, "...")
}
}
ZurbNavigator implements Selectable {

void select(String value) {
browser.js.exec(firstElement(), value, "...")
}
}
The innerNavigatorFactory could be used I suppose but something like:

static content = {
bootstrapDropdown(wait: true) { $bootstrap("#jqueryDropdown") }
zurbDropdown(wait: true) { $zurb("#zurbDropdown") }`
}
Would be nice. I would like to write geb navigators for different widget toolkits but using the same interfaces. Do you see a clean way to do this?

Marcin Erdmann

unread,
Jul 11, 2016, 4:56:21 PM7/11/16
to Geb User Mailing List
Hi Jose,

I would use a module instead of a custom navigator, because it's easier to implement a module than dealing with a custom navigator factory and module is-a navigator (http://www.gebish.org/manual/current/#code-module-code-is-a-code-navigator-code). I can't spot a difference between your Bootstrap and Zurb controls so I will only give example for one of them:

class BootstrapSelectModule extends Module implements Selectable {
    void select(String value) {
        browser.js.exec(firstElement(), value, "...")    
    }
}

and then:

static content = {
     bootstrapDropdown { $("#jqueryDropdown").module(BootstrapSelectModule) }
}

What's more, instead of having a custom select() method, you could override value() and value(Object) methods (i.e. http://www.gebish.org/manual/current/api/geb/navigator/Navigator.html#value() and http://www.gebish.org/manual/current/api/geb/navigator/Navigator.html#value(def)) which will create a more idiomatically Geb API for your module.

Hope this helps,
Marcin


--
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.
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/f5722893-c62b-48de-86c0-b7ab6329edf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeff Lowery

unread,
Jul 15, 2016, 12:56:35 PM7/15/16
to geb-...@googlegroups.com
if I do:

waitFor 10, {…}

is there a way to see if it took, for example, 8 seconds?

— Jeff

Marcin Erdmann

unread,
Jul 16, 2016, 10:02:36 AM7/16/16
to Geb User Mailing List
No, there isn't. What is your use case?


— Jeff

--
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.
To post to this group, send email to geb-...@googlegroups.com.

Lowery, Jeff

unread,
Jul 16, 2016, 4:04:04 PM7/16/16
to geb-...@googlegroups.com

I'd like to log the actual response times in stdout.


Marcin Erdmann

unread,
Jul 17, 2016, 5:39:49 AM7/17/16
to Geb User Mailing List
This could be achieved in the future by adding support for passing a WaitStatisticsListener instance to waitFor() calls. It would be a single abstract method interface which would mean that a closure can be used instead and it would get passed a statistics object after completion of a waitFor() all containing number of tries, waiting time and status so that you could implement any custom logic via such listener.

Please feel free to add an issue for this if you're interested in this being delivered in a future release. 

Reply all
Reply to author
Forward
0 new messages