I'm writing tests for my current project using CucumberJS
. The test will be tested using Selenium Server + WebDriverIO
. Now I'm stucking at the test where I have to choose an image file to upload to the server. I'm using this WebDriverIO's function:
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.
The thing is that, because I want the test to be runnable in every computer so I pre-uploaded some test image files to the server's root
folder. Because I don't know where this root
folder is going to be put in other computers, I think there must be a way to submit a relative file path to the chooseFile
function. I tried this way but it didn't work (this is the code in my mentioned below file 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
This is my project folder structure (I'm using MeteorJS
):
public/ (root)
---imgForTesting/
------spiderman.png
packages/
---test-cucumber/
------features/
---------uploadImg.feature
---------step_definitions/
------------uploadImg.coffee