admin管理员组文章数量:1125582
What happened? @autowire not initiating the class inside @steps class with Junit 5 - @IncludeEngines("cucumber")
What did you expect to happen? @autowire class should be accessible inside @steps classes
Serenity BDD version 4.0.28
JDK version 17
Execution environment OS: Windows Browser : Chrome
Framework : Spring boot - 3.4.0 Junit 5 Cucumber - 7.15.0
How to reproduce the bug. Runner class
@suite
@IncludeEngines("cucumber")
@SelectClasspathResource("/features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.automation.springboot.cucumber.steps")
public class TestRunner { }
Init class
@SpringBootTest(classes = CucumberTestApp.class)
public class Init extends PageObject {
@Autowired
RunConfig runConfig;
}
Run config
@DaTa
@component
@propertysource("classpath:config/newprop.properties")
public class RunConfig {
@Value("${app_url}")
private String strApp_URL;
}
Step Def
@component
public class DemoStepDef extends Init{
@Autowired
RunConfig runConfig;
@Steps
GooglePage googlePage;
@Given("Sample test")
public void demoStep(){
System.out.println("In the test case-----");
System.out.println("App URL : "+runConfig.getStrApp_URL());
googlePage.openApp();
}
@Then("search with {string}")
public void searchWith(String arg0) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
googlePage.search(arg0);
}
}
Google page
@component
public class GooglePage extends PageObject {
@Autowired
RunConfig runConfig;
@Step
public void openApp(){
getDriver().get(runConfig.getStrApp_URL());
}
@Step
public void search(String strKeyword){
find(By.name("q")).sendKeys(strKeyword);
}
}
POM.XML
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<serenity.version>4.0.28</serenity.version>
<junit.jupiter.version>5.10.1</junit.jupiter.version>
<junit.vintage.version>5.10.1</junit.vintage.version>
<junit-platform-suite.version>1.10.1</junit-platform-suite.version>
<cucumber-junit-platform-engine.version>7.15.0</cucumber-junit-platform-engine.version>
<mavenpiler.plugin.version>3.12.0</mavenpiler.plugin.version>
<mavenpiler.source>17</mavenpiler.source>
<mavenpiler.target>17</mavenpiler.target>
<maven.surefire.plugin.version>3.2.1</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>3.2.1</maven.failsafe.plugin.version>
</properties>
<dependencies>
<!--Spring boot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit 5 -->
<!-- JUNIT 5 Dependencies -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber-junit-platform-engine.version}</version>
<scope>test</scope>
</dependency>
<!-- Serenity -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-spring</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay-webdriver</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven.failsafe.plugin.version}</version>
<configuration>
<includes>
<include>**/*.java</include>
<include>**/TestRunner.java</include>
</includes>
<parallel>classes</parallel>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${mavenpiler.plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
<source>${mavenpiler.source}</source>
<target>${mavenpiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.version}</version>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-single-page-report</artifactId>
<version>${serenity.version}</version>
</dependency>
</dependencies>
<configuration>
<reports>single-page-html</reports>
</configuration>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
RunConfig works fine in Step definition class but returns null in GooglePage class. How to inject Spring boot context inside @steps classes?
本文标签: spring bootUnable to access Autowired classes inside Serenity Steps classStack Overflow
版权声明:本文标题:spring boot - Unable to access @Autowired classes inside Serenity @Steps class - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736657945a1946303.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论