Skip to main content

Working with colors

You can verify that the color of an element (usually retrieved in RGBA) matches a given color in any supported format. Look into the following steps:

  1. Get the color of element using getElementCssValue which looks into computed style of element and retrieves the required color property in RGBA.

  2. The desired color to match can be in any supported format such as HEX, RGB, RGBA, HSL, HSLA. You can also use colors constant that have more than hundred predefined colors for faster matching. All available colors are auto suggested when you do colors. in IDE.

Examples#

button = findElement('Submit', by.text)buttonColor = getElementCssValue(button, 'background-color')assertTrue(colorMatches(buttonColor, colors.blueviolet))assertTrue(colorMatches(buttonColor, '#8a2be2'))assertTrue(colorMatches(buttonColor, 'hsl(271, 76%, 53%)'))assertTrue(colorMatches(buttonColor, 'hsl(271, 76%, 53%, 1)'))assertTrue(colorMatches(buttonColor, 'rgb(138, 43, 226)'))assertTrue(colorMatches(buttonColor, 'rgba(138, 43, 226, 1)'))