wdio-screenshot icon indicating copy to clipboard operation
wdio-screenshot copied to clipboard

Multi-Browser Support

Open webmagit opened this issue 8 years ago • 2 comments

Currently wdio-screenshot does not work for browser.select(Browser) (WebDriverIO multiremote)

browser.select(browser).saveViewportScreenshot('great-shot.jpg')

For example, above call errors with: Invalid attempt to destructure non-iterable instance running TypeError: Invalid attempt to destructure non-iterable instance

webmagit avatar Nov 03 '16 22:11 webmagit

same here,

try to add two browser caps (chrome/ff) in wdio.conf.js by this example but its not working.

ERROR: undefined

:´(

EDIT:

i tried this and it works for me.

wdio.conf.js

...
capabilities: [{
        maxInstances: 5,
        browserName: 'chrome'
    }, {
        maxInstances: 5,
        browserName: 'firefox'
    }, {
        maxInstances: 5,
        browserName: 'safari'
    }],
...

myTest.js

...
var browserName = browser.desiredCapabilities.browserName;

describe('save a full document screenshot.', function() {
  it('should save a screenshot of complete document', function () {
    browser.saveDocumentScreenshot('./screenshot/'+browserName+'.png');
  });
});

Arthuron avatar Dec 19 '16 15:12 Arthuron

Okay spent some time trying to fork the repo to make it compatible to Mutliremote and while running the very first tests, noticed a simple solution worth sharing.

In your wdio.conf.js

capabilities: {
        browserC: {
            desiredCapabilities: {
                browserName: 'chrome'
            }
        },
        browserS: {
            desiredCapabilities: {
                browserName: 'safari'
            }
        }   
    }

add this to to config to associate wd-screenshot commands to each of the browser instances

 before: function () {
    require('wdio-screenshot').init(browser, {});
    require('wdio-screenshot').init(browserC, {});
    require('wdio-screenshot').init(browserS, {});
  }

That's it!

Now you can just call browserC.saveDocumentScreenshot() and it works.

blindedByCode avatar Feb 05 '17 23:02 blindedByCode