Reputation: 65
I am trying to upload a file using Karate UI. The problem I face is that I cannot identify the element which is in the vaadin-upload component. vaadin-button component works where I can click a simple button. But I couldn't figure out a way to upload a file using this vaadin-upload component. I have tried using driver.inputFile() as well as per Karate documentation but no luck. So far I have tried the below options:
Try 1: Upload doesn't work but Discovered button click works. Basically, vaadin-upload not working
* click('{}Discovered').delay(2000)
* assert "Discovered info (fields and values that are read for the given json):" == script("document.querySelector('#overlay > flow-component-renderer > div > vaadin-vertical-layout > label').innerText")
* delay(2000)
* script("document.querySelector('#settingsplayground-upload').shadowRoot.querySelector('#fileInput').hidden=false")
* driver.inputFile('#settingsplayground-upload', 'test_json.json')
Output:
Node is not a file input element
Try 2:
* def param = script("document.querySelector('#settingsplayground-upload').shadowRoot.querySelector('#fileInput').hidden=false")
* driver.inputFile(param , 'test_json.json')
Output:
Could not find node with given id error
Try 3: Tried using a POST call. Not sure if it has some Vaadin security feature as it appends the target which I am sending in my POST call, but still no Luck.
* script("document.querySelector('#settingsplayground-upload').shadowRoot.querySelector('#fileInput').hidden=false")
* def targetpath = script("document.querySelector('#settingsplayground-upload').target")
* print targetpath
Given path '/', targetpath
* delay(1000)
And multipart fields { name: 'file', filename: 'test_json.json'}
* delay(500)
When method post
* delay(1000)
Then status 200
Output:
Resource is not found for path=VAADIN/dynamic/resource/0/f0cfab56-7100-4714-820a-2ff4acfb1013/upload
Try 4:
Unhide the fileinput
and using XPATH
* script("document.querySelector('#settingsplayground-upload').shadowRoot.querySelector('#fileInput').hidden=false")
* delay(500)
* driver.inputFile("//*[@id='fileInput']", 'test_json.json')
* delay(500)
Output:
DOM Error while querying
Try 5: Last option I went with Karate-robot Tried Karate-robot for the first time as well, but it seems like I am stuck with a simple button click as well as the upload of the file (FYI, I have the latest karate-robot.jar 0.9.6 version)
* robot { window: '^Chrome', highlight: true }
#* script("document.querySelector('#settingsplayground-upload').shadowRoot.querySelector('#fileInput').hidden=false")
* click('#settingsplayground-discovered')
* robot.waitFor('#button').click().delay(1000)
* click('Discovered')
* assert "Discovered info (fields and values that are read for the given json):" == script("document.querySelector('#overlay > flow-component-renderer > div > vaadin-vertical-layout > label').innerText")
* assert exists('Discovered info (fields and values that are read for the given json):'
* robot.input(Key.ENTER)
* delay(1000)
* robot.input('test_json.json')
* robot.input(Key.ENTER)
* delay(1000)
Output: (But with Karate-robot hitting in to a different issue where I cannot do a simple click
com.intuit.karate.StringUtils.split(Ljava/lang/String;CZ)Ljava/util/List;
HTML code snippet here:
<vaadin-upload class="upload-no-files-display" id="settingsplayground-upload" target="VAADIN/dynamic/resource/8/e58aa57a-5596-406f-b6d5-d1987ea1dca7/upload" nodrop=""><vaadin-button slot="add-button" tabindex="0" role="button">Upload Json</vaadin-button></vaadin-upload>
#shadow-root (open)
<input type="file" id="fileInput" hidden="" accept="application/json">
<vaadin-button slot="add-button" tabindex="0" role="button">Upload Json</vaadin-button>
</vaadin-upload
<vaadin-button id="settingsplayground-discovered" tabindex="0" role="button">Discovered</vaadin-button>
#shadow-root (open)
"Discovered"
</vaadin-button
Can someone please look into this & point me what I am doing wrong here? Thanks, Sandy
Upvotes: 1
Views: 41