-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScreenShot.java
109 lines (88 loc) · 3.12 KB
/
ScreenShot.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package Steps;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.testng.AssertJUnit.assertEquals;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.Scenario;
import com.jacob.com.Variant;
import com.smartbear.cucumber.TestComplete;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
public class TestEtymoALM {
@Given("^i Run StepD$")
public void TestEtymoALM_1() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("Step:i Run StepD");
}
@When("^i run StepD$")
public void TestEtymoALM_2() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("Step:i Run StepD");
}
@Then("^i should expect StepD$")
public void TestEtymoALM_3() throws Throwable {
// // Write code here that turns the phrase above into concrete actions
System.out.println("Step:i should expect StepD");
assertEquals(true, true);
}
@Given("^i Run StepE$")
public void TestEtymoALM_4() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("Step:i Run StepE");
}
@When("^i run StepE$")
public void TestEtymoALM_5() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("Step:i Run StepE");
}
@Then("^i should expect StepE$")
public void TestEtymoALM_6() throws Throwable {
// // Write code here that turns the phrase above into concrete actions
System.out.println("Step:i should expect StepE");
assertEquals(true, false);
}
@After
public void tearDown(Scenario scenario) throws IOException {
if (takeScreenshot() == true) {
final byte[] screenshot = getImageAsByteArray();
scenario.embed(screenshot, "image/png");
} else {
System.out.println("Error in capturing the screenshot");
}
}
public byte[] getImageAsByteArray() throws IOException {
System.out.println(System.getProperty("user.dir"));
ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
BufferedImage img = ImageIO.read(new File(System.getProperty("user.dir"), "screencap.png"));
ImageIO.write(img, "png", baos);
baos.flush();
String base64String = Base64.encode(baos.toByteArray());
baos.close();
byte[] bytearray = Base64.decode(base64String);
return bytearray;
}
public boolean takeScreenshot() {
boolean isSuccess = false;
try {
Process p = Runtime.getRuntime()
.exec("cmd /c adb shell screencap -p /sdcard/screencap.png && adb pull /sdcard/screencap.png");
isSuccess = true;
System.out.println(System.getProperty("user.dir"));
} catch (IOException e1) {
System.out.println("Exception Occured while capturing the screenshot");
e1.printStackTrace();
isSuccess = false;
}
System.out.println("ScreenshotCaptured");
return isSuccess;
}
}