所以我编写了我的第一个 Geb 脚本,它扩展了 GebReportingSpec。我已经指定了一个 def 清理,我在其中执行了 driver.quit()。现在浏览器确实关闭了,但我收到一个错误,因为屏幕截图实用程序无法运行,因为我猜它在浏览器关闭后运行。我试着入睡看看是否是问题所在,但什么也没做
JUnit 4 Runner, Tests: 1, Failures: 1, Time: 25944Test Failure: Validate that the default time zone for store is set to America/New_York(groovy.manager.ReferenceStoreDefaultTimeZoneTests)org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called.Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.3', java.
version: '1.6.0_43'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute
(FirefoxDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
va:527)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
va:569)
at org.openqa.selenium.remote.RemoteWebDriver.getPageSource(RemoteWebDri
ver.java:414)
at geb.report.PageSourceReporter.getPageSource(PageSourceReporter.groovy
:39)
at geb.report.PageSourceReporter.writePageSource(PageSourceReporter.groo
vy:35)
at geb.report.PageSourceReporter.writeReport(PageSourceReporter.groovy:2
7)
at geb.report.ScreenshotAndPageSourceReporter.writeReport(ScreenshotAndP
ageSourceReporter.groovy:31)
at geb.Browser.report(Browser.groovy:731)
at geb.spock.GebReportingSpec.report(GebReportingSpec.groovy:43)
at geb.spock.GebReportingSpec.cleanup(GebReportingSpec.groovy:39)
想法?
编辑:
驱动程序是通过 GebConfig 文件创建的
@Grab(group='org.seleniumhq.selenium', module='selenium-firefox-driver',
version='2.31.0')
@Grab(group='org.seleniumhq.selenium', module='selenium-chrome-driver',
version='2.31.0')
@Grab(group='org.seleniumhq.selenium', module='selenium-htmlunit-driver',
version='2.31.0')
@Grab("org.seleniumhq.selenium:selenium-support:2.28.0")
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.htmlunit.HtmlUnitDriver
reportsDir = "target/geb-reports"
// default is to use firefox
driver = {
def driver = new FirefoxDriver()
driver.manage().window().maximize()
return driver
}
environments {
'chrome' {
def chromePath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
System.setProperty("webdriver.chrome.driver", chromePath)
driver = {
def driver = new ChromeDriver()
return driver
}
}
'firefox' {
driver = {
def driver = new FirefoxDriver()
driver.manage().window().maximize()
return driver
}
}
'htmlunit' {
driver = {
def driver = new HtmlUnitDriver()
driver.javascriptEnabled = true
return driver
}
}
}
这是正在执行的脚本
package groovy.manager
@Grab( 'org.spockframework:spock-core:0.7-groovy-2.0' )
@Grab(group='org.gebish', module='geb-core', version='0.9.0-RC-1')
@Grab(group='org.gebish', module='geb-spock', version='0.9.0-RC-1')
@Grab(group='org.seleniumhq.selenium', module='selenium-firefox-driver',
version='2.31.0')
import geb.spock.GebReportingSpec
import org.openqa.selenium.firefox.FirefoxDriver
import groovy.manager.pages.LoginPage
import groovy.manager.pages.org.OrganizationHomePage
import groovy.manager.pages.org.OrganizationProfilePage
class ReferenceStoreDefaultTimeZoneSpec extends GebReportingSpec {
def "Validate that the default time zone is set to America/New_York"() {
given: "You have the admin username and password"
def username = "admin"
def password = "test"
when: "Navigate to Manager"
to LoginPage
and: "Log intoManager"
usernameInput().value username
passwordInput().value password
submitBtn().click()
then:
assert at (OrganizationHomePage)
and:
assert ( {$("a[value='America/New York']")} )
when: "Navigate to the organization profile"
timeZoneLink().click()
then:
assert at (OrganizationProfilePage)
and: "Verify America New York is selected"
assert ( $("span", text: contains("America/New York")) )
}
}