Skip to content

Commit fbd2616

Browse files
committed
Update takeScreenshotScenario in Hooks
1 parent 2e89d8e commit fbd2616

File tree

7 files changed

+47
-51
lines changed

7 files changed

+47
-51
lines changed

src/main/java/com/anhtester/helpers/CaptureHelpers.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
package com.anhtester.helpers;
77

88
import com.anhtester.constants.FrameworkConstants;
9+
import com.anhtester.driver.DriverManager;
910
import com.anhtester.utils.LogUtils;
11+
import io.cucumber.java.Scenario;
1012
import org.apache.commons.io.FileUtils;
1113
import org.monte.media.Format;
1214
import org.monte.media.FormatKeys.MediaType;
@@ -40,13 +42,11 @@ public class CaptureHelpers extends ScreenRecorder {
4042
private static String name;
4143
private static SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
4244

43-
//Hàm xây dựng
4445
public CaptureHelpers(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder, String name) throws IOException, AWTException {
4546
super(cfg, captureArea, fileFormat, screenFormat, mouseFormat, audioFormat, movieFolder);
4647
this.name = name;
4748
}
48-
49-
//Hàm này bắt buộc để ghi đè custom lại hàm trong thư viên viết sẵn
49+
5050
@Override
5151
protected File createMovieFile(Format fileFormat) throws IOException {
5252

@@ -57,17 +57,15 @@ protected File createMovieFile(Format fileFormat) throws IOException {
5757
}
5858
return new File(movieFolder, name + "_" + dateFormat.format(new Date()) + "." + Registry.getInstance().getExtension(fileFormat));
5959
}
60-
61-
// Hàm Start record video
60+
6261
public static void startRecord(String methodName) {
63-
//Tạo thư mục để lưu file video vào
6462
File file = new File("./" + FrameworkConstants.EXPORT_VIDEO_PATH + File.separator + methodName + File.separator);
6563
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
6664
int width = screenSize.width;
6765
int height = screenSize.height;
6866

69-
System.out.println("width" + width);
70-
System.out.println("height" + height);
67+
LogUtils.info("width: " + width);
68+
LogUtils.info("height: " + height);
7169

7270
Rectangle captureSize = new Rectangle(0, 0, width, height);
7371

@@ -80,8 +78,7 @@ public static void startRecord(String methodName) {
8078
e.printStackTrace();
8179
}
8280
}
83-
84-
// Stop record video
81+
8582
public static void stopRecord() {
8683
try {
8784
screenRecorder.stop();
@@ -110,7 +107,7 @@ public static void captureScreenshot(WebDriver driver, String screenName) {
110107
LogUtils.info("Screenshot taken: " + screenName);
111108
LogUtils.info("Screenshot taken current URL: " + driver.getCurrentUrl());
112109
} catch (Exception e) {
113-
System.out.println("Exception while taking screenshot: " + e.getMessage());
110+
LogUtils.info("Exception while taking screenshot: " + e.getMessage());
114111
}
115112
}
116113

@@ -141,5 +138,15 @@ public static File getScreenshot(String screenshotName) {
141138
return file;
142139
}
143140

141+
public static void takeScreenshotScenario(Scenario scenario, String screenshotName) {
142+
try {
143+
TakesScreenshot ts = (TakesScreenshot) DriverManager.getDriver();
144+
byte[] src = ts.getScreenshotAs(OutputType.BYTES);
145+
scenario.attach(src, "image/png", screenshotName);
146+
} catch (Exception e) {
147+
LogUtils.error("Unable to take screenshot");
148+
LogUtils.error(e);
149+
}
150+
}
144151

145152
}

src/main/java/com/anhtester/keywords/WebUI.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,20 +1330,17 @@ public static List<String> getListElementsText(By by) {
13301330
* @return true/false
13311331
*/
13321332
@Step("Verify element exists {0}")
1333-
public static boolean checkElementExists(By by) {
1334-
smartWait();
1335-
1336-
boolean res;
1333+
public static Boolean checkElementExists(By by) {
1334+
boolean result;
13371335
List<WebElement> elementList = getWebElements(by);
13381336
if (elementList.size() > 0) {
1339-
res = true;
1337+
result = true;
13401338
LogUtils.info("Element existing");
13411339
} else {
1342-
res = false;
1340+
result = false;
13431341
LogUtils.error("Element not exists");
1344-
13451342
}
1346-
return res;
1343+
return result;
13471344
}
13481345

13491346

src/test/java/com/anhtester/hooks/CucumberListener.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.io.File;
1313
import java.io.IOException;
1414

15-
import static com.anhtester.constants.FrameworkConstants.DELETE_TEMP_FOLDER;
1615
import static com.anhtester.constants.FrameworkConstants.YES;
1716

1817
public class CucumberListener implements EventListener {

src/test/java/com/anhtester/hooks/Hooks.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ public static void before_all() {
4343
LogUtils.info("Deleted directory target/allure-results");
4444
FileUtils.deleteDirectory(new File("ExportData"));
4545
LogUtils.info("Deleted directory ExportData");
46-
FileUtils.deleteDirectory(new File("reports"));
47-
LogUtils.info("Deleted directory reports");
4846
}
4947
} catch (IOException e) {
48+
LogUtils.error(e.getMessage());
5049
e.printStackTrace();
5150
}
5251
}
@@ -103,21 +102,15 @@ public void afterScenario(Scenario scenario) {
103102
public void afterStep(Scenario scenario) {
104103
if (scenario.getStatus().equals(Status.PASSED) && SCREENSHOT_PASSED_STEPS.equals(YES)) {
105104
WebUI.waitForPageLoaded();
106-
107-
byte[] screenshot = ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
108-
scenario.attach(screenshot, "image/png", "Screenshot passed step");
105+
CaptureHelpers.takeScreenshotScenario(scenario,"Screenshot passed step");
109106
}
110107
if (scenario.getStatus().equals(Status.FAILED) && SCREENSHOT_FAILED_STEPS.equals(YES)) {
111108
WebUI.waitForPageLoaded();
112-
113-
byte[] screenshot = ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
114-
scenario.attach(screenshot, "image/png", "Screenshot failed step");
109+
CaptureHelpers.takeScreenshotScenario(scenario,"Screenshot failed step");
115110
}
116111
if (SCREENSHOT_ALL_STEPS.equals(YES)) {
117112
WebUI.waitForPageLoaded();
118-
119-
byte[] screenshot = ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
120-
scenario.attach(screenshot, "image/png", "Screenshot step");
113+
CaptureHelpers.takeScreenshotScenario(scenario,"Screenshot step");
121114
}
122115
}
123116

src/test/java/com/anhtester/projects/website/crm/pages/SignIn/SignInPageCRM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public class SignInPageCRM extends CommonPageCRM {
1717

1818
private String pageUrl = "/signin";
19-
private String pageTitle = "Sign in | RISE - Ultimate Project Manager and CRM";
19+
private String pageTitle = "Sign in | RISE CRM | Anh Tester Demo";
2020

2121
public By inputEmail = By.xpath("//input[@id='email']");
2222
public By inputPassword = By.xpath("//input[@id='password']");

src/test/resources/config/config.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ BROWSER = chrome
1515
TARGET = local
1616
# headless mode only for chrome or firefox and local execution
1717
HEADLESS = false
18-
URL_CRM = https://rise.fairsketch.com/signin
18+
URL_CRM = https://rise.anhtester.com/signin
1919
# grid url and port
2020
REMOTE_URL = localhost
2121
REMOTE_PORT = 4444
@@ -57,4 +57,4 @@ SCREENSHOT_FAILED_STEPS = yes
5757
# All Steps Screenshot
5858
SCREENSHOT_ALL_STEPS = no
5959

60-
DELETE_TEMP_FOLDER = yes
60+
DELETE_TEMP_FOLDER = no
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
Feature: Sign in page CRM
22

3-
@Regression @device_Window_10 @author_AnVo
4-
Scenario Outline: Sign in CRM with an email valid
5-
Given User navigate to url "<url>"
6-
When User login with username "<username>" and password "<password>" valid
7-
Then The user redirect to Dashboard page
8-
Examples:
9-
| url | username | password |
10-
| https://rise.fairsketch.com/signin | admin@demo.com | riseDemo |
3+
@Regression @device_Window_10 @author_AnVo
4+
Scenario Outline: Sign in CRM with an email valid
5+
Given User navigate to url "<url>"
6+
When User login with username "<username>" and password "<password>" valid
7+
Then The user redirect to Dashboard page
8+
Examples:
9+
| url | username | password |
10+
| https://rise.anhtester.com/signin | admin@example.com | 123456 |
1111

12-
@Smoke @device_Window_10 @author_AnVo
13-
Scenario Outline: Sign in CRM with an email invalid
14-
Given User navigate to url "<url>"
15-
When User login with username "<username>" and password "<password>" invalid
16-
Then The user can not redirect to Dashboard page
17-
And The error message is displays
18-
Examples:
19-
| url | username | password |
20-
| https://rise.fairsketch.com/signin | admin123@demo.com | riseDemo |
12+
@Smoke @device_Window_10 @author_AnVo
13+
Scenario Outline: Sign in CRM with an email invalid
14+
Given User navigate to url "<url>"
15+
When User login with username "<username>" and password "<password>" invalid
16+
Then The user can not redirect to Dashboard page
17+
And The error message is displays
18+
Examples:
19+
| url | username | password |
20+
| https://rise.anhtester.com/signin | demo@example.com | 123456 |

0 commit comments

Comments
 (0)