Is it possible to run incognito with a regular instance of the Chrome browser using Protractor?

I need to run a test in two browsers with the same view but with different users. Since the server changes the cookie and issues the first user due to the shared cookie between multiple windows in Chrome, I cannot run the test. So, I wonder if it is possible to run a regular instance of Chrome and incognito at the same time.

Another option is to launch an instance of Chrome and Firefox, but I need to control what to do with each browser.

+3


source to share


1 answer


You can use two browsers. Run the script to find out which browser you are in and then force different users to register based on that. First, get the browser, here is the script for that:

browser.getCapabilities()
.then(function(s) {

var platform = s.caps_.platform,
    browserName = s.caps_.browserName,
    browserVersion = s.caps_.version,
    shortVersion = browserVersion.split('.')[0],
    ie = /i.*explore/.test(browserName),
    ff = /firefox/.test(browserName),
    ch = /chrome/.test(browserName),
    sa = /safari/.test(browserName),
    shortName;

if (ie) {
    shortName = 'ie';
} else if (ff) {
    shortName = 'ff';
} else if (ch) {
    shortName = 'ch';
} else if (sa) {
    shortName = 'sa';
} else {
    throw new Exception('Unsupported browser: '+ browserName);
}

// Returns one of these: ['ch', 'ff', 'sa', 'ie']
browser.getShortBrowserName = function() {
    return shortName;
};

// Returns one of these: ['ch33', 'ff27', 'sa7', 'ie11', 'ie10', 'ie9']
browser.getShortNameVersionAll = function() {
    return shortName + shortVersion;
};

// Returns one of these: ['ch', 'ff', 'sa', 'ie11', 'ie10', 'ie9']
browser.getShortNameVersion = function() {
    if (ie) {
        return shortName + shortVersion;
    } else {
        return shortName;
    }
};

// Return if current browser is IE, optionally specifying if it is a particular IE version
browser.isIE = function(ver) {
    if (!ver) {
        return ie;
    } else {
        return ie && ver.toString() === shortVersion;
    }
};

browser.isSafari = function() {
    return sa;
};

browser.isFirefox = function() {
    return ff;
};

// Return if current browser is Chrome, optionally specifying if it is a particular Chrome version
browser.isChrome = function(ver) {
    if (!ver) {
        return ch;
    } else {
        return ch && ver.toString() === shortVersion;
    }
};

      

then you need a function to find out which user should be logged in:

global.getUserAndPassword = function getUser() {

var rv_user = process.env.PROTRACTOR_USER;

if (browser.isFireFox() && typeof process.env.PROTRACTOR_USER_2 !== 'undefined') {
  rv_user = process.env.PROTRACTOR_USER_2;
}

return [rv_user, process.env.PROTRACTOR_PASSWORD];

      



};

and then the login function:

global.loginFn = function loginFn() {
 var user_and_pass = getUserAndPassword();

 username.sendKeys(user_and_pass[0]);
 password.sendKeys(user_and_pass[1]);
 login.click();
};

      

+2


source







All Articles