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

Commit

Permalink
Addressed code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jevgenijus Marinuskinas committed Mar 3, 2021
1 parent ca265a5 commit c0959f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
17 changes: 9 additions & 8 deletions example/tests/elementActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("Element Actions", () => {
});

afterAll(async () => {
const tempFileDir = process.cwd() + "\\example\\testFiles\\temp";
const tempFileDir = process.cwd() + "/example/testFiles/temp";
await fsExtra.emptyDir(tempFileDir);
});

Expand Down Expand Up @@ -310,7 +310,7 @@ describe("Element Actions", () => {

it("should upload a file when an absolute path is provided", async () => {
//Arrange
const filePath = process.cwd() + "\\example\\testFiles\\Dummy.txt";
const filePath = process.cwd() + "/example/testFiles/Dummy.txt";
const remotePath = "C:\\fakepath\\Dummy.txt";
const uploadElement = new Element("#uploadFile");
const resultElement = new Element("#uploadedFilePath");
Expand All @@ -325,7 +325,7 @@ describe("Element Actions", () => {

it("should upload a file when a relative path is provided", async () => {
//Arrange
const filePath = "\\example\\testFiles\\Dummy.txt";
const filePath = "/example/testFiles/Dummy.txt";
const remotePath = "C:\\fakepath\\Dummy.txt";
const uploadElement = new Element("#uploadFile");
const resultElement = new Element("#uploadedFilePath");
Expand All @@ -338,7 +338,7 @@ describe("Element Actions", () => {
expect(await resultElement.text()).toEqual(remotePath);
});

//Skipping the Webkit for download tests until the issue is resolved https://github.com/microsoft/playwright/issues/5396
//TODO: un-skip when the local web server is implemented for the test pages
it.jestPlaywrightSkip({ browsers: ["webkit"] }, "should download a file when an absolute path is provided", async () => {
//Arrange
const filePath = localPath + "/example/examplePages/files/example.zip";
Expand All @@ -347,12 +347,13 @@ describe("Element Actions", () => {
await page.goto(`file:///${localPath}/example/examplePages/download.html`);

//Act
await downloadElement.downloadFile(resultFilePath, true);
await downloadElement.downloadFile(resultFilePath);

//Assert
expect(await fs.readFile(filePath)).toEqual(await fs.readFile(resultFilePath));
});


//TODO: un-skip when the local web server is implemented for the test pages
it.jestPlaywrightSkip({ browsers: ["webkit"] }, "should download a file when an relative path is provided", async () => {
//Arrange
const filePath = localPath + "/example/examplePages/files/example.zip";
Expand All @@ -361,9 +362,9 @@ describe("Element Actions", () => {
await page.goto(`file:///${localPath}/example/examplePages/download.html`);

//Act
await downloadElement.downloadFile(resultFilePath, false);
await downloadElement.downloadFile(resultFilePath);

//Assert
expect(await fs.readFile(filePath)).toEqual(await fs.readFile(process.cwd() + resultFilePath));
expect(await fs.readFile(filePath)).toEqual(await fs.readFile(localPath + resultFilePath));
});
});
5 changes: 3 additions & 2 deletions framework/Element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Helpers from "./helpers";

const path = require('path');
const config = require(process.cwd() + "/framework.config");
const defaultTimeout = config.defaultTimeout;
const shortTimeout = config.shortTimeout;
Expand Down Expand Up @@ -212,8 +213,8 @@ export default class Element {
await elementHandle.setInputFiles(filePath);
}

async downloadFile(filePath, isAbsolutePath) {
if (!isAbsolutePath) filePath = process.cwd() + filePath;
async downloadFile(filePath) {
if (!path.isAbsolute(filePath)) filePath = process.cwd().replace(/\\/g, "/") + filePath;
const [download] = await Promise.all([
page.waitForEvent("download"),
this.click(),
Expand Down
3 changes: 1 addition & 2 deletions jest-playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module.exports = {

// Describe which browsers we want to run

browsers: ["chromium", "webkit", "firefox"],
browsers: ["chromium", "firefox", "webkit",],
exitOnPageError: false,
launchOptions: {

// If we want to run browsers in headless mode or not,

headless: true,
Expand Down

0 comments on commit c0959f5

Please sign in to comment.