gpt4 book ai didi

JavaScript - WebDriverIO - 如何选择具有相对文件路径的文件来上传?

转载 作者:行者123 更新时间:2023-11-29 14:50:25 32 4
gpt4 key购买 nike

我正在使用 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 ) 这将有助于获取当前工作目录的绝对路径。

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

关于JavaScript - WebDriverIO - 如何选择具有相对文件路径的文件来上传?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26695531/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com