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

Commit 984054f

Browse files
author
Jevgenijus Marinuskinas
committed
Added a method uploadFile. Added tests. Added test data.
1 parent 2c06645 commit 984054f

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

example/tests/elementActions.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,36 @@ describe("Element Actions", () => {
304304
expect(coordinates.x).toEqual(expectedXCoordinate);
305305
expect(coordinates.y).toEqual(expectedYCoordinate);
306306
});
307+
308+
it("should upload a file when an absolute path is provided", async () => {
309+
//Arrange
310+
const filePath = process.cwd() + "\\testFiles\\Dummy.txt";
311+
const remotePath = "C:\\fakepath\\Dummy.txt";
312+
const uploadElement = new Element("#uploadFile");
313+
const resultElement = new Element("#uploadedFilePath");
314+
await page.goto("https://demoqa.com/upload-download");
315+
316+
//Act
317+
await uploadElement.uploadFile(filePath, true);
318+
319+
//Assert
320+
expect(await resultElement.text()).toEqual(remotePath);
321+
});
322+
323+
it("should upload a file when a relative path is provided", async () => {
324+
//Arrange
325+
const filePath = "\\testFiles\\Dummy.txt";
326+
const remotePath = "C:\\fakepath\\Dummy.txt";
327+
const uploadElement = new Element("#uploadFile");
328+
const resultElement = new Element("#uploadedFilePath");
329+
await page.goto("https://demoqa.com/upload-download");
330+
331+
//Act
332+
await uploadElement.uploadFile(filePath, false);
333+
334+
//Assert
335+
expect(await resultElement.text()).toEqual(remotePath);
336+
});
337+
338+
307339
});

framework/Element.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,11 @@ export default class Element {
195195
context.fill();
196196
});
197197
}
198+
199+
async uploadFile(filePath, isAbsolutePath) {
200+
if (!isAbsolutePath) filePath = process.cwd() + filePath;
201+
console.log(`Uploading a file with path ${filePath}`);
202+
const elementHandle = await this.wait();
203+
await elementHandle.setInputFiles(filePath);
204+
}
198205
}

testFiles/Dummy.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dummy test

0 commit comments

Comments
 (0)