Intellij 中无法识别的 Geb DSL 模块

Geb DSL Modules unrecognized within Intellij

Going off the documentation here are Modules and other Geb DSL not expected to be recognized within a Spock Spec with IntelliJ? This makes using Geb with IntelliJ a bit cumbersome with no DSL reference. 提问者做了一些自定义工作来让 IntelliJ 包装并注意到 Geb DSL。

我的问题是我是不是做错了什么或者这是预料之中的,在让 IntelliJ 识别 Geb DSL 方面有任何进展吗?

如果没有,是否有人对此 issue/limitation 和/或另一个能够识别 Geb DSL 的 IDE 有解决方法?

IntelliJ 支持 Geb DSL,我已经使用它多年 there are even tests in IntelliJ's codebase that confirm it's there

如果您可以分享您的代码的外观以及哪些不适合您,那么也许我们可以找到您的设置或期望的问题。最好知道您使用的是社区版还是专业版。

请注意,您链接到的问题中讨论的问题已由我在 this PR 中修复,自 IntelliJ 2018.2 以来不再存在。

编辑:

在阅读了您在我的回复下发表的评论后,我现在明白问题出在哪里了。您期望 IntelliJ 能够在运行时确定页面类型并为您提供自动完成功能。恐怕这根本不可能 - 您需要在代码中跟踪当前页面实例,以便 IntelliJ 能够推断类型。

请注意 geb-example-gradle are written in the very concise, yet dynamic style which means that IntelliJ is not able to infer types. What you need to do is to use the strongly typed style as described in the documentation. That section of the docs could do with a bit of improvement because it's not precise - I've created a Github issue to track that.

中的测试

基本上,如果您将 GebishOrgSpec 从 geb-example-gradle 调整为:

class GebishOrgSpec extends GebSpec {

    def "can get to the current Book of Geb"() {
        when:
        def homePage = to GebishOrgHomePage

        and:
        homePage.manualsMenu.open()

        then:
        homePage.manualsMenu.links[0].text().startsWith("current")

        when:
        homePage.manualsMenu.links[0].click()

        then:
        at TheBookOfGebPage
    }
}

然后 IntelliJ 将为您提供自动完成功能。