Get the current browser name in Protractor test

后端 未结 3 1656
余生分开走
余生分开走 2020-12-03 14:58

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.

相关标签:
3条回答
  • 2020-12-03 15:06

    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.

    0 讨论(0)
  • 2020-12-03 15:06

    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('bruno@test.com');
                console.log('Mande el mail');
                basePage.subscribe.click().then(function () {
                    basePage.confirmMessage('Contact already added to target campaign');
                });
            }
        });
    
    }); 
    
    0 讨论(0)
  • 2020-12-03 15:22

    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)
提交回复
热议问题