Nullpointer when requesting execution - Extentreport

Asked

Viewed 26 times

1

Good afternoon Personal,

I’m having a hard time using the extent api. The way I developed my project is preventing you from taking the prints. I created a Drivefactory class that instantiates the driver and interacts with the elements, calling in the Steps classes. Below:

public class Driverfactory {

private static WebDriver driver;
private static ExtentHtmlReporter htmlReporter;
private static ExtentReports extentReport;
private static ExtentTest extentTest;

@Beforeclass
public Static void beforeCenario(Scenario cenario){

    if(driver == null) {


        switch (Propriedades.browser) {
            case FIREFOX: 
                    System.setProperty("webdriver.gecko.driver", "/Users/portal/Documents/Drivers/geckodriver");    
                    driver = new FirefoxDriver();
                    driver.manage().deleteAllCookies(); 
                    ; break;
            case CHROME: 
                System.setProperty("webdriver.chrome.driver", "/Users/portal/Documents/Drivers/chromedriver");
                driver = new ChromeDriver();
                if(extentReport == null) {
                    extentReport = new ExtentReports();
                    htmlReporter = new ExtentHtmlReporter("src/test/resources/htmlReporter.html");
                    extentReport.attachReporter(htmlReporter);
                }

                extentTest = extentReport.createTest (cenario.getId());


                break;
            case EDGE: 
                driver = new EdgeDriver(); break;
            case IE:
                driver = new InternetExplorerDriver();

            break;
        }
        driver.manage().window().setSize(new Dimension(1800, 900)); 

    }

}


public static WebDriver getDriver() {
    return driver;
}

@After
public void afterCenario(Scenario cenario) {
    extentTest.log(Status.PASS, "Cenario "+ cenario.getName()+ " executado com sucesso");
    extentReport.flush();

}

public static void killDriver(){
    if(driver != null) {
        extentReport.flush();
        driver.quit();
        driver = null;
    }
}


public static ExtentTest getExtentTest() {
    return extentTest;
}

}

Excerpt from the Steps class

Steps class public class Apply authenticated {

HomePage home = PageFactory.initElements(DriverFactory.getDriver(), HomePage.class);
NavBarPage nav= PageFactory.initElements(DriverFactory.getDriver(), NavBarPage.class);
LoginPage login =PageFactory.initElements(DriverFactory.getDriver(), LoginPage.class);
AssinePage assine = PageFactory.initElements(DriverFactory.getDriver(), AssinePage.class);
LoginGooglePage lGoogle = PageFactory.initElements(DriverFactory.getDriver(), LoginGooglePage.class);
LoginFacebookPage lFacebook = PageFactory.initElements(DriverFactory.getDriver(), LoginFacebookPage.class);


@Given("^que o usuario está na pagina inicial do Estadão$")
public void que_o_usuario_está_na_pagina_inicial_do_Estadão() throws Throwable {
    home.acessarHomePage();
    Thread.sleep(3000);

    home.fecharPropaganda();
    home.fecharPush();
}

@Given("^realiza login$")
public void realiza_login() throws Throwable {
    nav.cliqueEntrar();
    Thread.sleep(3000);
    login.setUsuario("[email protected]");
    login.setSenha("");
    login.entrar();

}

@Given("^realiza login via Google$")
public void realiza_login_via_Google() throws Throwable {
    nav.cliqueEntrar();
    login.clickBotaoEntrarGoogle();
    lGoogle.setEmail("@gmail.com");
    lGoogle.clickProximo();
    lGoogle.setSenha("");

The problem is that in the Steps class, I give a Pagefactory.initElements(Driverfactory.getDriver(), Homepage.class); and put in the call the Driverfactory class, but even putting a @Before in the beforeCenario method in the Driverfactoru class so that it runs before the getDriver method, it does not recognize and appears nullPointer. How can I fix this?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.