Reputation: 89
I'm figuring what is in Karate testing the best practice to reuse some features containing selenium steps in other features. In other words I'd like to use some scenarios containing the web browsing part and recall them in other features.
This is important from my point of view for:
I've tried defining a feature "A" that:
The feature "B" opens the url in a browser and does something, for example clicks on a button and waits for a div:
Given driver my_url
When waitForEnabled(<button selector>).click()
Then match waitFor(<div selector>).text == 'Signing complete'
The problem with this solution is that running the feature A, it calls the feature B and it works all fine but it doesn't close the webdriver at the end of the feature. Probably using a hook, closing the webdriver after the scenario in feature B, can be a solution but I'm not sure that is the best practice to do it.
I tried launching the feature in my IDE (IntelliJ Idea), not with maven.
So have you tried other solutions for this? Have you hints/tips to suggest?
Upvotes: 1
Views: 752
Reputation: 58098
I think explicitly closing the browser within the test flow is fine.
Or you can use an afterScenario
hook from the top-level calling feature: https://github.com/intuit/karate#hooks
You can also choose to call Java code: https://stackoverflow.com/a/47233301/143475
Do note that Karate has a replacement for Webdriver now, and Karate will auto-close the browser: https://github.com/intuit/karate/tree/master/karate-core
Upvotes: 1