Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 1x 1x | /**
*
* Get a css property from a DOM-element selected by given selector. The return value
* is formatted to be testable. Colors gets parsed via [rgb2hex](https://www.npmjs.org/package/rgb2hex)
* and all other properties get parsed via [css-value](https://www.npmjs.org/package/css-value).
*
* Note that shorthand CSS properties (e.g. background, font, border, margin, padding, list-style, outline,
* pause, cue) are not returned, in accordance with the DOM CSS2 specification - you should directly access
* the longhand properties (e.g. background-color) to access the desired values.
*
* <example>
:example.html
<label id="myLabel" for="input" style="color: #0088cc; font-family: helvetica, arial, freesans, clean, sans-serif, width: 100px">Some Label</label>
:getCSSProperty.js
it('should demonstrate the getCSSProperty command', () => {
const elem = $('#myLabel')
const color = elem.getCSSProperty('color')
console.log(color)
// outputs the following:
// {
// property: 'color',
// value: 'rgba(0, 136, 204, 1)',
// parsed: {
// hex: '#0088cc',
// alpha: 1,
// type: 'color',
// rgba: 'rgba(0, 136, 204, 1)'
// }
// }
const font = elem.getCSSProperty('font-family')
console.log(font)
// outputs the following:
// {
// property: 'font-family',
// value: 'helvetica',
// parsed: {
// value: [ 'helvetica', 'arial', 'freesans', 'clean', 'sans-serif' ],
// type: 'font',
// string: 'helvetica, arial, freesans, clean, sans-serif'
// }
// }
var width = elem.getCSSProperty('width')
console.log(width)
// outputs the following:
// {
// property: 'width',
// value: '100px',
// parsed: {
// type: 'number',
// string: '100px',
// unit: 'px',
// value: 100
// }
// }
})
* </example>
*
* @alias element.getCSSProperty
* @param {String} cssProperty css property name
* @return {Object} The specified css of the element
* @uses protocol/elements, protocol/elementIdCssProperty
* @type property
*
*/
import { parseCSS } from '../../utils'
export default async function getCSSProperty (cssProperty) {
const cssValue = await this.getElementCSSValue(this.elementId, cssProperty)
return parseCSS(cssValue, cssProperty)
}
|