Kirill Kogan
Kirill Kogan

Reputation: 35

allure report +selenide, Attached console print log is empty

I am using selenide, testng and allure reports.My goal is just print console logs into the allure report I am using below code (demo)to add text printed on console to attach to my allure reports :

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

}

The problem is that the printLog is empty screenshot

how i can fix it ?

Upvotes: 1

Views: 2263

Answers (2)

Michael Dally
Michael Dally

Reputation: 194

I got this working by adding this to my browser setup method:

LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(BROWSER, Level.ALL);
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);

And added this to my code which handles the allure report generation:

List<String> logs = Selenide.getWebDriverLogs(LogType.BROWSER);
Allure.addAttachment("Console logs: ", logs.toString());

Upvotes: 1

i am using for logs..

protected static void log(String 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);
    }
}

Upvotes: 0

Related Questions