protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Different global variables depending on capabilities

Open FuturaITLtd opened this issue 12 years ago • 4 comments

Is there a way calling a different set of static variables depending on what capability is used. For example if I'm testing in Chrome and IE, could I use different login credentials to enable me to run tests concurrently that might not possible if restricted to using the same user (due to the way the the app in test handles sessions).

Thanks

FuturaITLtd avatar Jun 03 '14 20:06 FuturaITLtd

I do something similar, generating individual user names per browser so i can ran e2e in parallel:

// Sample returns: 'user1_ie10', 'user1_ch', 'user1_ff', 'user2_ie9', 'user3_ie11', ...
function getUserName(idx) {
    return 'user' + idx + '_' + browser.getShortNameVersion();
};

You will need to put bellow gist code within an onPrepare file or section: https://gist.github.com/elgalu/82929eeeef4a80e01835#file-onprepare-conf-js

elgalu avatar Jun 03 '14 20:06 elgalu

Thanks, just what I was looking for!

FuturaITLtd avatar Jun 03 '14 20:06 FuturaITLtd

@juliemr Would you be interested in merging some of that gist code into protractor core? I imagine many users might enjoy asking handy questions without going through getCapabilities() every time, i.e.

browser.getShortBrowserName(); //=> 'ch' / 'ff' / 'sa' / 'ie'
browser.isInternetExplorer(); //=> true / false
browser.isInternetExplorer(11); //=> true / false
browser.isInternetExplorer(9); //=> true / false
browser.isSafari(); //=> true / false
browser.inWindows(); //=> true / false
browser.inOSX(); //=> true / false
// .... and so on ...

elgalu avatar Jun 03 '14 21:06 elgalu

@elgalu i am trying to set the global variable from onPrepare() method using browser.variablename and try to get value in spec using browser.variablename but i am not getting. I have also tried global instead of browser but still it is not working.

Saurabh06 avatar Jun 09 '16 09:06 Saurabh06