0

我想运行并行屏幕截图测试,但出现错误。我提高了 Xmx 和 Xms,它们并没有吃掉我所有的 RAM,我有 32gb。但是他们在吃掉它定义的记忆后随机点失败。有内存优化的解决方案吗?我在某处有 18 张以上的图片,PNG 格式大约需要 200-600-800kb

这是 gradle.properties。

org.gradle.parallel=false
org.gradle.caching=false
org.gradle.console=verbose
org.gradle.jvmargs=-Xmx16g -Xms4g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
systemProp.junit.jupiter.execution.parallel.enabled=true
systemProp.junit.jupiter.execution.parallel.mode.default=concurrent
systemProp.junit.jupiter.execution.parallel.mode.classes.default=concurrent
systemProp.junit.jupiter.execution.parallel.config.strategy=dynamic
systemProp.junit.jupiter.execution.parallel.config.dynamic.factor=1

我的进口,有最新版本的库。

import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.comparison.ImageDiff;
import ru.yandex.qatools.ashot.comparison.ImageDiffer;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

还有一些我发现差异的代码

    protected int differenceBetweenPages(String pageName,
                                         String actualUrl,
                                         int scrollTime) throws IOException {
        open(actualUrl);
        actual = capturePage(scrollTime);
        ImageIO.write(actual.getImage(), "png", actualImg(pageName));

        attach = new FileInputStream(actualImg(pageName));
        Allure.addAttachment("Actual page", "image/png", attach, ".png");
        attach.close();

        expected = expectedScreenshot(pageName);
        diff = new ImageDiffer().makeDiff(expected, actual);
        ImageIO.write(diff.getMarkedImage(), "png", diffImg(pageName));

        attach = new FileInputStream(diffImg(pageName));
        Allure.addAttachment("Diff Page", "image/png", attach, ".png");
        attach.close();

        return diff.getDiffSize();
    }

4

1 回答 1

0

我在使用 Ashot 库时也遇到了问题。我改用了 ShutterBug,它工作正常。 https://github.com/assertthat/selenium-shutterbug

build.gradle 片段

compile 'com.assertthat:selenium-shutterbug:0.9.2'

用于捕获页面截图并将其附加到 Allure 报告的 API

@Attachment(value = "Page screenshot", type = "image/png")
    public static byte[] captureScreenshot(WebDriver driver) {

        BufferedImage screenshot = Shutterbug.shootPage(driver, ScrollStrategy.WHOLE_PAGE, true).getImage();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        try {
            ImageIO.write(screenshot, "png", outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return outputStream.toByteArray();

    }
于 2019-12-10T17:42:31.563 回答