zinserjan / wdio-screenshot

A WebdriverIO plugin. Additional commands for taking screenshots with WebdriverIO.
MIT License
108 stars 43 forks source link

How do I use this in "Standalone Mode"? #63

Closed laughinghan closed 7 years ago

laughinghan commented 7 years ago

My script require()s WebdriverIO rather than using the testrunner, apparently called "Standalone Mode": http://webdriver.io/guide/getstarted/modes.html

The instructions in the README for wdio-screenshot mention wdio.config.js, but that appears to be only for the testrunner. Doing require('webdriverio').remote({desiredCapabilities: {...}, plugins: {'wdio-screenshot': {}}}) results in an object without the .saveDocumentScreenshot() method. Does this only work with the testrunner?

mroien commented 7 years ago

I'm looking for this too.

kisenka commented 7 years ago

@laughinghan @mroien

const webdriverio = require('webdriverio');
const webdriverioScreenshot = require('wdio-screenshot');

const client = webdriverio.remote(...);
webdriverioScreenshot.init(client);
client.init();
kisenka commented 7 years ago

@zinserjan should it be mentioned in readme? Is PR needed?

mroien commented 7 years ago

No, the part about webdriverioScreenshot.init(client); is in the README.

kisenka commented 7 years ago

@mroien where? Also there is a PR about updating the readme https://github.com/zinserjan/wdio-screenshot/pull/59

mroien commented 7 years ago

Oh I'm sorry you're right it's was on the wdio-element-screenshot readme

zinserjan commented 7 years ago

@kisenka @mroien At the moment this library is only supposed to work with webdriverio's testrunner.

There is no official support for standalone mode as there are no tests for standalone mode yet and the current solution or workaround for standalone just exists due to webdriverio's plugin API expect a method called init.

Ideally, the following examples should work without any further workarounds:

// single browser
const webdriverio = require('webdriverio');
const webdriverioScreenshot = require('wdio-screenshot');

const client = webdriverio.remote(...);
webdriverioScreenshot.init(client);
client.init();
// multi browser
const webdriverio = require('webdriverio');
const webdriverioScreenshot = require('wdio-screenshot');

const client = webdriverio.multiremote({
    myChromeBrowser: {
        desiredCapabilities: {
            browserName: 'chrome'
        }
    },
    myFirefoxBrowser: {
        desiredCapabilities: {
            browserName: 'firefox'
        }
    }
});

webdriverioScreenshot.init(client);
client.init();

But the latter doesn't as the init method seems to be wrong for multiremote. Also multiremote should work with testrunner out of the box without the ugly workaround suggested by @blindedByCode in https://github.com/zinserjan/wdio-screenshot/issues/42#issuecomment-277560304

I'm happy to accept a PR that add some tests for this and makes sure that also multiremote works in standalone or testrunner mode.

maggiesavovska commented 7 years ago

So, I'm not sure if this corresponds to the question asked, but I forked this project and did some very minor tweaking in order to use this with standalone mode: https://github.com/maggiesavovska/wdio-screenshot