【发布时间】:2014-12-29 00:06:56
【问题描述】:
我正在使用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
【问题讨论】:
标签: javascript selenium meteor webdriver-io