【问题标题】:JavaScript - WebDriverIO - How to chooseFile with relative file path to upload?JavaScript - WebDriverIO - 如何选择具有相对文件路径的文件来上传?
【发布时间】: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


    【解决方案1】:

    我找到了这个节点命令:process.cwd() (http://nodejs.org/api/process.html#process_process_cwd),这将有助于获取当前工作目录的绝对路径。

    更多阅读:What's the difference between process.cwd() vs __dirname?

    【讨论】:

      猜你喜欢
      • 2018-01-18
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多