Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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