0

Could not invoke step [User clicks Register on main page] defined at 'pcz.StepDefs.LoginPageStepDefs.userClicksRegisterOnMainPage()'. It appears there was a problem with the step definition. The converted arguments types were ()

Caused by: io.cucumber.core.backend.CucumberBackendException: Error creating bean with name 'pcz.StepDefs.LoginPageStepDefs': Unsatisfied dependency expressed through field 'loginPage'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'pcz.Page.LoginPage' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory .annotation.Autowired(required=true)}

Project Structure:

enter image description here

public class LoginPageStepDefs {

@Autowired
LoginPage loginPage;


    @When("User clicks Register on main page")
    public void userClicksRegisterOnMainPage() {
        loginPage.test();

    }
}



import org.springframework.stereotype.Component;
@Component
public class LoginPage {
    public void test(){
    }
}

And Spring config:

@CucumberContextConfiguration
@ContextConfiguration(classes = SpringBootCucumberApplication.class, loader = AnnotationConfigContextLoader.class)
@SpringBootTest()
public class CucumberSpringConfiguration {
}


@SpringBootApplication()
public class SpringBootCucumberApplication {

    public static void main(String[] args) {


    }
}

1 Answers1

3

Neither your SpringBootCucumberApplication nor your CucumberSpringConfiguration scan your LoginPage component because it's in a totally different package. The default component scan only looks in the current and any descending packages, but pcz.Page isn't anywhere beneath the pcz.StepDefs or config packages.

You can try any of the following:

  • Rename the config package to pcz. That will make the default component scan of your SpringBootCucumberApplication notice your pcz.Page package.

  • Move your pcz.Page package to pcz.StepDefs.Page so that the default component scan of your CucumberSpringConfiguration will notice it.

  • Use a ComponentScan annotation on your CucumberSpringApplication, telling it which packages to scan: @ComponentScan(basePackages = {"Page"}).

Side note, your package names should probably be lower-cased.

hartenfels
  • 106
  • 2
  • I decided to rename package - works, I'll take a look on names, thanks! –  Jun 12 '22 at 18:04
  • No problem. You can mark the answer as accepted by clicking the checkmark on the left, that'll show that this question has been resolved. – hartenfels Jun 12 '22 at 19:14