Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine Operating System/User Agent Protractor Test

I have a mouse/key sequence in a Protractor test that differs depending on OS (Mac vs. everything else). I'd like to change out which key is held down durring a mouse click depending on OS or User Agent.

Depending on where I test (local Mac OSx + Chrome or headless PhantomJS on Linux) the Command key or the Ctrl key is what is needed.

Current test looks like:

describe('my test', function() {

  //get elements with code not shown
   ptor.actions()
                        .sendKeys(protractor.Key.CONTROL)  //mac protrator.Key.COMMAND non mac protractor.Key.CONTROL
                        .mouseDown(trs[0])
                        .mouseUp(trs[0])
                        .sendKeys(protractor.Key.NULL)
                        .perform();
                    trs[0].evaluate('selectedItems.length')
                        .then(function(count) {
                            expect(count).toBe(0);
                        })

});
like image 868
binarygiant Avatar asked Mar 26 '26 20:03

binarygiant


1 Answers

First a heads-up, using webdriver's COMMAND key probably won't work in OSX.

Regarding a way to determine current browser OS, I use some helper functions.

Usage - Config file

onPrepare: require('./capabilities.js'),

Usage - Test files

if (browser.inOSX()) {
  // in Mac...
} else if (browser.inWindows()) {
  // in Windows...
} else {
  // likely in Linux...
}

Browser Capabilities Extensions

See capabilities.js in this gist

like image 187
Leo Gallucci Avatar answered Mar 28 '26 10:03

Leo Gallucci



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!