![](/img/trans.png)
[英]Selenium Webdriver : How to upload file using his relative path (javascript)
[英]JavaScript - WebDriverIO - How to chooseFile with relative file path to upload?
我正在使用CucumberJS
為我當前的項目編寫測試。 測試將使用Selenium Server + WebDriverIO
進行測試。 現在我一直在測試,我必須選擇一個圖像文件上傳到服務器。 我正在使用這個WebDriverIO的功能:
chooseFile(String selector, String localFilePath, Function callback)
Given a selector corresponding to an <input type=file>, will upload the local file to the browser machine and fill the form accordingly. It does not submit the form for you.
問題是,因為我希望測試在每台計算機上都可以運行,所以我將一些測試圖像文件預先上傳到服務器的root
文件夾。 因為我不知道這個root
文件夾將放在其他計算機的哪個位置,所以我認為必須有一種方法可以向chooseFile
函數提交相對文件路徑。 我試過這種方式,但它不起作用(這是我在下面提到的文件uploadImg.coffee
的代碼)
@Given /^user attemp to upload his first avatar$/, (callback) ->
@browser
.click ".change-avatar"
.chooseFile "input[name=avatarFile]", "/imgForTesting/spiderman.png"
.click "#saveAvatarButton"
.call callback
return
這是我的項目文件夾結構(我正在使用MeteorJS
):
public/ (root)
---imgForTesting/
------spiderman.png
packages/
---test-cucumber/
------features/
---------uploadImg.feature
---------step_definitions/
------------uploadImg.coffee
我找到了這個節點命令: process.cwd()
( http://nodejs.org/api/process.html#process_process_cwd ),這將有助於獲取當前工作目錄的絕對路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.