Cucumber failing to instantiate class, 'steps undefined'

0

I get these errors on the console every time I try to run my test using cucumber with selenium:

cucumber.runtime.CucumberException: Failed to instantiate class br.gov.pb.receita.atfbdd.steps.arrecadacao.ConsultarLancamentoARR001 - this class doesn't have an empty or a page enabled constructor"
    at cucumber.runtime.SerenityObjectFactory.newInstance(SerenityObjectFactory.java:66)
    at cucumber.runtime.SerenityObjectFactory.cacheNewInstance(SerenityObjectFactory.java:51)
    at cucumber.runtime.SerenityObjectFactory.getInstance(SerenityObjectFactory.java:41)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)
    at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)
    at cucumber.runner.TestStep.executeStep(TestStep.java:55)
    at cucumber.runner.TestStep.run(TestStep.java:42)
    at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:53)
    at cucumber.runner.TestCase.run(TestCase.java:47)
    at cucumber.runner.Runner.runPickle(Runner.java:44)
    at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
    at net.serenitybdd.cucumber.CucumberWithSerenity.runChild(CucumberWithSerenity.java:144)
    at net.serenitybdd.cucumber.CucumberWithSerenity.runChild(CucumberWithSerenity.java:45)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at net.serenitybdd.cucumber.CucumberWithSerenity$1.evaluate(CucumberWithSerenity.java:153)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at cucumber.runtime.SerenityObjectFactory.newInstance(SerenityObjectFactory.java:63)
    ... 36 more
Caused by: java.lang.NullPointerException
    at br.gov.pb.receita.atfbdd.steps.arrecadacao.ConsultarLancamentoARR001.<init>(ConsultarLancamentoARR001.java:34)
    ... 41 more

cucumber.runtime.junit.UndefinedThrowable: The step "Eu solicito a funcionalidade Consultar Lan�amento" is undefined

cucumber.runtime.junit.UndefinedThrowable: The step "Eu informar os dados para consulta" is undefined

cucumber.runtime.junit.UndefinedThrowable: The step "O sistema valida as informa��es e executa a consulta" is undefined

cucumber.runtime.junit.UndefinedThrowable: The step "O sistema exibe uma lista contendo os lan�amentos obtidos" is undefined

I have tried to run my steps class with and without ScenarioSteps and, as you can see, the class has an empty constructor.

However, even extending Scenario Steps into the class of steps, I still get the error "cucumber.runtime.junit.UndefinedThrowable: The step is undefined", as shown above.

Here is my class of steps:

@CucumberOptions(features = "classpath:features/arrecadacao/")
public class ConsultarLancamentoARR001 extends ScenarioSteps {

    Selenium selenium;

    public ConsultarLancamentoARR001() {

    }

    ConsultarLancamentoPage consultarLancamento = new ConsultarLancamentoPage(selenium.getDriver());
    LoginPage loginPage = new LoginPage(selenium.getDriver());

    @Step
    @Given("^Eu desejo acessar o sistema ATF$")
    public void euDesejoAcessarAtf() throws Exception {
        selenium.getDriver().navigate().to(ConfiguracaoATF.URL_ADDRESS_DES);
    }

    @Step
    @When("^Eu informo as credenciais de login$")
    public void euInformoCredenciaisLogin() throws Exception {
        loginPage.logarSistemaViaCredenciaisUsuario(DadosConfigARR.USUARIO_ADMIN_DES, DadosConfigARR.SENHA_ADMIN_DES);
    }

    @Step
    @Then("^Eu devo logar no sistema com sucesso$")
    public void euLogoComSucesso() throws Exception {
        assertEquals("Lotação:", selenium.getDriver().findElement(By.xpath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[3]/td[1]")));
    }

    @Step
    @Given("^Eu solicito a funcionalidade Consultar Lançamento$")
    public void euSolicitoConsultarLancamento() throws Exception {
        consultarLancamento.acessarFuncionalidadeARR_001();
    }

    @Step
    @When("^Eu informar os dados para consulta$")
    public void euInformoDadosConsulta() throws Throwable {
        consultarLancamento.informarNumeroLancamento(DadosConfigARR.NOSSO_NUMERO_REG1);
        consultarLancamento.descerBarraDeRolagemCompletamente();
        consultarLancamento.clicarBotaoConsultarLancamento();
        Thread.sleep(2000);

    }

    @Step
    @Then("^O sistema valida as informações e executa a consulta$")
    public void oSistemaValidaInformacoes() throws Throwable {
        consultarLancamento.naoSelecionarNenhumItem();
        Thread.sleep(2000);

        assertEquals("Selecione um item", consultarLancamento.capturarPopupAlerta());

        consultarLancamento.detalharLancamento();
        Thread.sleep(5000);
    }

    @Step
    @And("^O sistema exibe uma lista contendo os lançamentos obtidos$")
    public void oSistemaExibeLancamentos() throws Throwable {
        consultarLancamento.detalharLancamento();
        Thread.sleep(5000);
    }

}

Here's my runner:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
        features = "src/test/resources/features/arrecadacao/",
        glue = "classpath:br.gov.pb.receita.atfbdd.steps.arrecadacao")

public class CucumberRunnerARR {

    protected static WebDriver driver;

    @BeforeClass
    public static void beforeClass() throws Exception {
        driver = Selenium.getInstance().getDriver();
        driver.manage().window().maximize();
//      LoginPage loginPage = new LoginPage(driver);
//      loginPage.logarSistemaViaCredenciaisUsuario(DadosConfigARR.USUARIO_ADMIN_DES, DadosConfigARR.SENHA_ADMIN_DES);
    }

    @AfterClass
    public static void afterClass() throws Exception {
        driver.quit();
    }
}

Here's my .feature:

Feature: Consultar lançamento

  O usuário consulta um lançamento no sistema ATF

  Background: O usuário está logado
    Given Eu desejo acessar o sistema ATF
    When Eu informo as credenciais de login
    Then Eu devo logar no sistema com sucesso

  @CT015
  Scenario: Fluxo básico de eventos
    Given Eu solicito a funcionalidade Consultar Lançamento
    When Eu informar os dados para consulta
    Then O sistema valida as informações e executa a consulta
    And O sistema exibe uma lista contendo os lançamentos obtidos

And, if you help, here is the organization of my project:

What am I doing wrong?

    
asked by anonymous 17.09.2018 / 22:24

0 answers