Skip to content

Commit

Permalink
remove JQuery wait in screenshot method
Browse files Browse the repository at this point in the history
  • Loading branch information
vothaian committed May 21, 2024
1 parent 7afcb04 commit 2e89d8e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 41 deletions.
24 changes: 10 additions & 14 deletions src/test/java/com/anhtester/hooks/CucumberListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
public class CucumberListener implements EventListener {

//Khai báo các biến để thống kê tổng số test cases sau khi kết thúc test
public static int count_totalTCs;
public static int count_passedTCs;
public static int count_skippedTCs;
public static int count_failedTCs;
public static int count_totalTCs = 0;
public static int count_passedTCs = 0;
public static int count_skippedTCs = 0;
public static int count_failedTCs = 0;

@Override
public void setEventPublisher(EventPublisher publisher) {
Expand All @@ -48,15 +48,15 @@ private void runFinished(TestRunFinished event) {
// This event is triggered when feature file is read
// here we create the feature node
private void featureRead(TestSourceRead event) {
String featurePath = event.getUri().toString();
String featureName = featurePath.split(".*/")[1];
LogUtils.info("Feature Path: " + featurePath);
LogUtils.info("Feature Name: " + featureName);
// String featurePath = event.getUri().toString();
// String featureName = featurePath.split(".*/")[1];
// LogUtils.info("Feature Path: " + featurePath);
// LogUtils.info("Feature Name: " + featureName);
}

private void ScenarioStarted(TestCaseStarted event) {
LogUtils.info("Scenario Path: " + event.getTestCase().getUri().toString());
LogUtils.info("Scenario Name: " + event.getTestCase().getName());
// LogUtils.info("Scenario Path: " + event.getTestCase().getUri().toString());
// LogUtils.info("Scenario Name: " + event.getTestCase().getName());
count_totalTCs = count_totalTCs + 1;
}

Expand All @@ -72,10 +72,6 @@ private void ScenarioFinished(TestCaseFinished event) {
if (Status.SKIPPED.equals(result.getStatus())) {
count_skippedTCs = count_skippedTCs + 1;
}

//Quit driver in thread local
DriverManager.quit();
WebUI.stopSoftAssertAll();
}

// Step started event
Expand Down
39 changes: 31 additions & 8 deletions src/test/java/com/anhtester/hooks/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

public class Hooks {

public static int count_totalTCs = 0;
public static int count_passedTCs = 0;
public static int count_skippedTCs = 0;
public static int count_failedTCs = 0;

TestContext testContext;

public Hooks(TestContext context) {
Expand All @@ -29,7 +34,7 @@ public Hooks(TestContext context) {
@BeforeAll
public static void before_all() {
LogUtils.info("================ BEFORE ALL ================");
PropertiesHelpers.loadAllFiles(); //Load Config and Locators
PropertiesHelpers.loadAllFiles();
AllureManager.setAllureEnvironmentInformation();

try {
Expand All @@ -50,15 +55,21 @@ public static void before_all() {
public static void after_all() {
LogUtils.info("================ AFTER ALL ================");
ZipUtils.zipReportFolder();
EmailSendUtils.sendEmail(CucumberListener.count_totalTCs
, CucumberListener.count_passedTCs
, CucumberListener.count_failedTCs
, CucumberListener.count_skippedTCs);
EmailSendUtils.sendEmail(count_totalTCs
, count_passedTCs
, count_failedTCs
, count_skippedTCs);

LogUtils.info("count_totalTCs: " + count_totalTCs);
LogUtils.info("count_passedTCs: " + count_passedTCs);
LogUtils.info("count_failedTCs: " + count_failedTCs);
LogUtils.info("count_skippedTCs: " + count_skippedTCs);
}

@Before
public void beforeScenario(Scenario scenario) {
LogUtils.info("Scenario Name: " + scenario.getName());
count_totalTCs = count_totalTCs + 1;

if (VIDEO_RECORD.toLowerCase().trim().equals(YES)) {
CaptureHelpers.startRecord(scenario.getName());
Expand All @@ -67,31 +78,43 @@ public void beforeScenario(Scenario scenario) {

@After
public void afterScenario(Scenario scenario) {

if (Status.PASSED.equals(scenario.getStatus())) {
count_passedTCs = count_passedTCs + 1;
}
if (Status.FAILED.equals(scenario.getStatus())) {
count_failedTCs = count_failedTCs + 1;
}
if (Status.SKIPPED.equals(scenario.getStatus())) {
count_skippedTCs = count_skippedTCs + 1;
}

if (VIDEO_RECORD.toLowerCase().trim().equals(YES)) {
WebUI.sleep(1);
CaptureHelpers.stopRecord();
}

//Quit driver in thread local
DriverManager.quit();
WebUI.stopSoftAssertAll();
}

@AfterStep
public void afterStep(Scenario scenario) {
if (scenario.getStatus().equals(Status.PASSED) && SCREENSHOT_PASSED_STEPS.equals(YES)) {
WebUI.waitForPageLoaded();
WebUI.waitForJQueryLoad();

byte[] screenshot = ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, "image/png", "Screenshot passed step");
}
if (scenario.getStatus().equals(Status.FAILED) && SCREENSHOT_FAILED_STEPS.equals(YES)) {
WebUI.waitForPageLoaded();
WebUI.waitForJQueryLoad();

byte[] screenshot = ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, "image/png", "Screenshot failed step");
}
if (SCREENSHOT_ALL_STEPS.equals(YES)) {
WebUI.waitForPageLoaded();
WebUI.waitForJQueryLoad();

byte[] screenshot = ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, "image/png", "Screenshot step");
Expand Down
26 changes: 10 additions & 16 deletions src/test/java/com/anhtester/runners/TestRunnerAllFeatureByTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,28 @@
@Test
@CucumberOptions(
features = "src/test/resources/features",
glue = {"com.anhtester.projects.website.crm.stepdefinitions",
glue = {
"com.anhtester.projects.website.crm.stepdefinitions",
"com.anhtester.projects.website.cms.stepdefinitions",
"com.anhtester.projects.website.hrm.stepdefinitions",
"com.anhtester.hooks"},
plugin = {"com.anhtester.hooks.CucumberListener",
"com.anhtester.hooks"
},
plugin = {
"com.anhtester.hooks.CucumberListener",
"pretty",
"html:target/cucumber-reports/cucumber-reports.html",
"json:target/cucumber-reports/cucumber-reports.json",
"io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm",
"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"}
, monochrome = true,
"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"
},
monochrome = true,
tags = "@Regression or @Smoke"
)

public class TestRunnerAllFeatureByTag extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = false)
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}

@AfterSuite
public void afterSuite() {
System.out.println("================ AFTER SUITE ================");
ZipUtils.zipReportFolder();
EmailSendUtils.sendEmail(CucumberListener.count_totalTCs
, CucumberListener.count_passedTCs
, CucumberListener.count_failedTCs
, CucumberListener.count_skippedTCs);
}
}
2 changes: 1 addition & 1 deletion src/test/resources/features/Dashboard.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: HRM dashboard page
Background: User is logged to the HRM system
Given User logged in with email "admin_example" and password "123456"

@Regression
@Regression @device_Window_11 @author_AnhTester
Scenario Outline: Open menu
Given User navigate to dashboard
When User click "<menu>"
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/features/SigninCRM.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Sign in page CRM

@Regression
@Regression @device_Window_10 @author_AnVo
Scenario Outline: Sign in CRM with an email valid
Given User navigate to url "<url>"
When User login with username "<username>" and password "<password>" valid
Expand All @@ -9,7 +9,7 @@ Feature: Sign in page CRM
| url | username | password |
| https://rise.fairsketch.com/signin | admin@demo.com | riseDemo |

@Smoke
@Smoke @device_Window_10 @author_AnVo
Scenario Outline: Sign in CRM with an email invalid
Given User navigate to url "<url>"
When User login with username "<username>" and password "<password>" invalid
Expand Down

0 comments on commit 2e89d8e

Please sign in to comment.