I have automation tests that will need to be ran in chrome desktop edition and chrome mobile edition. One of my tests require the desktop edition to click on an element that only appears when hovering, however, the mobile edition does not require hover the elements are always visible. I am having troubles finding a way to tell the test running on ipad to ignore the hover step and just click the button. I could create a method just for ipad and separate spec file but I don't want to waste my time if there is an easy fix.
Asked
Active
Viewed 49 times
1 Answers
1
however, the mobile edition does not require hover the elements are always visible.
We may use that. Basically, if the element is visible, click on it, if not - hover and then click:
elm.isDisplayed().then(function (isDisplayed) {
if (!isDisplayed) {
// hover what you need to hover
}
elm.click();
});
There is also that getCapabilities()
function that gives you access to the current capability object. You may have a helper function that would determine whether a hover is needed depending on the current browser the tests are executed in. Let's first write our isMobile
sample function and define it on the browser
object:
browser.isMobile = function(ver) {
var platformName, version;
return browser.getCapabilities().then(function(s) {
platformName = s.caps_.platformName;
version = s.caps_.version;
return /Android|iOS/.test(platformName);
});
};
Sample helper function:
function hoverClick(elm) {
return browser.isMobile().then(function (isMobile) {
if (!isMobile) {
browser.actions().mouseMove(elm).perform();
}
return elm.click();
});
}
See also: Protractor: accessing capabilities.
You may also extend the browser.actions()
and add a custom hoverClick action, see:
-
would this still work if I had multiple browsers to run at once having multi capabilities defined in the my conf using Chrome, IE11, and edoge browsers for desktop and one android? Or would android need to be the only defined browser/platform? – Nicole Phillips Nov 15 '15 at 22:44
-
@NicolePhillips good question! I think it should work even with multi capabilities used (have not tested though). – alecxe Nov 15 '15 at 22:46
-
I'll give it a shot in the morning and let you know how it goes, as always thankyou! – Nicole Phillips Nov 15 '15 at 22:49