首页 > 解决方案 > 使用 vaadin-upload 组件上传文件

问题描述

我正在尝试使用空手道 UI 上传文件。我面临的问题是我无法识别vaadin-upload组件中的元素。vaadin-button组件在我可以单击一个简单按钮的地方工作。但是我想不出使用这个vaadin-upload组件上传文件的方法。我尝试过使用 driver.inputFile() 以及空手道文档,但没有运气。到目前为止,我已经尝试了以下选项:

尝试 1:上传不起作用,但发现按钮单击有效。基本上,vaadin-upload 不起作用

   * 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')

输出:

Node is not a file input element

尝试2:

* def param = script("document.querySelector('#settingsplayground-upload').shadowRoot.querySelector('#fileInput').hidden=false")
* driver.inputFile(param , 'test_json.json')

输出:

Could not find node with given id error

尝试 3:尝试使用 POST 调用。不确定它是否具有一些 Vaadin 安全功能,因为它附加了我在 POST 调用中发送的目标,但仍然没有运气。

* 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

输出:

Resource is not found for path=VAADIN/dynamic/resource/0/f0cfab56-7100-4714-820a-2ff4acfb1013/upload

尝试 4:取消隐藏fileinput并使用 XPATH

   * script("document.querySelector('#settingsplayground-upload').shadowRoot.querySelector('#fileInput').hidden=false")
   * delay(500)
   * driver.inputFile("//*[@id='fileInput']", 'test_json.json')
   * delay(500) 

输出:

DOM Error while querying

尝试 5:最后一个选项我第一次使用空手道机器人尝试空手道机器人,但似乎我被一个简单的按钮单击以及文件的上传卡住了(仅供参考,我有最新的空手道-robot.jar 0.9.6 版本)

   * 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)

输出:(但是空手道机器人遇到了一个不同的问题,我无法进行简单的点击

com.intuit.karate.StringUtils.split(Ljava/lang/String;CZ)Ljava/util/List;

这里的 HTML 代码片段:

<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

有人可以调查一下并指出我在这里做错了什么吗?谢谢,桑迪

标签: user-interfacekaratevaadin-upload

解决方案


推荐阅读