JavaScript - WebDriverIO - How to select a File with a relative file path to load?

I am writing tests for my current project using CucumberJS

. The test will be tested using Selenium Server + WebDriverIO

. Now I am delaying a test where I need to select an image file to upload to the server. I am using this WebDriverIO 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, since I want the test to run on every computer, I pre-loaded some test image files into the server folder root

. Since I don't know where this folder root

will be placed on other computers, I think there must be a way to send the relative path to the function file chooseFile

. I tried this path but it didn't work (this is the code in my file mentioned below 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 am using MeteorJS

):

public/ (root)
---imgForTesting/
------spiderman.png
packages/
---test-cucumber/
------features/
---------uploadImg.feature
---------step_definitions/
------------uploadImg.coffee

      

+3


source to share


1 answer


I found this node command: process.cwd()

( http://nodejs.org/api/process.html#process_process_cwd ) which will help get the absolute path of the current working directory.



Additional info: What is the difference between process.cwd () vs __dirname?

+2


source







All Articles