Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple onPrepare or dynamic login params when using multiCapabilites

basically the same as this: https://stackoverflow.com/questions/25163674/can-you-do-multiple-onprepares-per-browser-instance but since there were no answers or comments I'll post again.

I want to login with two user profiles on two separate browsers.

I'd be using something like this in my config file:

multiCapabilities: [{
    browserName: 'chrome',
    specs: ['profile_1.spec.js'],
    login: {email: 'profile_1',
    password: 'pw1'}
}, {
    browserName: 'chrome',
    specs: ['profile_2.spec.js'],
    login: { email: 'profile_2',
    password: 'pw2'}
}]

Since my login page isn't angular I need to use onPrepare and I can only set login params once.

Is there a way pass the login params from the multiCapabilities array to the onPrepare function or to have specific onPrepares inside the multiCapabilities objects?

like image 541
Dave Briand Avatar asked May 27 '26 07:05

Dave Briand


1 Answers

You can work around this by adding logic in your code.

At protractor 1.7, you can call browser.getProcessedConfig(), which returns your config.

You can add arbitrary fields into your browserName.

multiCapabilities: [{
    browserName: 'chrome',
    specs: ['profile_1.spec.js'],
    name: 'profile1'
}, {
    browserName: 'chrome',
    specs: ['profile_2.spec.js'],
    name: 'profile2'
}]

and use params:

params: {
    profile1: {
        email: 'CA',
        password: 'pw123'
    },
    profile2: {
        email: 'Sup',
        password: 'pw123'
    }
},

Then in on prepare:

onPrepare: function() {
    browser.getProcessedConfig().then(function(config) {
      //do something with browser.params[config.capabilities.name]
    });
},
like image 83
hankduan Avatar answered May 31 '26 09:05

hankduan