0

I use an input file to load data from a xml file.

HTML Code:

<button (click)="xmlFile.click()" id="btnLoadXmlFile">
      Load data from file
</button>
<input type="file" (change)="handleFileInput($event)" accept="text/xml" class="load-xml-file" id="inputLoadXML" #xmlFile>
<span>{{ chosenFile }}</span>

E2E Code:

it( "Should load data from XML file", () => {
    const path = require('path');
    const fileToUpload = '../../src/assets/xml/myXmlFile.xml', 
    absolutePath = path.resolve(__dirname, fileToUpload);
    componentPo.getDomElements().btnLoadXML.click();
    componentPo.getDomElements().inputLoadXML.sendKeys(absolutePath);
});

It works fine except not being able to close the finder window (Mac User) after selecting the file and loading the data. This also causes that the E2E fails.

Any hint or idea how to fix this and force the Finder window to be closed after selecting the file?

k.vincent
  • 3,743
  • 8
  • 37
  • 74
  • 1
    use `sendKeys` directly. No need to click. remove `componentPo.getDomElements().btnLoadXML.click();` . It will work – jithinkmatthew Jul 15 '19 at 13:43
  • Yes, true. Thanks. Would you please add your comment as answer, so that all users could profit from it and I can accept it. – k.vincent Jul 15 '19 at 13:55

1 Answers1

1

No need to click on that File Upload button to upload a file. sendKeys will do that for you. Please remove componentPo.getDomElements().btnLoadXML.click(); from your existing code.

 it( "Should load data from XML file", () => {
    const path = require('path');
    const fileToUpload = '../../src/assets/xml/myXmlFile.xml', 
    absolutePath = path.resolve(__dirname, fileToUpload);
    componentPo.getDomElements().inputLoadXML.sendKeys(absolutePath);
   });
jithinkmatthew
  • 890
  • 8
  • 17