1

I am having an issue where if I run a test that has 6 steps, 3 pass, 1 fail, 2 skipped. It will always report as Passed in my extent reports. I am using Klov. Is it possible that I have not correctly configured the report? and if so does anyone have suggestions to fix this issue.

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

}

And here is my test, it is just a simple test that opens googles login page, just to make sure the extent reports will do everything I need it to

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();
}
}
  • Your approach is flawed.. you need hooks to report back to extent of the status of your tests. For cucumber use the CucumberExtentReporter plugin. Otherwise for testng, see the good example in docs. – Karthik Jul 24 '18 at 21:38
  • Thank you, I will change the way I am implementing it – caseyprogramming Jul 25 '18 at 13:24
  • the new code shown above is giving me the correct results when I go to builds but the overall pie chart on the main dashboard page still has every test passing which is what I am now trying to resolve. – caseyprogramming Jul 26 '18 at 20:27
  • Are you using cucumber? – Karthik Jul 26 '18 at 23:37
  • yes cucumber and may possibly implement serenity – caseyprogramming Jul 27 '18 at 13:12
  • https://github.com/email2vimalraj/CucumberExtentReporter is a good plugin to use. – Karthik Jul 27 '18 at 13:45
  • yes I have actually been using that plugin, the only issue i am having now is on the main dashboard page where there is a pie chart for total tests it says that 10,662 tests passed when that is not the case when i go to the builds tab it will tell me accurate information such as which tests failed/passed/skipped etc. – caseyprogramming Jul 27 '18 at 14:07
  • Can you open a ticket in the repo and check with Dev? Wr use this plugin and have no such issues.. – Karthik Jul 27 '18 at 14:35

1 Answers1

0

You should use ITestListener Interface on your Listener class where extent report's test is created OnTestStart and do other things alos as descriobed below (I have used Thread for parallel device testing so you can ignore, rest is useful)

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