How does one test the color of the link on hover using protractor?
I want to simulate the mouse hovering over a link, that link changes from say white to blue and then I want the test to expect that the color = blue, on hover.
code that I am currently using to test.
it('should redirect to the home page', function(){
element(by.css('ul.first_menu > li > a'));
expect('ul.first_menu. > li > a'.getCssValue("color")).toEqual("rgba(11, 51, 60, 1)");
browser.actions().mouseMove('ul.first_menu. > li > a').perform();
browser.wait(waitForCssValue('ul.first_menu. > li > a', "color", "rgba(42, 100, 150, 1)"), 1000);
browser.wait(waitForCssValue('ul.first_menu. > li > a', "text-decoration", "underline"), 1000);
waitForCssValue = function (elementFinder, cssProperty, cssValue) {
return function () {
return elementFinder.getCssValue(cssProperty).then(function(actualValue) {
return actualValue === cssValue;
});
};
};
});
I've done exactly what you are asking about.
The idea is to use getCssValue() and get color and text-decoration properties. Then, hover the link with mouseMove() and wait for CSS values to change:
var elm = element(by.css('ul.first_menu > li > a'));
function waitForCssValue (elementFinder, cssProperty, cssValue) {
return function () {
return elementFinder.getCssValue(cssProperty).then(function(actualValue) {
return actualValue === cssValue;
});
};
};
expect(elm.getCssValue("color")).toEqual("rgba(11, 51, 60, 1)");
expect(elm.getCssValue("text-decoration")).toEqual("none");
browser.actions().mouseMove(elm).perform();
browser.wait(waitForCssValue(elm, "color", "rgba(42, 100, 150, 1)"), 1000);
browser.wait(waitForCssValue(elm, "text-decoration", "underline"), 1000);
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