running a geb test from a java class

烈酒焚心 提交于 2019-12-02 00:45:45

Geb is designed for, and can only be used from, Groovy code. This is mainly due to the dynamic nature of its APIs. What you can choose is which test framework to use (JUnit, TestNG, Spock, etc.). As Geb itself is just a library, it can also be used without a test framework, for example to automate an interaction with a website.

If you need to stick to Java, you'll have to use something like Selenium2, which is what Geb uses under the covers.

I stumpled upon this question while searching a Geb-TestNG example. Here is what is working for me:

import geb.testng.GebTest
import org.testng.annotations.Test


class GroovyYourTestClass extends GebTest {

    @Test
    void "should test something"() {
        to YourPageObject
        // ...
    }
}

The best alternative to Geb if you're using Java is IMHO Selenide (http://selenide.org)

example from Quick Start Guide:

@Test
public void userCanLoginByUsername() {
  open("/login");
  $(By.name("user.name")).setValue("johny");
  $("#submit").click();
  $(".loading_progress").should(disappear); // Waits until element disappears
  $("#username").shouldHave(text("Hello, Johny!")); // Waits until element gets text
}

It's independent from your testing framework and therefore can be used with e.g. JUnit, TestNG, Cucumber, ScalaTest, JBehave

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!