Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #60 from devbridge/return-screenshot-path
Browse files Browse the repository at this point in the history
Return screenshot path
  • Loading branch information
vaidasmaciulis authored Sep 8, 2020
2 parents 5a50d40 + c98d66e commit 72f1c2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 17 additions & 5 deletions example/tests/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@ describe("Helpers", () => {
console.log("Running test: " + jasmine["currentTest"].fullName);
});

it("should take screenshot and save to test logs directory", async () => {
it("should take screenshot, save to logs folder and return filepath", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/");
const filename = Date.now();
const filepath = `./logs/Helpers/should take screenshot and save to test logs directory/${filename}.png`;
const fileName = Date.now();
const expectedFilePath = `./logs/Helpers/should take screenshot, save to logs folder and return filepath/${fileName}.png`;

//Act
await helpers.takeScreenshot(filename);
const actualFilePath = await helpers.takeScreenshot(fileName);

//Assert
expect(fs.existsSync(filepath)).toBeTruthy();
expect(actualFilePath).toBe(expectedFilePath);
expect(fs.existsSync(actualFilePath)).toBeTruthy();
});

it("should use date now for screenshot file name when none is provided", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/");

//Act
const actualFilePath = await helpers.takeScreenshot();

//Assert
expect(actualFilePath).toContain(Date.now().toString().slice(0, -6));
});

it("should retry until action have succeeded", async () => {
Expand Down
4 changes: 3 additions & 1 deletion framework/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export default class Helpers {
targetDir = targetDir +`/${jasmine["currentTest"].description}`;
}
fs.mkdirSync(targetDir, { recursive: true });
await page.screenshot({ path: `${targetDir}/${filename || Date.now()}.png` });
const screenshotPath = `${targetDir}/${filename || Date.now()}.png`;
await page.screenshot({ path: screenshotPath });
return screenshotPath;
}

async retry(fn, retries = 5, minTimeout = 500) {
Expand Down

0 comments on commit 72f1c2e

Please sign in to comment.