The Problem:
In our rather big test codebase, we are using different keyboard shortcuts. For instance, to copy selected text we are using CTRL/COMMAND + C
, to paste CTRL/COMMAND + v
, to open a new tab CTRL/COMMAND + T
etc.
To keep tests work on multiple platforms, we'd like to make the CTRL
vs COMMAND
choice automatic depending on what platform the target browser is running on. To determine a target platform, we are currently using the following helper function which uses navigator.appVersion
:
this.getControlKey = function () {
return browser.executeScript("return navigator.appVersion.indexOf('Mac');").then(function (isMac) {
return isMac ? protractor.Key.COMMAND : protractor.Key.CONTROL;
});
};
The problem with this approach is that getControlKey()
returns a promise and, every time we use it, we have to resolve the promise explicitly:
helpers.getControlKey().then(function (controlKey) {
elm.sendKeys(protractor.Key.chord(controlKey, "c"));
});
The Question(s):
Is it possible to avoid the nestedness and simplify the use of getControlKey()
? Ideally I would like it work as simple as:
elm.sendKeys(protractor.Key.chord(helpers.getControlKey(), "c"));
Is using navigator.appVersion
the best approach to determine a target platform, and is there a better way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…