问题
I'm using cucumber-jvm
, and trying to implement global @After
method which should be executed only once after all scenario's execution was completed.
The @After
method should quit the appium driver.
Currently @After
hook being executed after each running scenario , and it means that the driver should be created each time from scratch , but I do want to reuse it.
Any help will be much appreciated
回答1:
You can try using QAF which support Gherkin, where driver management is taken care by the framework. It is dedicated framework built upon TestNG for web, mobile web, mobile native, and webservices functional test automation.
When using QAF you don't need to write any code to setup/teardown driver. You can configure as per your need through testng xml configuration file and properties. You can specify behavior by using property selenium.singletone
. For example:
#will reuse driver session for close browser after all testcase configured under xml test node
selenium.singletone=true
#will teardown after each scenario/testcase
selenium.singletone=Method
#will reuse driver session for group
selenium.singletone=Groups
If you are running in parrallel it will you can have driver session sharing between test running in same thread. All combinations you can achieve through execution configuration.
Moreover, you can use all TestNG listener and annotations. For example:
@BeforeMethod
:Invokes Before each Testcase/Scenario@BeforeSuite
: Invokes once before entire suite@BeforeTest
: Invokes once before each xml test node for each xml test node in configuration@BeforeGroup
: Invokes once before starting execution of test in group for each group@AfterSuite
: Invokes once after entire suite@AfterTest
: Invokes once after entire xml test node@AfterGroup
:Invokes once after all test in group for each group@AfterMethod
:Invokes after each Testcase/Scenario
Refer Gherkin with QAF
来源:https://stackoverflow.com/questions/53991190/cucumber-jvm-after-with-appium-driver