I am running selenium cucumber tests with spring configuration. I have created beans for all pages and autowired them in all steps classes. i created a cucumberspringconfig file as well When running as maven test run i get the below error
by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.deko.automation.pages.AvailableOffersPage]: Factory method 'availableOffersPage' threw exception with message: Input must be set
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
... 62 more
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/resources/features/"},
glue = {"cucumber.steps", "com.deko.automation"},
tags = "@test",
plugin = {"pretty", "html:target/report/cucumber-report", "json:target/report/cucumber.json"},
monochrome = true)
public class TestRunner extends AbstractTestNGCucumberTests {}
@ContextConfiguration(classes = {Config.class})
@ComponentScan({"com.deko.automation.cucumber.pages"})
@CucumberContextConfiguration()
@SpringBootTest
public class CucumberSpringConfiguration {
/** Dummy method to tell cucumber to initialise this class */
@Before
public void setUp() {}
}
@Configuration
public class Config {
@Bean
@Lazy
@Scope("cucumber-glue")
public AvailableOffersPage availableOffersPage() {
return new AvailableOffersPage();
}
public class OffersPageSteps {
@Autowired
AvailableOffersPage availableOffersPage;
@Autowired
CreditApplicationPage creditApplicationPage;
@Given("I select first offer and apply")
public void selectFirstOfferandApply() {
availableOffersPage.selectFirstOfferAndClickApply();
creditApplicationPage.clickOnCompletePurchaseButton();
}
}
@Scope(SCOPE_CUCUMBER_GLUE)
@Component
public class AvailableOffersPage extends BasePage {
@FindBy(xpath = "//button[@data-testid='apply-button']")
private WebElement applyButton;
@FindBy(xpath = "//div[text()='Representative Example']")
private WebElement representativeExampleText;
@FindBy(xpath = "//div[@data-testid='offer-container']")
private WebElement firstOffer;
@FindBy(xpath = "//div[@data-testid='trigger-close']")
private WebElement triggerCloseButton;
public void selectFirstOfferAndClickApply() {
switchToIframe(getDriver(), 0);
triggerCloseButton.click();
scrollIntoView(getDriver(), firstOffer);
waitForElementAndClick(30, firstOffer);
scrollToTheEndOfPage(getDriver());
applyButton.click();
waitTillElementIsInvisible(getDriver(), applyButton);
}
I tried to run the tests and got the above error 'Input must be set' I dont understand what input AvailableoffersPage is expecting when initialising Also it actually fails in basepage constructor