Closed sobi-ki closed 4 months ago
Hello,
Have you tried using Spring ConditionalOnProperty
?
This should only create the web driver bean if the tag you pass at runtime is @fe
@Configuration
@ConditionalOnProperty(name = "cucumber.tags", havingValue = "@fe")
public class WebDriverConfiguration {
}
// or
@Bean
@ConditionalOnProperty(name = "cucumber.tags", havingValue = "@fe")
public WebDriver webDriver() {
}
Pass it at runtime / or define it as a default in your app config
gradle test -Dcucumber.tags="@fe"
Thank you for your response.
I do have a solution if running via gradle cmd, but the issue is when setting a tag of @fe, then I won't be able to fire the API test. The problem is that the tags are not seen when @Bean is called from CourgetteRunner class or when running test via Feature / Scenario level in Feature file.
Have you considered making your bean @Lazy
?
@Bean
@Lazy
public WebDriver webDriver() {
}
So only tests that require a webDriver bean will call it to launch a browser.
As your API tests doesn't need a webDriver bean, it simply won't be loaded / created and as a result, no browser will be launched.
You could also dynamically register the bean based on the Cucumber tags at runtime.
@Before
public void before(Scenario scenario) {
if (scenario.getSourceTagNames().contains("fe")) {
// register your webDriver bean here
}
}
Thank you for your feedback. Not tried @Lazy will give it a go.
Hey,
I hope you are doing well.
I have the following setup using Spring:
This calls the WebDriverConfiguration class
createWebDriver is the setup of drivers.
I have a small challenge, and I hope you can help me out.
The current project needs to support API tests.
I have now set the Feature files with the tags: @fe run front end test @api run API test
The current limitation is that I am not able to expose the tags in the WebDriverConfiguration class.
Is there any way I can expose the cucumber tags? So that I don't need to launch the browser for the API test.
This will need to get tags from CourgetteChromeRunner, at Feature level and when running via Gradle/Maven
Thank you