All files / webdriverio/src/commands/element getSize.js

100% Statements 7/7
100% Branches 5/5
100% Functions 1/1
100% Lines 7/7

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                                                              12x   12x 11x   1x     12x 2x     10x          
/**
 *
 * Get the width and height for an DOM-element.
 *
 * <example>
    :getSize.js
    it('should demonstrate the getSize command', () => {
        browser.url('http://github.com')
        const logo = $('.octicon-mark-github')
 
        const size = logo.getSize()
        console.log(size) // outputs: { width: 32, height: 32 }
 
        const width = logo.getSize('width')
        console.log(width) // outputs: 32
 
        const height = logo.getSize('height')
        console.log(height) // outputs: 32
    })
 * </example>
 *
 * @alias element.getElementSize
 * @param {String=} prop     size to receive [optional] ("width" or "height")
 * @return {Object|Number}    requested element size (`{ width: <Number>, height: <Number> }`) or actual width/height as number if prop param is given
 * @type property
 *
 */
 
import { getElementRect } from '../../utils'
 
export default async function getSize(prop = null) {
    let rect = {}
 
    if (this.isW3C) {
        rect = await getElementRect(this)
    } else {
        rect = await this.getElementSize(this.elementId)
    }
 
    if(rect[prop]) {
        return rect[prop]
    }
 
    return {
        width: rect.width,
        height: rect.height
    }
}