我正在使用selenide、testng和allure reports.My,我的目标是将控制台日志打印到我正在使用的魅力报告中,使用以下代码(演示)添加控制台上打印的文本,以附加到我的魅力报告中:
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
我怎么才能修复它?
发布于 2021-09-23 13:33:01
通过将以下代码添加到我的浏览器设置方法中,我实现了这一点:
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(BROWSER, Level.ALL);
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);并将此代码添加到我的代码中,该代码处理诱惑力报告的生成:
List<String> logs = Selenide.getWebDriverLogs(LogType.BROWSER);
Allure.addAttachment("Console logs: ", logs.toString());发布于 2018-10-10 21:22:47
我正在用于日志的..
受保护的静态无效日志(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);
}
}https://stackoverflow.com/questions/48510170
复制相似问题