Skip to content

Commit

Permalink
Add geb-testng module
Browse files Browse the repository at this point in the history
  • Loading branch information
zolotov committed Jun 1, 2011
1 parent 6f2117e commit fba3723
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 4 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ allprojects {
groovyModules = [
":module:geb-core", ":module:test-utils",
":module:geb-spock", ":module:geb-junit3", ":module:geb-junit4",
":module:geb-easyb"
":module:geb-easyb", ":module:geb-testng"
]

publishedModules = [
":module:geb-core", ":module:geb-spock",
":module:geb-junit3", ":module:geb-junit4", ":module:geb-easyb",
":doc:manual"
":module:geb-testng", ":doc:manual"
]
}

Expand Down Expand Up @@ -268,4 +268,4 @@ task test(dependsOn: getTasksByName("test", true)) << {

task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-3'
}
}
10 changes: 10 additions & 0 deletions module/geb-testng/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
dependencies {
compile project(':module:geb-core')
compile "org.testng:testng:6.0.1"
testCompile project(":module:test-utils")
}

modifyPom = { pom ->
// User provides their own testng
pom.dependencies.removeAll(pom.dependencies.findAll { it.groupId == "org.testng" })
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package geb.testng

class GebReportingTest {
}
55 changes: 55 additions & 0 deletions module/geb-testng/src/main/groovy/geb/testng/GebTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package geb.testng

import geb.Browser
import org.openqa.selenium.WebDriver
import org.testng.annotations.AfterMethod;

class GebTest {
private _browser

Browser getBrowser() {
if (_browser == null) {
_browser = createBrowser()
}
_browser
}

void resetBrowser() {
_browser = null
}

def methodMissing(String name, args) {
getBrowser()."$name"(*args)
}

def propertyMissing(String name) {
getBrowser()."$name"
}

def propertyMissing(String name, value) {
getBrowser()."$name" = value
}

Browser createBrowser() {
def driver = createDriver()
def baseUrl = getBaseUrl()

driver ? new Browser(driver, baseUrl) : new Browser(baseUrl)
}

WebDriver createDriver() {
null // use Browser default
}

String getBaseUrl() {
null
}

@AfterMethod
void clearBrowserCookies() {
if (browser.config.autoClearCookies) {
browser.clearCookiesQuietly()
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* Copyright 2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package geb.testng

import geb.test.util.CallbackHttpServer
import org.testng.annotations.BeforeMethod
import org.testng.annotations.AfterMethod
import org.testng.annotations.Test

class GebReportingTestTest extends GebReportingTest {

def server = new CallbackHttpServer()

static private counter = 0

static responseText = """
<html>
<body>
<div class="d1" id="d1">d1</div>
</body>
</html>
"""

@BeforeMethod
void setUp() {
server.start()
server.get = { req, res ->
res.outputStream << responseText
}
super.setUp()
go()
}

String getBaseUrl() {
server.baseUrl
}

File getReportDir() {
new File("build/geb-output")
}

def getClassReportDir() {
new File(getReportDir(), this.class.name.replace('.', '/'))
}

@Test
void a() {
doTestReport()
}

@Test
void b() {
doTestReport()
}

@Test
void c() {
doTestReport()
}

def doTestReport() {
if (++counter > 1) {
def report = classReportDir.listFiles().find { it.name.startsWith((counter - 1).toString()) }
assert report.exists()
assert report.text.contains('<div class="d1" id="d1">')
}
}

@AfterMethod
void tearDown() {
server.stop()
super.tearDown()
}
}
75 changes: 75 additions & 0 deletions module/geb-testng/src/test/groovy/geb/testng/GebTestTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Copyright 2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package geb.testng

import geb.Page
import geb.test.util.CallbackHttpServer
import org.testng.annotations.AfterMethod
import org.testng.annotations.BeforeMethod
import org.testng.annotations.Test

class GebTestTest extends GebTest {

def server = new CallbackHttpServer()

@BeforeMethod
void setUp() {
server.start()
server.get = { req, res ->
res.outputStream << """
<html>
<body>
<div class="d1" id="d1">d1</div>
</body>
</html>"""
}
super.setUp()
}

String getBaseUrl() {
server.baseUrl
}

@Test
void missingMethodsAreInvokedOnTheDriverInstance() {
// This also verifies that the driver instance is instantiated correctly
go("/")
}

@Test
void missingPropertyAccessesAreRequestedOnTheDriverInstance() {
page SomePage
assert prop == 1
}

@Test
void missingPropertyAssignmentsAreForwardedToTheDriverInstance() {
page SomePage
prop = 2
assert prop == 2
}

@AfterMethod
void tearDown() {
server.stop()
super.tearDown()
}
}

class SomePage extends Page {

def prop = 1
}
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ include "module:geb-core",
"module:geb-junit3",
"module:geb-junit4",
"module:geb-grails",
"module:geb-testng",
"module:geb-easyb",
"doc:manual",
"doc:site-app"

if (hasProperty("withSamples")) {
include "samples:google"
}
}

0 comments on commit fba3723

Please sign in to comment.