running a geb test from a java class
Asked Answered
M

3

2

I've recently stumbled across geb and it looks like a good way to perform integration tests on our web applications. Our platforms are all java based and from reading that

"Geb provides first class support for functional web testing via integration with popular testing frameworks such as ...JUnit, TestNG..."

i assumed it would be easy to execute a test from a java class (testng test?).

I'm new to groovy and geb.

So far I have included geb-testng and groovy in my pom:

<dependency>
    <groupId>org.codehaus.geb</groupId>
    <artifactId>geb-testng</artifactId>
    <version>0.7.0</version>
</dependency>
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy</artifactId>
    <version>1.8.6</version>
</dependency>

... However i can't find any examples of creating a test and running it from a java class.

help appreciated.

Mump answered 20/6, 2012 at 0:48 Comment(0)
T
4

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.

Tune answered 20/6, 2012 at 17:48 Comment(0)
F
1

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
        // ...
    }
}
Foreclosure answered 20/3, 2014 at 15:16 Comment(0)
A
0

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

Appetizer answered 4/4, 2017 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.