簡體   English   中英

JavaScript - WebDriverIO - 如何選擇文件並使用相對文件路徑上傳?

[英]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 ),這將有助於獲取當前工作目錄的絕對路徑。

更多閱讀: process.cwd()與__dirname之間有什么區別?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM