1

I have to write test for a electron GUI which contains a choose file dialog. I have no access to the implementation of the GUI.

I have wrote

await app.client.chooseFile('//*[@id="import-file"]/form/div/div/div[1]/input', path.join(__dirname, '..','..','..', 'Fahrtzeit.xlsx'))
.catch(function (error) {
  console.log(error);
}).getValue('//*[@id="import-file"]/form/div/div/div[1]/input').then(function (val) {

  console.log("value is :"+val);
  });

I get a console output

value is :

The value is empty

I am new to spectron. Am I missing something?

UPDATE: The DOM of the choose file element is

<div _ngcontent-c9="" class="mat-form-field-flex"><div _ngcontent-c9="" class="mat-form-field-infix"><input _ngcontent-c9="" class="mat-input-element unit-input ng-untouched ng-pristine ng-valid" formcontrolname="fileDisplay" readonly="" type="text" ng-reflect-name="fileDisplay" title="Auftragsdatei auswählen"></div><button _ngcontent-c9="" class="btn btn-link filepicker-btn unit-filepicker"><ui-icon _ngcontent-c9="" class="filepicker-icon" iconname="a_ic_attach_file" _nghost-c5="" ng-reflect-icon-name="a_ic_attach_file" id="import-file-icon"><div _ngcontent-c5="" class="a_ic_attach_file" ng-reflect-ng-class="a_ic_attach_file"></div></ui-icon></button><div _ngcontent-c9="" class="mat-form-field-underline"></div></div>
FarFarAway
  • 1,017
  • 3
  • 14
  • 35

1 Answers1

0
it('Should upload a file',async ()=>{

    let toUpload = path.join(__dirname, '..', '..', 'fixtures', 'Fahrtzeit.xlsx')

    await app.client.chooseFile('//*[@id="import-file"]/form/div/div/div[1]/input', toUpload);

    let val =await app.client.getValue('//*[@id="import-file"]/form/div/div/div[1]/input');

// Do asserts and test the **val** 
})        

reference : http://v4.webdriver.io/api/utility/chooseFile.html

just console val and test if this works.

Bharath Kumar S
  • 1,410
  • 2
  • 10
  • 29