Создать скриншот - Allure, JUnit5, Selenium - PullRequest
0 голосов
/ 03 сентября 2018

Есть ли документация по этому поводу? JUnit4 имеет @Rule, и решение является простым. Для JUnit5 я сделал расширение public class TestWatcher implements AfterTestExecutionCallback, но я не знаю, что добавить в метод @Override.

Ответы [ 2 ]

0 голосов
/ 09 сентября 2018

Мне удалось решить это. По умолчанию используется метод захвата экрана:

@Attachment(value = "{testName} - screenshot", type = "image/png")
private byte[] makeScreenshotOnFailure(String testName) {

    return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}

и TestWatcher (расширение):

@Override
public void afterTestExecution(ExtensionContext extensionContext) throws Exception {

    Object test = extensionContext.getRequiredTestInstance();
    Field a = test.getClass().getDeclaredField("driver");
    a.setAccessible(true);
    driver = (WebDriver) a.get(test);

    Method method = extensionContext.getRequiredTestMethod();
    if (extensionContext.getExecutionException().isPresent()) {
        makeScreenshotOnFailure(method.getName());
    }
}
0 голосов
/ 04 сентября 2018

Вы можете найти образец здесь . Это код из NoraUi Open Source Framework (Java + Selenium).

import org.openqa.selenium.TakesScreenshot;

final byte[] screenshot = ((TakesScreenshot) Context.getDriver()).getScreenshotAs(OutputType.BYTES); 
...