Better Geb support for Intellij IDEA

148 views
Skip to first unread message

Vladimir Bolshitkin

unread,
Jul 17, 2018, 4:49:09 AM7/17/18
to Geb User Mailing List
Hello everyone!

I am new to Geb, and when I tried to use it I found it a bit hard to work productively without syntax highlighting, type inferring and navigation support. Originally I was using Eclipse, then found http://www.gebish.org/manual/0.10.0/ide-and-typing.html and tried IDEA Community Edition. It also did not satisfy me.

Out-of-the-box IDEA supports elements defined in static content block in Page subclasses and that is good, but in Test cases they remain unresolved:

to MyPage
testMethod()
testContent.click()

As described in the documentation, it works if you write 

MyPage myPage = to MyPage
myPage.testMethod()
myPage.testContent.click()


But that is more difficult to read. I also found possible syntax

to MyPage with {
  testMethod()
  testContent.click()
}

A bit better, but not perfect, cause might lead to several nested with-blocks.

So I decided to start a new small project and implement improved Geb support in IDEA using GDSL feature. Meet Geb-GDSL:


Now it supports the case described above. But I still don't know what cases are widespread in production Geb usage. So for those Geb users who already use IDEA for tests authoring I suggest to try Geb-GDSL. Github Issues with test-cases, pull-requests or any other feedback are welcome.

Regards, Vladimir

Marcin Erdmann

unread,
Jul 17, 2018, 5:44:18 PM7/17/18
to Geb User Mailing List
Hi Vladimir,

Thanks for sharing your work. It's interesting to see that you're looking for better support for autocompletion and navigation in code using Geb. I totally share your sentiment with regards to being more productive when the IDE understands the context of the code you write but I'm relatively happy with using the technique described in the the manual section about IDE support even if it leads to slightly more verbose code. Btw, a newer version than what you linked to is available at http://www.gebish.org/manual/current/#ide-support.

If tracking the page in your tests explicitly is something that you cannot accept then your idea with using with() method is indeed an improvement. I don't agree that it might lead to nested with() blocks as you can always do:

to MyPage with {
    ...
}

at AnotherPage with {
    ...
}

While I appreciate your effort with the GDSL I think it contains a number of deficiencies:
- it only works inside of JUnit tests and not within Spock tests which as far as I understand are far more popular amongst people using Geb,
- it only looks into at most 200 previous elements which seems like a fairly arbitrary limit,
- as far as I can tell it does not cater for page changes in control flow statements, but I might be wrong because I'm not that familiar with GDSL,
- it does not deal with page changes triggered using content template options, i.e. http://gebish.org/manual/current/#content-dsl-to

I personally believe that being explicit with regards to what is the current page type (as described in the IDE support section of the manual) will yield you better results than trying to deduce from the context of your code.

Marcin

P.s. In the next version of Geb which I'm hoping to release relatively soon there's also going to be a new at() method that takes a closure as the last parameter and IntelliJ will understand that the page type passed as the first parameter is the delegate of that closure. See http://gebish.org/manual/snapshot/#at-check-assertions-ide for more details.

--
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/0d374229-83f3-430c-b4ee-934d75891d78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vladimir Bolshitkin

unread,
Jul 18, 2018, 11:28:17 AM7/18/18
to Geb User Mailing List
Marcin, thanks for you feedback

1. I just pushed Spock support and basic support for withFrame method (without Page class passed as a parameter yet).
2. 200 elements limit will also be fixed soon, as recently I discovered great PsiTreeUtil that will ease traversing
3.regarding page changes inside control statements... they are recognized, but perhaps there is a bug there, so that if we write

if (1>2) {
  to ImpossiblePage
}


my code will think that the page is actually changed. What I think here is to recognize more than one previous page and add all possible methods from previous pages

It does not recognize page chages performed inside method calls, but I don't think it is a good idea to write code that way.

4. interesting feature, I didn't know about it. Will add it to backlog, but in fact it makes code less explicit.

I agree with you about importance of being explicit. My main goal is to allow being less verbose in cases where it does not reduce maintainability. Seems, Geb developers also move that way. 

Thank you for your time,
Vladimir
 
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages