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 #93 from devbridge/92-support_file_upload
Browse files Browse the repository at this point in the history
92 support file upload
  • Loading branch information
jevgenijusmarinuskinas authored Feb 4, 2021
2 parents 2c06645 + 879d83d commit 6ac7a95
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
32 changes: 32 additions & 0 deletions example/tests/elementActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,36 @@ describe("Element Actions", () => {
expect(coordinates.x).toEqual(expectedXCoordinate);
expect(coordinates.y).toEqual(expectedYCoordinate);
});

it("should upload a file when an absolute path is provided", async () => {
//Arrange
const filePath = process.cwd() + "\\testFiles\\Dummy.txt";
const remotePath = "C:\\fakepath\\Dummy.txt";
const uploadElement = new Element("#uploadFile");
const resultElement = new Element("#uploadedFilePath");
await page.goto("https://demoqa.com/upload-download");

//Act
await uploadElement.uploadFile(filePath, true);

//Assert
expect(await resultElement.text()).toEqual(remotePath);
});

it("should upload a file when a relative path is provided", async () => {
//Arrange
const filePath = "\\testFiles\\Dummy.txt";
const remotePath = "C:\\fakepath\\Dummy.txt";
const uploadElement = new Element("#uploadFile");
const resultElement = new Element("#uploadedFilePath");
await page.goto("https://demoqa.com/upload-download");

//Act
await uploadElement.uploadFile(filePath, false);

//Assert
expect(await resultElement.text()).toEqual(remotePath);
});


});
7 changes: 7 additions & 0 deletions framework/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,11 @@ export default class Element {
context.fill();
});
}

async uploadFile(filePath, isAbsolutePath) {
if (!isAbsolutePath) filePath = process.cwd() + filePath;
console.log(`Uploading a file with path ${filePath}`);
const elementHandle = await this.wait();
await elementHandle.setInputFiles(filePath);
}
}
1 change: 1 addition & 0 deletions testFiles/Dummy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy test

0 comments on commit 6ac7a95

Please sign in to comment.