public synchronized static void captureScreenshot(WebDriver driver, String screenshotName) {
try {
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("./Screenshots/"
+ screenshotName + ".png"));
System.out.println("Screenshot taken");
filePath=timestamp()+ screenshotName + ".png";
} catch (Exception e) {
System.out.println("Exception while taking screenshot "
+ e.getMessage());
}
}
CONSOLE LOGS: 截屏时出现异常处理命令时发生未知的服务器端错误。原始错误:无法代理。代理错误:60秒的新命令超时已过期。尝试使用' newCommandTimeout'来自定义超时。所需功能(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:660.36秒 构建信息:版本:' 2.44.0',修订版:' 76d78cf323ce037c5f92db6c1bba601c2ac43ad8',时间:' 2014-10-23 13:11:40' 系统信息:主持人:' DocASAP-mac-mini.local',ip:' 192.168.1.45',os.name:' Mac OS X',os .arch:' x86_64',os.version:' 10.11.5',java.version:' 1.7.0_79' 会话ID:f8bcc2d5-a00d-43c5-8a8a-157d2fbe6260 驱动程序信息:org.openqa.selenium.remote.RemoteWebDriver 功能[{platform = ANDROID,javascriptEnabled = true,acceptSslCerts = true,browserName = Browser,networkConnectionEnabled = true,desired = {newCommandTimeout = 60,platform = ANDROID,autoAcceptAlerts = true,acceptSslCerts = true,deviceName = 192.168.56.101:5555, platformName = Android,browserName = Browser,setAcceptUntrustedCertificates = true,version = 5.1.0},locationContextEnabled = false,deviceUDID = 192.168.57.101:5555,version = 5.1.0,newCommandTimeout = 60,platformVersion = 5.1,autoAcceptAlerts = true,databaseEnabled = false,deviceName = 192.168.57.101:5555,platformName = Android,webStorageEnabled = false,setAcceptUntrustedCertificates = true,warnings = {},takesScreenshot = true}]