Open Kilda Java Documentation
CommonSteps.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.atdd.staging.steps;
17 
18 import cucumber.api.Scenario;
19 import cucumber.api.java.After;
20 import cucumber.api.java.Before;
21 import cucumber.api.java.en.And;
22 import org.junit.Assume;
23 
24 import java.util.concurrent.TimeUnit;
25 
26 public class CommonSteps {
27 
28  // If one of the scenarios fails, with a high probability something is wrong with the test environment and
29  // there is no sense to run other scenarios because of a low percentage of their success. So this flag controls
30  // other scenario executions after the first scenario failure.
31  private static boolean skipScenario = false;
32 
33  @Before
34  public void beforeScenario() {
35  if (skipScenario) {
36  Assume.assumeTrue("The scenario is skipped due to a failure of one of the previous scenarios!", false);
37  }
38  }
39 
40  @After
41  public void afterScenario(Scenario scenario) {
42  if (scenario.isFailed()) {
43  skipScenario = true;
44  }
45  }
46 
47  @And("(?:remains? in this state|wait) for (\\d+) seconds")
48  public void delay(int seconds) throws InterruptedException {
49  TimeUnit.SECONDS.sleep(seconds);
50  }
51 }