java创建的

c9x0cxw0  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(195)

我在我的 selenium 项目截图使用下面的方法

public String getScreenShotUrl(String fileName, Information information) {
    final String screenShotS3FolderName = "/test/s3"
    final String apiHistoryScreenshotUrl = "/test/history"
    new Thread(() -> {
        File screenshot = ((TakesScreenshot) information.getDriver()).getScreenshotAs(OutputType.FILE);
        contentHandler.moveScreenshotImageFileToS3(fileName, screenShotS3FolderName, screenshot);
    }).start();
    String crawlScreenshotUrl = apiHistoryScreenshotUrl + fileName + DOT_JPEG_FILE_EXTENSION;
    information.getAllScreenShotUrls().add(screenshotUrl);
    return crawlScreenshotUrl;
}

我没有在var/tmp文件夹中存储任何文件
我在用火狐83
geco司机:28
操作系统:linux
问题:
我看到里面有很多png文件

/var/tmp

screenshot18218906458183251330.png

现在确定是什么触发了我的firefox/selenium中的这个屏幕截图。
这是我的硬盘。如何阻止firefox截图。
不确定是哪个命令触发了这个。我最近升级到firefox-83,但不确定83是这个问题的原因

6mw9ycah

6mw9ycah1#

根据rahul命令,我明确地添加了delete命令。这就解决了添加screenshot.delete()//在不等待jvm退出的情况下显式删除文件的问题

public String getScreenShotUrl(String fileName, Information information) {
    final String screenShotS3FolderName = "/test/s3"
    final String apiHistoryScreenshotUrl = "/test/history"
    new Thread(() -> {
        File screenshot = ((TakesScreenshot) information.getDriver()).getScreenshotAs(OutputType.FILE);
        contentHandler.moveScreenshotImageFileToS3(fileName, screenShotS3FolderName, screenshot);
        screenshot.delete() // This delete the file once it is moved to s3
    }).start();
    String crawlScreenshotUrl = apiHistoryScreenshotUrl + fileName + DOT_JPEG_FILE_EXTENSION;
    information.getAllScreenShotUrls().add(screenshotUrl);
    return crawlScreenshotUrl;
}

相关问题