diff --git a/example/tests/helpers.test.js b/example/tests/helpers.test.js index a53b2b5..6a5c3e9 100644 --- a/example/tests/helpers.test.js +++ b/example/tests/helpers.test.js @@ -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 () => { diff --git a/framework/helpers.js b/framework/helpers.js index 4bba38b..e7fb881 100644 --- a/framework/helpers.js +++ b/framework/helpers.js @@ -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) {