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

时间:2018-01-29 21:20:29

标签: selenium-webdriver allure selenide

我正在使用selenide,testng和诱惑报告。我的目标只是打印控制台日志到诱惑报告中 我使用下面的代码(演示)添加打印在控制台上的文本以附加到我的诱惑报告:

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

我怎么能解决它?

1 个答案:

答案 0 :(得分:0)

我正在使用日志。.

受保护的静态无效日志(字符串stringToLog){

    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);
    }
}