14

I'm creating users in some test. Since it is connected to the backend and create real users I need fixtures. I was thinking of using the browser name to create unique user. However, It has proven to be quite difficult to get to it...

Anyone can point me in the right direction?

3 Answers 3

40

Another case of rubber ducking :)

The answer was actually quite simple.

in my onPrepare function I added the following function and it works flawlessly.

browser.getCapabilities().then(function (cap) {
  browser.browserName = cap.caps_.browserName;
});

I can get access the name in my test using browser.browserName.

1
  • 12
    I have worked as a programmer for 27 years and never heard the term "rubber duck debugging". Thank you for that. Commented Dec 9, 2014 at 21:47
18

This has changed in version of protractor starting from 3.2 (selenium webdriver 2.52)

Now one should call:

browser.driver.getCapabilities().then(function(caps){
    browser.browserName = caps.get('browserName');
}
0
0

If you want to avoid the a browser, you may want to do this:

it('User should see a message that he has already been added to the campaing when entering the same email twice', function () {

    browser.getCapabilities().then(function (capabilities) {
        browserName = capabilities.caps_.browserName;
        platform = capabilities.caps_.platform;
    }).then(function () {
        console.log('Browser:', browserName, 'on platform', platform);
        if (browserName === 'internet explorer') {
            console.log('IE Was avoided for this test.');
        } else {
            basePage.email.sendKeys('[email protected]');
            console.log('Mande el mail');
            basePage.subscribe.click().then(function () {
                basePage.confirmMessage('Contact already added to target campaign');
            });
        }
    });

}); 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.