我正在制作硒范围报告,但我收到了错误 - 静态最终ExtentReports extrpt = ExtentReports.get(ReportClass.class); 鼠标盘旋后,我得到以下信息。 对于ExtentReports类型,方法get(class)是未定义的 这是我简单的java项目,请告诉我我在哪里做错了。
package DemoPacakge;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
public class ReportClass {
// * ReportClass .class will become TheClassName.class
static final ExtentReports extrpt=ExtentReports.get(ReportClass.class);
public void test()
{
WebDriver driver =new FirefoxDriver();
driver.get("http://learn-automation.com/advance-selenium-reporting-with-screenshots/");
String tile=driver.getTitle();
Assert.assertTrue(tile.contains("learn"));
}
}
答案 0 :(得分:0)
请参阅示例部分:http://extentreports.relevantcodes.com/1x/docs.html#examples
有一些错误,例如,您没有使用“文件路径”初始化报告。您还没有指示Extent开始测试。尝试使用以下代码,它应该工作:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.LogStatus;
public class ReportClass {
static final ExtentReports extrpt = ExtentReports.get(ReportClass.class);
WebDriver driver;
@BeforeClass
public void beforeClass() {
extrpt.init("file-path.html", true);
extrpt.config().displayCallerClass(false);
}
@Test
public void test() {
extrpt.startTest("Test");
driver = new FirefoxDriver();
extrpt.log(LogStatus.INFO, "Starting FirefoxDriver..");
driver.get("http://learn-automation.com/advance-selenium-reporting-with-screenshots/");
extrpt.log(LogStatus.INFO, "Navigating to learn-automation.com..");
String title = driver.getTitle();
extrpt.log(LogStatus.INFO, "Title: " + title);
try {
Assert.assertTrue(title.contains("learn"));
extrpt.log(LogStatus.PASS, "Step Passed");
}
catch (AssertionError e) {
extrpt.log(LogStatus.FAIL, "<pre>" + e.getMessage() + "</pre>");
}
}
@AfterTest
public void afterTest() {
driver.quit();
extrpt.endTest();
}
}