1
我需要将结果值传递给我拥有的check
方法。将测试结果传递给使用Java的Selenium中的ITestResult
@Test
public void test1()
{
test = extent.createTest("Test Case 4 : Checking displayed date against current date",
"Checking if the date displayed on the check in and check out box is equal to the current date");
String checkin = driver.findElement(By.id("from")).getAttribute("value");
test.info(checkin);
String timeStamp = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
if (checkin.equals(timeStamp))
{
test.info("The checkin in date " + checkin + " is equal to the current date " + timeStamp);
} else
{
test.info("The checkin in date " + checkin + " does not equal the current date " + timeStamp);
}
}
@AfterMethod
public void check(ITestResult result) throws IOException
{
if (result.getStatus() == ITestResult.FAILURE)
{
String screenshotPath = GetScreenshot.capture(driver);
test.fail("Test Case Failed");
test.info(result.getThrowable());
test.info("Screenshot Below : " + test.addScreenCaptureFromPath(screenshotPath));
} else if (result.getStatus() == ITestResult.SKIP)
{
test.skip("Test Case Has Been Skipped");
} else
{
test.pass("Test Case Passed");
}
}
所以,我想做到的是,如果checkin
等于timeStamp
那么测试应该通过,如果checkin
不等于timeStamp
测试应该失败。对于我当前的代码,测试通过两种情况。
有无论如何,我可以通过test.fail()
什么的check
方法。我试过check(ITestResult.FAILURE);
哪个没有用。
我也试过check((ITestResult) test.fail("Test has Failed"));
,它投掷了ClassCastException
。