serenity cucumber browser unique session per feature

我与影子孤独终老i 提交于 2019-12-12 04:05:58

问题


I'm looking at serenity (the following versions)

<serenity.version>1.1.26</serenity.version>
 <serenity.maven.version>1.1.26</serenity.maven.version>
 <serenity.cucumber.version>1.1.5</serenity.cucumber.version>

I have feature files F1, F2, F3.

I'm looking for support to run all the scenarios in F1 (only) to run in a single browser session.

The scenarios in F2 and F3 can run in a "browser per scenario" mode.

How to achieve this?


回答1:


Cucumber hooks do the job for you.

import cucumber.annotation.After;
import cucumber.annotation.Before;

public static WebDriver DRIVER;

@Before
public void setUp() {
  // start browser if it does not exist yet
}

@After
public void tearDown() {
  // clean cookies
}

Note that I use the cucumber before, not the JUnit before.Do make sure you have a reference to the DRIVER in your tests. The hooks wil run before and after each scenario (or example if you use scenario outline). If you want a specific setup for certain annotated features, for example:

@slowtest
Feature: F1 feature

Then you can use:

import cucumber.annotation.After;
import cucumber.annotation.Before;

public static WebDriver DRIVER;

@Before("@slowtest")
public void setUp() {
  // start browser if it does not exist yet
}

@After("@slowtest")
public void tearDown() {
  // close browser or clean cookies, or....
}

Conclusion you can use cucumber hooks in combination with annotations in features for custom setup and teardown.



来源:https://stackoverflow.com/questions/35547776/serenity-cucumber-browser-unique-session-per-feature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!