3

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
Dominique
  • 1,080
  • 14
  • 29
sonlexqt
  • 6,011
  • 5
  • 42
  • 58

1 Answers1

2

I've found this node command: process.cwd() (http://nodejs.org/api/process.html#process_process_cwd) which will helps getting the absolute path of the current working directory.

More reading: What's the difference between process.cwd() vs __dirname?

Community
  • 1
  • 1
sonlexqt
  • 6,011
  • 5
  • 42
  • 58