This repository was archived by the owner on Feb 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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} ) ;
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 1+ Dummy test
You can’t perform that action at this time.
0 commit comments