0
您好,我使用selelium和spock编写烟雾测试,我想截取测试失败的截图。尝试这样的:Selenium在失败时采取屏幕
public class ScreenshotTestRule implements MethodRule {
public Statement apply(final Statement statement, final FrameworkMethod frameworkMethod, final Object o) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
statement.evaluate()
} catch (Throwable t) {
captureScreenshot(frameworkMethod.getName().replaceAll(" ", "-"))
throw t
}
}
public void captureScreenshot(String fileName) {
try {
new File("target/surefire-reports/").mkdirs()
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE)
Files.copy(screenshot, new File("/target/surefire-reports/"+fileName+".png"))
} catch (Exception e) {
print "Error while creating screenshot " + fileName
throw new RuntimeException(e)
}
}
}
}
}
,但我收到此错误:
java.lang.RuntimeException: groovy.lang.MissingFieldException: No such field: driver for class: lt.inventi.apollo.system.test.SmokeTest$ScreenshotTestRule
好哪里'driver'从何而来?它在哪里创建?你确定你不想把它传递给captureScreenshot方法吗? – Arran
驱动程序是SmokeTest类字段,而ScreenShotTestRule类是内部的,所以我想它应该在这里可见 – IowA