我正在GebReportingSpec
从内部运行以下脚本(一个测试用例)GroovyConsole.exe
。当 GroovyConsole 启动时,它第一次正常运行。它打开 FF,运行场景,然后在退出浏览器时关闭 FF。
但是,当我从同一个 GroovyConsole 再次运行同一个脚本时,我得到一个UnreachableBrowserException
. 它首先调用setupSpec()
方法,然后在调用go
测试用例中的方法时,它调用cleanupSpec()
...
GEB:0.9.0
硒:2.26.0
时髦的:2.0.5
法郎:14.0.1
JDK:1.6.0_37 64 位
脚本:
@Grapes([
@Grab("org.gebish:geb-core:0.9.0"),
@Grab("org.gebish:geb-spock:0.9.0"),
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.26.0"),
//@Grab("org.seleniumhq.selenium:selenium-chrome-driver:2.26.0"),
@Grab("org.seleniumhq.selenium:selenium-support:2.26.0")
])
import geb.Browser
import geb.spock.GebReportingSpec
import org.openqa.selenium.firefox.*
class Google_Search_Test extends GebReportingSpec {
def setupSpec() {
println "Inside setupSpec()..."
browser.config.autoClearCookies = true
}
def cleanupSpec() {
println "Inside cleanupSpec()..."
println "Quitting browser..."
browser.quit()
}
def "google_search_wikipedia"() {
println "Inside google_search_wikipedia..."
when:
println "Going to google.com..."
go "http://google.com/ncr"
// make sure we actually got to the page
assert title == "Google"
// enter wikipedia into the search field
$("input", name: "q").value("wikipedia")
// wait for the change to results page to happen
// (google updates the page dynamically without a new request)
waitFor { title.endsWith("Google Search") }
// is the first link to wikipedia?
def firstLink = $("li.g", 0).find("a.l")
then:
firstLink.text() == "Wikipedia"
println "Finished test execution..."
}
}
GebConfig.groovy:
import org.openqa.selenium.firefox.*
import java.util.concurrent.*
driver = {
FirefoxProfile firefoxProfile = new FirefoxProfile()
firefoxProfile.setPreference("capability.policy.default.Window.frameElement", "allAccess")
def driver = new FirefoxDriver(firefoxProfile)
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS)
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS)
driver
}
waiting {
// all values are in seconds
timeout = 60
retryInterval = 0.5
}
reportsDir = "SeleniumReports"
成功运行:
Inside setupSpec()...
Inside google_search_wikipedia...
Going to google.com...
Finished test execution...
Inside cleanupSpec()...
Quitting browser...
JUnit 4 Runner, Tests: 1, Failures: 0, Time: 15739
后续运行(异常):
Inside setupSpec()...
Inside google_search_wikipedia...
Going to google.com...
Inside cleanupSpec()...
Quitting browser...
JUnit 4 Runner, Tests: 1, Failures: 2, Time: 687
Test Failure: google_search_wikipedia(Google_Search_Test)
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.26.0', revision: '18040', time: '2012-11-02 09:44:45'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_37'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:526)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:275)
at geb.Browser.go(Browser.groovy:371)
at geb.Browser.go(Browser.groovy:363)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:51)
at Google_Search_Test.google_search_wikipedia(Google_Search.groovy:27)
Caused by: org.openqa.selenium.WebDriverException: The FirefoxDriver cannot be used after quit() was called.
Build info: version: '2.26.0', revision: '18040', time: '2012-11-02 09:44:45'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_37'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:351)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:505)
... 5 more
Test Failure: google_search_wikipedia(Google_Search_Test)
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.26.0', revision: '18040', time: '2012-11-02 09:44:45'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_37'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:526)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:535)
at org.openqa.selenium.remote.RemoteWebDriver.getPageSource(RemoteWebDriver.java:396)
at geb.report.PageSourceReporter.getPageSource(PageSourceReporter.groovy:42)
at geb.report.PageSourceReporter.writePageSource(PageSourceReporter.groovy:38)
at geb.report.PageSourceReporter.writeReport(PageSourceReporter.groovy:29)
at geb.report.CompositeReporter.writeReport(CompositeReporter.groovy:31)
at geb.Browser.report(Browser.groovy:698)
at geb.spock.GebReportingSpec.report(GebReportingSpec.groovy:43)
at geb.spock.GebReportingSpec.cleanup(GebReportingSpec.groovy:39)
Caused by: org.openqa.selenium.WebDriverException: The FirefoxDriver cannot be used after quit() was called.
Build info: version: '2.26.0', revision: '18040', time: '2012-11-02 09:44:45'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_37'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:351)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:505)
... 9 more