我在尝试在Geb中截取屏幕时出现Cannot invoke method propertyMissing()
错误。
以下是课程
package geb.pages
import geb.Page
class MyLoginPage extends Page {
static url = "https://JSPNet.com/entry"
static at = { title == "My Login" }
....
signIn { $("#btnEnter span")}
def getScreenshots(){
File scrFile = ((TakesScreenshot)DriverInstance).getScreenshotAs(OutputType.FILE) ***** Error line ****
FileUtils.copyFile(scrFile, new File("D:\\tmp\\screenshot.png"))
}
}
我在上述课程中遇到与DriverInstance
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.firefox.FirefoxDriver
driver = {
System.setProperty("webdriver.chrome.driver", "D:\\MyFolder\\selenium-2.32.0\\chromedriver.exe")
def newdriver = new ChromeDriver()
DriverInstance = newdriver
return newdriver
}
environments {
chrome { driver = { new ChromeDriver() } }
firefox {driver = { new FirefoxDriver() }}
}
waiting {timeout = 5}
And(~'^hit the Login button$') { ->
page.signIn.click()
MyLoginPage = new MyLoginPage()
MyLoginPage.getScreenshots()
}
错误:
java.lang.NullPointerException: Cannot invoke method propertyMissing() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at geb.pages.MyLoginPage.getScreenshots(MyLoginPage.groovy:70)
at geb.pages.MyLoginPage$getScreenshots.call(Unknown Source)
答案 0 :(得分:1)
似乎DriverInstance
为空。您应该能够使用driver
属性访问驱动程序:
def getScreenshots(){
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File("D:\\tmp\\screenshot.png"))
}