-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenshotHook.java
71 lines (59 loc) · 2.71 KB
/
ScreenshotHook.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
70
71
/*
package com.fs.app.automation.ScreenshotUtils;
import com.assertthat.selenium_shutterbug.core.Shutterbug;
import com.assertthat.selenium_shutterbug.utils.web.ScrollStrategy;
import com.telstra.automation.core.Params;
import com.telstra.automation.core.WebDriverHelper;
import cucumber.api.Scenario;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriverException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
import java.awt.image.BufferedImage;
import java.util.Map;
public class ScreenshotHook{
private static final Logger LOG = LoggerFactory.getLogger(ScreenshotHook.class);
public static void embedScreenshot(Scenario scenario) {
try {
Map<String, Object> screenShots = ScreenshotHelper.getScreenShotsForCurrentTest();
for (Map.Entry<String, Object> screenShot : screenShots.entrySet()) {
scenario.write(screenShot.getKey());
scenario.embed((byte[]) screenShot.getValue(), "image/png");
}
ScreenshotHelper.tidyUpAfterTestRun();
scenario.write(WebDriverHelper.getWebDriver().getCurrentUrl());
byte[] screenShot;
if(Params.BROWSER.equals("firefox")){
screenShot = ((TakesScreenshot) WebDriverHelper.getWebDriver()).getScreenshotAs(OutputType.BYTES);
}else{
Screenshot shoot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(WebDriverHelper.getWebDriver());
BufferedImage image = shoot.getImage();
screenShot = ScreenshotHelper.imageToByteArray(image);
}
scenario.embed(screenShot, "image/png");
} catch (WebDriverException | ClassCastException wde) {
LOG.error(wde.getMessage());
} finally {
WebDriverHelper.getWebDriver().switchTo().defaultContent();
}
}
public static void stepScreenshot(String path, String step) {
try {
Shutterbug.shootPage(WebDriverHelper.getWebDriver(), ScrollStrategy.BOTH_DIRECTIONS)
.withName(step)
.save(path);
} catch (WebDriverException | ClassCastException wde) {
//wde.printStackTrace();
LOG.error(wde.getMessage());
}catch (Exception e){
LOG.error("Failed to capture screenshot: "+e.getMessage());
} finally {
WebDriverHelper.getWebDriver().switchTo().defaultContent();
}
}
}
*/