Skip to content

Commit

Permalink
Add screenshot to help debug (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valpich authored Oct 11, 2024
1 parent 6651631 commit 4d9f2c0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,57 @@ void FillCommerceApiSettings() throws InterruptedException {
try {
// Login
Thread.sleep(TWO_SECONDS);
takeScreenshot(sfccAdminLoginPage);
sfccAdminLoginPage.setUsername(SFCC_AUTOMATED_TESTS_USERNAME);
takeScreenshot(sfccAdminLoginPage);
sfccAdminLoginPage.clickSkipForNowButton();
Thread.sleep(TWO_SECONDS);
takeScreenshot(sfccAdminLoginPage);
sfccAdminLoginPage.setPassword(SFCC_AUTOMATED_TESTS_PASSWORD);
takeScreenshot(sfccAdminLoginPage);
sfccAdminLoginPage.clickSkipForNowButton();
Thread.sleep(TWO_SECONDS);
takeScreenshot(sfccAdminLoginPage);
sfccAdminVerifyPage.fillAuthenticatorForm(SFCC_AUTOMATED_TESTS_SECRET_KEY);
takeScreenshot(sfccAdminLoginPage);
sfccAdminVerifyPage.clickSkipForNowButton();

// Feature Switches
Thread.sleep(TEN_SECONDS);
takeScreenshot(sfccAdminLoginPage);
sfccNavigationPage.clickSkipForNowButton();
takeScreenshot(sfccAdminLoginPage);
sfccNavigationPage.clickAdministrationSubMenus();
takeScreenshot(sfccAdminLoginPage);
try {
sfccNavigationPage.clickViewFeatureSwitchPrefsSubMenus();
} catch (Exception e) {
sfccNavigationPage.clickSkipForNowButton();
takeScreenshot(sfccAdminLoginPage);
sfccNavigationPage.clickAdministrationSubMenus();
takeScreenshot(sfccAdminLoginPage);
sfccNavigationPage.clickViewFeatureSwitchPrefsSubMenus();
}
Thread.sleep(TWO_SECONDS);
takeScreenshot(sfccAdminLoginPage);
featureSwitchesPage.clickSkipForNowButton();
takeScreenshot(sfccAdminLoginPage);
Thread.sleep(TWO_SECONDS);
takeScreenshot(sfccAdminLoginPage);
featureSwitchesPage.enableScapiHookExecutionFlag();
Thread.sleep(TWO_SECONDS);
takeScreenshot(sfccAdminLoginPage);
featureSwitchesPage.clickSkipForNowButton();
takeScreenshot(sfccAdminLoginPage);
Thread.sleep(TWO_SECONDS);
takeScreenshot(sfccAdminLoginPage);
featureSwitchesPage.clickApplyButton();
return;
} catch (Exception e) {
logger.error("Error while filling Commerce API settings", e);
currentError++;
}
takeScreenshot(sfccAdminLoginPage);
} while (currentError < maxError);
}

Expand Down
11 changes: 11 additions & 0 deletions playwright_tools/src/test/java/com/mirakl/sfcc/PlaywrightBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import com.microsoft.playwright.*;
import org.junit.jupiter.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand All @@ -12,6 +16,7 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class PlaywrightBase {

private static final Logger logger = LoggerFactory.getLogger(PlaywrightBase.class);
protected static final long TWO_SECONDS = TimeUnit.SECONDS.toMillis(2);
protected static final long TEN_SECONDS = TimeUnit.SECONDS.toMillis(10);
protected static final List<String> BROWSER_DEFAULT_ARGS = List.of("--start-maximized", "--start-fullscreen", "--incognito", "--disable-save-password-bubble");
Expand Down Expand Up @@ -45,6 +50,12 @@ protected static void clickSkipForNowBtn(Page page) {
page.keyboard().press("Tab");
}

protected static void takeScreenshot(BasePage basePage){
byte[] buffer = basePage.getPage().screenshot();
logger.info("Screenshot taken from the page" , Arrays.stream(Thread.currentThread().getStackTrace()).map(StackTraceElement::toString).toArray());
logger.info(Base64.getEncoder().encodeToString(buffer));
}

@BeforeAll
static void launchBrowser() {
playwright = create();
Expand Down

0 comments on commit 4d9f2c0

Please sign in to comment.