所以我寫了我的第一個Geb腳本,它擴展了GebReportingSpec。我已經指定了一個def cleanup,其中我做了一個driver.quit()。現在瀏覽器關閉了,但我得到一個錯誤,導致屏幕截圖實用程序無法運行,因爲我猜它在瀏覽器關閉後運行。我試圖把睡眠看到如果是這樣的問題,不過這沒有采取任何行動geb spock並關閉瀏覽器窗口
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")))
}
}
你是如何運行的測試類? – erdi 2013-03-28 10:31:05
從xterm2開始,運行groovy groovy/manager/ReferenceStoreDefaultTimeZoneSpec.groovy – jrock2004 2013-03-28 16:10:08