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);
})
});
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.
onPrepare: require('./capabilities.js'),
if (browser.inOSX()) {
// in Mac...
} else if (browser.inWindows()) {
// in Windows...
} else {
// likely in Linux...
}
See capabilities.js in this gist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With