-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHooks.java
69 lines (59 loc) · 2.23 KB
/
Hooks.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.fs.app.automation.step.definition;
import com.fs.app.automation.DriverUtils.DriverUtils;
import com.fs.app.automation.ScreenshotUtils.EmailReporter;
import com.fs.app.automation.ScreenshotUtils.ExecutionRecord;
import com.fs.app.automation.ScreenshotUtils.ScreenshotHook;
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
public class Hooks {
private static final Logger LOG = LoggerFactory.getLogger(Hooks.class);
public static ExecutionRecord record;
long startTime;
public static void stepRecordHook(String step){
record.stepRecord(step);
}
@BeforeClass
public static void start(){
DriverUtils.getAppDriver();
}
@Before
public void setUp(Scenario scenario){
LOG.debug("Before scenario");
startTime = System.currentTimeMillis();
record = new ExecutionRecord("./target/screenshots/"+scenario.getName());
}
@After
public void tearDown(Scenario scenario){
LOG.debug("After scenario");
long estimatedTime = System.currentTimeMillis() - startTime;
if(scenario.isFailed()) {
ScreenshotHook.embedScreenshot(scenario);
stepRecordHook("FAILED_STEP");
}
record.closeScenarioRecord(scenario, getDurationBreakdown(estimatedTime));
record.setTestResults(scenario);
try {
EmailReporter.reportMail("target/screenshots/");
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
@AfterClass
public static void close() {
DriverUtils.closeDriver();
}
public static String getDurationBreakdown(long millis) {
if (millis < 0) {
throw new IllegalArgumentException("Duration must be greater than zero!");
}
long minutes = TimeUnit.MILLISECONDS.toMinutes(millis) % 60;
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis) % 60;
return String.format("%d Minutes %d Seconds",minutes, seconds);
}
}