Index: ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/ALL.java =================================================================== diff -u -r18695 -r18713 --- ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/ALL.java (.../ALL.java) (revision 18695) +++ ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/ALL.java (.../ALL.java) (revision 18713) @@ -1,6 +1,7 @@ package test.forgon.disinfectsystem.selenium; import java.io.File; +import java.io.FilenameFilter; import java.text.SimpleDateFormat; import org.apache.commons.io.FileUtils; @@ -18,6 +19,8 @@ import org.testng.annotations.AfterTest; import org.testng.annotations.Test; +import com.forgon.tools.util.PathUtils; + import test.forgon.disinfectsystem.AbstractCSSDTest; import test.forgon.disinfectsystem.selenium.apply.applyConstants.DeskIconEnum; import test.forgon.disinfectsystem.selenium.apply.chain.ChainConsumer; @@ -401,15 +404,32 @@ } if (session != null){ + + String webAppRootPath = PathUtils.getWebAppRootPath(); + String buildTempPath = webAppRootPath.replaceAll("/src/main/webapp", "/build/tmp"); + + // 删除之前产生的png文件 + final File folder = new File(buildTempPath); + + final File[] files = folder.listFiles(new FilenameFilter() { + public boolean accept(final File dir, final String name) { + return name.endsWith(".png") && name.startsWith("screenshot"); + } + }); + for (final File file : files) { + if (!file.delete()) { + System.err.println("无法删除文件:" + + file.getAbsolutePath()); + } + } + + // 截图 File scrFile = ((TakesScreenshot) Utils.driver) .getScreenshotAs(OutputType.FILE); - // Now you can do whatever you need to do with it, for example - // copy - // somewhere String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss") .format(new java.util.Date()); - FileUtils.copyFile(scrFile, new File("c:\\temp\\screenshot-" + FileUtils.copyFile(scrFile, new File(buildTempPath + "/screenshot-" + timeStamp + ".png")); } } catch (Exception e) {