webdriverio-boneyard / gulp-webdriver

gulp-webdriver is a gulp plugin to run selenium tests with the WebdriverIO testrunner
http://webdriver.io
MIT License
76 stars 33 forks source link

Haven't found the WebdriverIO test runner #20

Closed electricmonk closed 8 years ago

electricmonk commented 9 years ago

Using v1.0.1, when the top level project is dependent on both gulp-webdriver and webdriverio, the webdriverio module is installed in the top-level node_modules dir. Running gulp with piping to gulp-webdriver, gulp fails with the aforementioned message.

The problem is reproduced here: https://github.com/electricmonk/goos-nodejs/tree/e6c3a0453a211fb072f7777e04c7e9491e556ba5

The code that causes this failure is this (index.js):

if (!fs.existsSync(opts.wdioBin)) {
   return this.emit('error', new gutil.PluginError('gulp-webdriver', 'Haven\'t found the WebdriverIO test runner', {
    showStack: false
  }));
}

which is caused by this line:

wdioBin = path.join(__dirname, 'node_modules', '.bin', isWin ? 'wdio.cmd' : 'wdio');

I managed to work around it by overriding the wdioBin option in my Gulpfile thus:

gulp.task('e2e', ['test', 'selenium'], function () {
    return gulp.src('wdio.conf.js', {read: false})
        .pipe(webdriver({
            wdioBin:  path.join(__dirname, 'node_modules', '.bin', 'wdio'),
            desiredCapabilities: {
                browserName: 'phantomjs'
            }
        }))
        .once('end', function () {
            selenium.child.kill();
        });

});

But I think that gulp-webdriver should be able to handle this case on its own.

FBerthelot commented 9 years ago

I use the v1.0.1 too and i've the same issue. But i use only webdriverio in my project.

Thanks for the trick.

christian-bromann commented 9 years ago

@electricmonk @FBerthelot does it work with v1.0.0? On which platform are you running node?

christian-bromann commented 9 years ago

Seems that /^win/.test(process.platform) returns a wrong value / cc @mhoyer

electricmonk commented 9 years ago

@christian-bromann nope. I added opts.wdioBin to the error message locally (might be a good idea to add it permanently) and it looked for the binary relative to gulp-webdriver rather than relative to the project root. And it was not installed there, but rather in the project root.

edit: Regarding your previous comment, I'm running 0.12.7 on OS X 10.10.4. v1.0.0 also doesn't work.

FBerthelot commented 9 years ago

@christian-bromann : For me it work with v1.0.0

I run my test on a kubuntu 14.04.

silvenon commented 9 years ago

v1.0.1 works fine for me. (OS X 10.10.5)

jessebeach commented 9 years ago

I just ran into this as well. Specifying the path to wdioBin as @electricmonk suggested got me past this error and onto the next one!

silvenon commented 9 years ago

Ugh, I'm experiencing this issue as well now. Investigating…

silvenon commented 9 years ago

Ok, got it. The issue isn't caused by a specific change in webdriverio, it's caused by npm v3 flattening the dependency tree. So the binary is now located at node_modules/.bin/wdio, but gulp-webdriver is still searching at node_modules/gulp-webdriver/node_modules/.bin/wdio.

Anybody knows a reliable way to get the path to the executable?

kmturley commented 8 years ago

I had the same issue, using the following path didn't work either:

wdioBin: __dirname + '/node_modules/.bin/wdio'

because I was running my gulp tasks inside a child folder:

gulpfile.js
/gulp/tasks.js

This path worked for me, which is relative to the root directory:

wdioBin: './node_modules/.bin/wdio'
FennNaten commented 8 years ago

Hi, Looks like this issue is back on windows. When the dependency tree is flattened, there correctly is a wdio file in node_modules/webdriverio/bin/ as well as in node_modules/.bin/, however the wdio.cmd can only be found in node_modules/.bin/. So I get this error:

Cannot find module 'webdriverio\bin\wdio.cmd' at Function.Module._resolveFilename (module.js:327:15) at Function.require.resolve (internal/module.js:17:19)

I don't know if it comes from the way webdriver.io is published in latest version or from changes in npm, however I know that the problem only occurred when I upgraded node and npm (worked like a charm with node 4/npm 2). It can be fixed in my case by pasting manually a modified wdio.cmd in webdriverio\bin but it's not pretty ^^' However, I'm not sure it's possible to make a fix taking into account all combinations of os/npm versions

edit: I thought I could supply a different path through opts but it's not even the case in 1.0.2: it's the require.resolve which throws, and as it's called in every cases before merging the opts there's nothing I can do. So at the moment I had to revert back to 1.0.1 and then use: wdioOpts = {wdioBin: require('path').join('./node_modules', '.bin', isWin ? 'wdio.cmd' : 'wdio')}; in my gulpfile as gulp-webdriver options. (working because I forced npm3 as engine and put the .gulpfile at the project root)

kmturley commented 8 years ago

The results are also different based on the version of webdriverio used. I'm using 2.4.5 to support webdrivercss:

npm uninstall webdriverio --save-dev
npm install webdriverio@2.4.5 --save-dev

When using this version, I had to change gulp-webdriver index.js line to:

wdioBin = require.resolve(path.join('.bin', isWin ? 'wdio.cmd' : 'wdio'));

I would suggest gulp-webdriver should check for the version of webdriverio and modify it's approach!