Create an easy way to add some custom methods on Navigator #96

Closed
geb-bot opened this Issue Jul 15, 2011 · 9 comments

Projects

None yet

2 participants

@geb-bot
geb-bot commented Jul 15, 2011

Originally created by Marcin Erdmann.

In my test I quite often do:

button.displayed & !button.disabled

It would look much better if I could add a method on all Navigator objects like:
boolean isVisibleAndEnabled() {
displayed & !disabled
}

@geb-bot
geb-bot commented Jul 15, 2011

This issue relates to #235

@geb-bot
geb-bot commented Jul 15, 2011

This issue relates to #236

@geb-bot
geb-bot commented Oct 23, 2011

Originally posted by Alexander Zolotov.

I'm not sure that it realy need. IMHO, unnecessary and inappropriate complexity. IMHO again, Navigator should provide simple methods that allows to do everything, and not all possible combinations of existing methods.

Why not encapsulate this logic in your page-classes? In this case, you can create a base page class with method ensureVisibleAndEnabled (throws AssertException) and other similar methods, and use them in every child class where they are needed:

page:
def submitForm
ensureVisibleAndEnabled(submitButton).click
end

test:
page.submitForm

Or you can create testHelper that will have methods like that.
Or you can create base class for all you tests. If you are using junit or testng it will even be a good idea.
Or you can use hamcrest-library and create appropriate matchers.

May be I misunderstood you. Can you give an example of a real test and page classes that it uses?

@geb-bot
geb-bot commented Oct 24, 2011

Originally posted by Alex Anderson.

We inject behaviour into our Navigators (empty and non-empty) using metaClass.

We're using Grails, so we do the injection in grails-app/conf/BootStrap.groovy.

@geb-bot
geb-bot commented Oct 24, 2011

Originally posted by Marcin Erdmann.

@Alexander Zolotov
The issue itself is not about adding any methods to Navigator in Geb's core but allowing users to easily add them for themselves if they want/need/find it convenient. Also I completely agree that Navigator shouldn't get bloated in core and for sure shouldn't contain all combinations of current methods. But as I said, the issue is only about making it easy for people who wish to do so.

All of your suggestions (putting the method into a base page, a test helper, base class) seem logical and probably would do. The only thing I don't like about it is that you will have to write
isEnabledAndVisible(navigator) insted of navigator.enabledAndVisible. You are actually checking some properties on a navigator so why not ask the navigator to answer your question? For some it might be just sugar but I don't like those static helper methods. Using property access on navigator is definitely groovier and Geb is supposed to be a very groovy browser automation;).

@Alex Anderson
You're solution will work only if you run Geb and your Grails app within one JVM (so for example if you run your Geb tests using 'grails test-app functional:'). If you run them in two JVMs, i.e. keep your grails app runing while developing and frequently running tests from an IDE to save on startup time it won't work. You will have to put your Navigator metaClass manipulations into GebConfig. But still, I believe this to be a bit hacky solution, putting stuff in config when it doesn't belong there.

@geb-bot
geb-bot commented Oct 24, 2011

Originally posted by Marcin Erdmann.

Copy pasted from mailing list to better keep track of the discussion:

"I'm eager to take the issue on if only somebody has a hint on how to approach the problem. My only idea is to add the new method using Groovy categories which would be listed in GebConfig and then mixed in by the Geb code into all navigators - maybe in a static initializer for the Navigator class?"

@geb-bot
geb-bot commented Apr 11, 2012

Originally posted by Luke Daley.

My current thinking is that we will introduce a NavigatorFactory interface and a default impl. The factory instance will be retrieved from the config, which would allow users to inject their own factory if necessary.

@geb-bot
geb-bot commented Sep 14, 2012

Originally posted by Luke Daley.

Implemented via new NavigatorFactory mechanism, which can be injected via config.

@geb-bot
geb-bot commented Sep 14, 2012

Resolved

@geb-bot geb-bot added the Improvement label Apr 12, 2015
@alkemist alkemist was assigned by geb-bot Apr 12, 2015
@geb-bot geb-bot added this to the 0.9.0 milestone Apr 12, 2015
@geb-bot geb-bot closed this Apr 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment