Skip to content

Commit 99b0f93

Browse files
Richard Petersenkobenguyent
authored andcommitted
fix: cannot grab for css attributes with hyphen (#2059)
1 parent 6f487e0 commit 99b0f93

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

lib/helper/Puppeteer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
ucfirst,
1414
fileExists,
1515
chunkArray,
16+
toCamelCase,
1617
convertCssPropertiesToCamelCase,
1718
screenshotOutputFolder,
1819
getNormalizedKeyAttributeValue,
@@ -1462,7 +1463,7 @@ class Puppeteer extends Helper {
14621463
async grabCssPropertyFrom(locator, cssProperty) {
14631464
const els = await this._locate(locator);
14641465
const res = await Promise.all(els.map(el => el.executionContext().evaluate(el => JSON.parse(JSON.stringify(getComputedStyle(el))), el)));
1465-
const cssValues = res.map(props => props[cssProperty]);
1466+
const cssValues = res.map(props => props[toCamelCase(cssProperty)]);
14661467

14671468
if (res.length > 0) {
14681469
return cssValues;

lib/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ function toCamelCase(name) {
210210
return letter.toUpperCase();
211211
});
212212
}
213+
module.exports.toCamelCase = toCamelCase;
213214

214215
function convertFontWeightToNumber(name) {
215216
const fontWeightPatterns = [

test/data/app/view/form/doubleclick.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
color: white;
1010
height: 100px;
1111
width: 150px;
12+
user-select: text;
1213
}
1314
div.dbl {
1415
background: yellow;

test/helper/webapi.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,15 @@ module.exports.tests = function () {
11431143
const css = await I.grabCssPropertyFrom('#block', 'height');
11441144
assert.equal(css, '100px');
11451145
});
1146+
1147+
it('should grab camelcased css properies', async () => {
1148+
if (isHelper('Nightmare')) return;
1149+
if (isHelper('TestCafe')) return;
1150+
1151+
await I.amOnPage('/form/doubleclick');
1152+
const css = await I.grabCssPropertyFrom('#block', 'user-select');
1153+
assert.equal(css, 'text');
1154+
});
11461155
});
11471156

11481157
describe('#seeAttributesOnElements', () => {

0 commit comments

Comments
 (0)