Я получаю эти ошибки каждый раз, когда пытаюсь запустить свой тест, используя огурец с селеном:
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
Я пытался запустить свой класс шагов с и без ScenarioSteps, и, как вы можете видеть, у него есть пустой конструктор.
Но, даже расширяя ScenarioSteps в моем классе шагов, я продолжаю получать эти ошибки "cucumber.runtime.junit.UndefinedThrowable: шаг не определен", как показано выше.
Вот мой класс урока:
@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);
}
}
Вот мой бегун:
@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();
}
}
Вот мой .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
И, если это поможет, вот как организован проект:
Project Explorer
Что я делаю не так?