selenium - 范围报告测试总是报告通过
问题描述
我遇到了一个问题,如果我运行一个包含 6 个步骤、3 个通过、1 个失败、2 个跳过的测试。在我的范围报告中,它将始终报告为已通过。我正在使用克洛夫。是否有可能我没有正确配置报告?如果是这样,是否有人有解决此问题的建议。
public class MyRunner {
@BeforeClass
public static void initialize(){
d = new Date();
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setKlovServerUrl("http://localhost");
extentProperties.setKlovProjectName("Test Project");
extentProperties.setKlovReportName("Test Report: " + d);
extentProperties.setMongodbHost("localhost");
extentProperties.setMongodbPort(27017);
extentProperties.setMongodbDatabase("klov");
}
}
@AfterClass
public static void teardown(ITestResult result){
extent.flush();
}
}
这是我的测试,它只是一个打开谷歌登录页面的简单测试,只是为了确保范围报告能够完成我需要的一切
public class Google {
WebDriver driver;
@Given("^that I am on the webpage Google$")
public void thatIAmOnTheWebpageGoogle() throws Throwable {
System.setProperty("webdriver.chrome.driver","\\\\hiscox.nonprod\\profiles\\Citrix\\XDRedirect\\CaseyG\\Desktop\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("https://accounts.google.com/signin/v2/identifier?hl=en&passive=true&continue=https%3A%2F%2Fwww.google.com%2F&flowName=GlifWebSignIn&flowEntry=ServiceLogin");
driver.manage().window().maximize();
MyRunner.logger.log(Status.INFO, "Opened Google login page")
//throw new PendingException();
//extent.createTest("Step 1").pass("log");
}
@When("^I try to login$")
public void i_try_to_login() throws Throwable {
// find the username field and enters the username, then clicks next
WebElement username = driver.findElement(By.xpath("//input[@id='identifierId']"));
username.sendKeys("********");
driver.findElement(By.id("identifierNext")).click();
//finds the password field and enters the password
WebElement password = driver.findElement(By.xpath("//input[@name='password']"));
password.sendKeys("**********");
Assert.assertFalse(true);
driver.findElement(By.id("passwordNext")).click();
//throw new PendingException();
//extent.createTest("Step 2").pass("log");
}
@Then("^I will be successfully logged into Google$")
public void i_will_be_successfully_logged_into_Google() throws Throwable {
String account = "Google Account: greg casey \n" + "(klovtest@gmail.com)";
//WebElement loggedInUser = driver.findElement(By.xpath("//*[@id="gbw"]/div/div/div[2]/div[4]/div[1]"))
//*[@id="gbw"]/div/div/div[2]/div[4]/div[1]/a
//extent.createTest("Step 3").pass("log");
throw new PendingException();
}
}
解决方案
您应该在侦听器类上使用 ITestListener 接口,在该类中创建范围报告的测试 OnTestStart 并执行下面描述的其他操作(我已使用 Thread 进行并行设备测试,因此您可以忽略,休息很有用)
public class Listeners extends Utilities implements ITestListener {
ExtentReports extent = ExtentReporterTool.getReport();enter code here
ExtentTest test;
ThreadLocal<ExtentTest> testObjects = new ThreadLocal<ExtentTest>();
@Override
public void onTestStart(ITestResult result) {
test = extent.createTest(result.getMethod().getMethodName());
testObjects.set(test);
}
@Override
public void onTestSuccess(ITestResult result) {
testObjects.get().log(Status.PASS, "Test Case passed");
}
@Override
public void onTestFailure(ITestResult result) {
testObjects.get().fail(result.getThrowable());
WebDriver driver;
try {
driver = (WebDriver) result.getTestClass().getRealClass().getSuperclass().getField("driver")
.get(result.getInstance()); testObjects.get().addScreenCaptureFromPath(takeScreenshot(result.getMethod().getMethodName(), driver),
result.getMethod().getMethodName());
} catch (IOException | IllegalArgumentException | SecurityException | IllegalAccessException
| NoSuchFieldException e) {
e.printStackTrace();
}
}
@Override
public void onTestSkipped(ITestResult result) {
testObjects.get().log(Status.SKIP, "Test Case skipped");
}
@Override
public void onFinish(ITestContext context) {
extent.flush();
}
}
推荐阅读
- parsing - 如何重写此语法以进行 LL(1) 解析?
- java - 即使应用程序关闭,也试图保持 MQTT 客户端连接
- android - 我想手动将用户添加到 Firebase 并尝试登录我的应用程序,但出现“请验证您的电子邮件以登录”之类的错误
- php - 如何将值设置为像 chaning 方法这样的数组?
- vba - MS Access VBA 生成基于查询的表
- python-3.x - 如何从多个小部件 ipywidgets 中获取观察值
- javascript - 如何按属性值的长度过滤重复项
- python - 如何在 Pandas 中将一行合并到最近的行(基于时间戳)?
- php - Codeigniter 3 显示带有子类别和产品的主类别
- excel - 小时:分钟的 Excel 格式代码,不带前导零