我正在使用CucumberJS
爲我當前的項目編寫測試。測試將使用Selenium Server + WebDriverIO
進行測試。現在我正在測試中選擇要上傳到服務器的圖像文件。我使用這個WebDriverIO的功能:JavaScript - 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