首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >诱人报告+selenide,附加控制台打印日志为空

诱人报告+selenide,附加控制台打印日志为空
EN

Stack Overflow用户
提问于 2018-01-30 05:20:29
回答 2查看 1.2K关注 0票数 1

我正在使用selenide、testng和allure reports.My,我的目标是将控制台日志打印到我正在使用的魅力报告中,使用以下代码(演示)添加控制台上打印的文本,以附加到我的魅力报告中:

代码语言:javascript
复制
import com.codeborne.selenide.testng.TextReport;
import com.codeborne.selenide.testng.annotations.Report;

import io.qameta.allure.Attachment;

import org.openqa.selenium.By;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.Condition.enabled;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.*;

import java.io.IOException;
import java.util.List;

@Report
@Listeners(TextReport.class)
public class GoogleTestNGTest {

    @Attachment
    public String logOutput(List<String> outputList) {
        String output = "";
        for (String o : outputList)
            output += o + " ";
        return output;
    }

    @AfterMethod
    protected void printLog(ITestResult testResult) throws IOException {
        logOutput(Reporter.getOutput(testResult));
    }

    @BeforeMethod
    public void setUp() {
        TextReport.onSucceededTest = true;
        TextReport.onFailedTest = true;
        open("http://google.com/ncr");
    }

    @Test(enabled = true)
    public void failingMethod() {
        $(By.name("q")).shouldBe(visible, enabled);
        $("#missing-button").click();
    }

    @Test
    public void successfulMethod() {
        $(By.name("q")).setValue("selenide").pressEnter();
        $$("#ires .g").shouldHave(size(10));
    }

}

问题是printLog为空的screenshot

我怎么才能修复它?

EN

回答 2

Stack Overflow用户

发布于 2021-09-23 13:33:01

通过将以下代码添加到我的浏览器设置方法中,我实现了这一点:

代码语言:javascript
复制
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(BROWSER, Level.ALL);
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);

并将此代码添加到我的代码中,该代码处理诱惑力报告的生成:

代码语言:javascript
复制
List<String> logs = Selenide.getWebDriverLogs(LogType.BROWSER);
Allure.addAttachment("Console logs: ", logs.toString());
票数 1
EN

Stack Overflow用户

发布于 2018-10-10 21:22:47

我正在用于日志的..

受保护的静态无效日志(String stringToLog) {

代码语言:javascript
复制
    final String uuid = UUID.randomUUID().toString();

    final StepResult result = new StepResult()
            .withName(stringToLog);

    getLifecycle().startStep(uuid, result);

    try {
        getLifecycle().updateStep(uuid, s -> s.withStatus(Status.PASSED));
    } finally {
        getLifecycle().stopStep(uuid);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48510170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档