GebSpec ElementNotVisibleException is being thrown from the wrong driver!

119 views
Skip to first unread message

Manny Rodriguez

unread,
May 26, 2016, 9:30:59 AM5/26/16
to Geb User Mailing List
I have read most of the (excellent) Geb documentation and have been familiarizing myself with the Geb API with examples that just run as main production code, completely outside the scope of any unit tests. I am now trying to familiarize myself with the Geb-Spock API so that I can write functional/UAT tests. Here is all my code:

  // Basic project structure (built w/ Gradle):
  geb-sandbox/
    src/
      main/
        groovy/
          sandbox.geb/
            GoogleHomepage.groovy
            GoogleSearchResultsPage.groovy
      test/
        groovy/
          sandbox.geb/
            MyFirstGebSpec.groovy
        resources/
          GebConfig.groovy
    build.gradle

  // Snippet from build.gradle:
  task firefoxTest(type: Test) {
      reports {
          html.destination = reporting.file('build/reports/tests')
      }

      outputs.upToDateWhen { false }

      systemProperty "geb.build.reportsDir", reporting.file('build/reports/geb')
      systemProperty "geb.build.reportsDir", 'firefox'
  }

  // GebConfig.groovy
  import org.openqa.selenium.firefox.FirefoxDriver

  waiting {
      timeout = 5
  }

  environments {
      firefox {
          driver = {
              new FirefoxDriver()
          }
      }
  }

  baseUrl = 'http://google.com'

  // GoogleHomepage.groovy:
  class GoogleHomepage extends Page {
      static url = 'http://google.com'

      static at = {
          title == 'Google'
      }

      static content = {
          search {
              $('input', name: 'q')
          }

          searchButton {
              $('button', name: 'btnG')
          }
      }
  }

  // GoogleSearchResultsPage.groovy:
  class GoogleSearchResultsPage extends Page {
      static at = {
          title == 'gmail - Google Search'
      }

      static content = {
          firstLink {
              $('h3.r > a')[0]
          }
      }
  }

  // MyFirstGebSpec.groovy:
  class MyFirstGebSpec extends GebSpec {
      void 'we can get to the gmail signin page'() {
          when:
          to GoogleHomepage
          search().value('gmail')
          searchButton.click()
          waitFor {
              at(GoogleSearchResultsPage)
          }
          firstLink.click()
          waitFor {
              at(GmailLandingPage)
          }
          signinLink.click()

          then:
          at GmailLandingPage
      }
  }

When I run ./gradlew firefoxTest, I get the following build error:

  :compileJava UP-TO-DATE
  :compileGroovy UP-TO-DATE
  :processResources UP-TO-DATE
  :classes UP-TO-DATE
  :compileTestJava UP-TO-DATE
  :compileTestGroovy
  :processTestResources
  :testClasses
  :firefoxTest

  sandbox.geb.MyFirstGebSpec > we can get to the gmail signin page FAILED
      org.openqa.selenium.ElementNotVisibleException at MyFirstGebSpec.groovy:38

  1 test completed, 1 failed
  :firefoxTest FAILED

  FAILURE: Build failed with an exception.

When I look at the test report, I see an actual stacktrace:

  org.openqa.selenium.ElementNotVisibleException: You may only interact with visible elements
  Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
  System info: host: 'BLAH', ip: 'BLAH', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_45'
  Driver info: driver.version: unknown
  at org.openqa.selenium.htmlunit.HtmlUnitWebElement.verifyCanInteractWithElement(HtmlUnitWebElement.java:282)
  at org.openqa.selenium.htmlunit.HtmlUnitWebElement.click(HtmlUnitWebElement.java:142)
  at geb.navigator.NonEmptyNavigator.click(NonEmptyNavigator.groovy:463)
  at geb.content.TemplateDerivedPageContent.click(TemplateDerivedPageContent.groovy:73)
  at sandbox.geb.MyFirstGebSpec.we can get to the gmail signin page(MyFirstGebSpec.groovy:38)

Obviously BLAH is not the actual value for my host/IP :-)

MyFirstGebSpec line 38 is this line:

  searchButton.click()

It's interesting to me that I'm specifying Firefox as the driver but the HTMLUnit driver is somehow being selected. Perhaps I'm configuring something wrong and the default is HTMLUnit? Anybody know why this search button isn't visible? Thanks!

Brian Kotek

unread,
May 26, 2016, 9:37:05 AM5/26/16
to Geb User Mailing List
Do you actually have HTMLUnit also set up as a task and driver option in your Gradle build script?

--
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/de118d95-c833-4d00-8f37-b2669eb3cb92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Manny Rodriguez

unread,
May 26, 2016, 10:17:22 AM5/26/16
to Geb User Mailing List
Thanks @brian428, no I don't have HTMLUnit set up as a task/driver option in build.gradle but I a bringing it in as a dependency ('org.seleniumhq.selenium:htmlunit-driver:2.21'), even though I'm not currently using it anywhere. I had previously tinkered around with it but have since then removed any code that uses it. Thoughts?

Brian Kotek

unread,
May 26, 2016, 12:18:28 PM5/26/16
to Geb User Mailing List
Not much to offer, other than it sounds like an issue with your Gradle script rather than an issue with Geb.

Marcin Erdmann

unread,
May 26, 2016, 3:53:15 PM5/26/16
to Geb User Mailing List
In your build.gradle, instead of:

systemProperty "geb.build.reportsDir", 'firefox'

You should use:

systemProperty "geb.env", 'firefox'

Manny Rodriguez

unread,
May 27, 2016, 9:32:28 AM5/27/16
to Geb User Mailing List
Thanks @Marcin - that was a copy-n-paste error on my end - your suggestion worked marvelously! Thanks again!
Reply all
Reply to author
Forward
0 new messages