Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

geb-bot opened this issue Jul 15, 2011 · 9 comments
Assignees
Milestone

Comments

@geb-bot
Copy link

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
Copy link
Author

geb-bot commented Jul 15, 2011

This issue relates to #235

@geb-bot
Copy link
Author

geb-bot commented Jul 15, 2011

This issue relates to #236

@geb-bot
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

geb-bot commented Sep 14, 2012

Originally posted by Luke Daley.

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

@geb-bot
Copy link
Author

geb-bot commented Sep 14, 2012

Resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants