forked from geb/geb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
236 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }) | ||
} |
4 changes: 4 additions & 0 deletions
4
module/geb-testng/src/main/groovy/geb/testng/GebReportingTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
55
module/geb-testng/src/main/groovy/geb/testng/GebTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
module/geb-testng/src/test/groovy/geb/testng/GebReportingTestTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
75
module/geb-testng/src/test/groovy/geb/testng/GebTestTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters