Skip to content

Commit 7c5dd8b

Browse files
authored
fix: seeCssPropertiesOnElements verification condition (#4057)
* fix: seeCssPropertiesOnElements verification condition * fix: UTs * fix: UTs * fix: UTs * fix: UTs
1 parent 8c63b54 commit 7c5dd8b

File tree

6 files changed

+50
-32
lines changed

6 files changed

+50
-32
lines changed

.github/workflows/playwright.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ jobs:
5050
run: "BROWSER=firefox node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"
5151
- name: run webkit tests
5252
run: "BROWSER=webkit node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"
53-
- name: run unit tests
53+
- name: run chromium unit tests
5454
run: ./node_modules/.bin/mocha test/helper/Playwright_test.js --timeout 5000

lib/colorUtils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,25 @@ function isColorProperty(prop) {
226226
'color',
227227
'background',
228228
'backgroundColor',
229+
'background-color',
229230
'borderColor',
231+
'border-color',
230232
'borderBottomColor',
233+
'border-bottom-color',
231234
'borderLeftColor',
235+
'border-left-color',
232236
'borderRightColor',
233237
'borderTopColor',
234238
'caretColor',
235239
'columnRuleColor',
236240
'outlineColor',
237241
'textDecorationColor',
242+
'border-right-color',
243+
'border-top-color',
244+
'caret-color',
245+
'column-rule-color',
246+
'outline-color',
247+
'text-decoration-color',
238248
].indexOf(prop) > -1;
239249
}
240250

lib/helper/Playwright.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,29 +2119,26 @@ class Playwright extends Helper {
21192119

21202120
const cssPropertiesCamelCase = convertCssPropertiesToCamelCase(cssProperties);
21212121
const elemAmount = res.length;
2122-
const commands = [];
21232122
let props = [];
21242123

21252124
for (const element of res) {
2126-
const cssProperties = await element.evaluate((el) => getComputedStyle(el));
2127-
2128-
Object.keys(cssPropertiesCamelCase).forEach(prop => {
2125+
for (const prop of Object.keys(cssProperties)) {
2126+
const cssProp = await this.grabCssPropertyFrom(locator, prop);
21292127
if (isColorProperty(prop)) {
2130-
props.push(convertColorToRGBA(cssProperties[prop]));
2128+
props.push(convertColorToRGBA(cssProp));
21312129
} else {
2132-
props.push(cssProperties[prop]);
2130+
props.push(cssProp);
21332131
}
2134-
});
2132+
}
21352133
}
21362134

21372135
const values = Object.keys(cssPropertiesCamelCase).map(key => cssPropertiesCamelCase[key]);
21382136
if (!Array.isArray(props)) props = [props];
21392137
let chunked = chunkArray(props, values.length);
21402138
chunked = chunked.filter((val) => {
21412139
for (let i = 0; i < val.length; ++i) {
2142-
const _acutal = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(val[i], 10);
2143-
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
2144-
if (_acutal !== _expected) return false;
2140+
// eslint-disable-next-line eqeqeq
2141+
if (val[i] != values[i]) return false;
21452142
}
21462143
return true;
21472144
});

lib/helper/Puppeteer.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,31 +1770,26 @@ class Puppeteer extends Helper {
17701770

17711771
const cssPropertiesCamelCase = convertCssPropertiesToCamelCase(cssProperties);
17721772
const elemAmount = res.length;
1773-
const commands = [];
1774-
res.forEach((el) => {
1775-
Object.keys(cssPropertiesCamelCase).forEach((prop) => {
1776-
commands.push(el.executionContext()
1777-
.evaluate((el) => {
1778-
const style = window.getComputedStyle ? getComputedStyle(el) : el.currentStyle;
1779-
return JSON.parse(JSON.stringify(style));
1780-
}, el)
1781-
.then((props) => {
1782-
if (isColorProperty(prop)) {
1783-
return convertColorToRGBA(props[prop]);
1784-
}
1785-
return props[prop];
1786-
}));
1787-
});
1788-
});
1789-
let props = await Promise.all(commands);
1773+
let props = [];
1774+
1775+
for (const element of res) {
1776+
for (const prop of Object.keys(cssProperties)) {
1777+
const cssProp = await this.grabCssPropertyFrom(locator, prop);
1778+
if (isColorProperty(prop)) {
1779+
props.push(convertColorToRGBA(cssProp));
1780+
} else {
1781+
props.push(cssProp);
1782+
}
1783+
}
1784+
}
1785+
17901786
const values = Object.keys(cssPropertiesCamelCase).map(key => cssPropertiesCamelCase[key]);
17911787
if (!Array.isArray(props)) props = [props];
17921788
let chunked = chunkArray(props, values.length);
17931789
chunked = chunked.filter((val) => {
17941790
for (let i = 0; i < val.length; ++i) {
1795-
const _acutal = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(val[i], 10);
1796-
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
1797-
if (_acutal !== _expected) return false;
1791+
// eslint-disable-next-line eqeqeq
1792+
if (val[i] != values[i]) return false;
17981793
}
17991794
return true;
18001795
});

test/helper/Playwright_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('Playwright', function () {
3333
I = new Playwright({
3434
url: siteUrl,
3535
windowSize: '500x700',
36+
browser: process.env.BROWSER || 'chromium',
3637
show: false,
3738
waitForTimeout: 5000,
3839
waitForAction: 500,
@@ -112,6 +113,17 @@ describe('Playwright', function () {
112113
});
113114
});
114115

116+
describe('#seeCssPropertiesOnElements', () => {
117+
it('should check background-color css property for given element', async () => {
118+
try {
119+
await I.amOnPage('https://codecept.io/helpers/Playwright/');
120+
await I.seeCssPropertiesOnElements('.navbar', { 'background-color': 'rgb(128, 90, 213)' });
121+
} catch (e) {
122+
e.message.should.include('expected element (.navbar) to have CSS property { \'background-color\': \'rgb(128, 90, 213)\' }');
123+
}
124+
});
125+
});
126+
115127
webApiTests.tests();
116128

117129
describe('#click', () => {
@@ -1051,6 +1063,7 @@ describe('Playwright', function () {
10511063

10521064
describe('#startRecordingWebSocketMessages, #grabWebSocketMessages, #stopRecordingWebSocketMessages', () => {
10531065
it('should throw error when calling grabWebSocketMessages before startRecordingWebSocketMessages', () => {
1066+
if (process.env.BROWSER === 'firefox') this.skip();
10541067
try {
10551068
I.amOnPage('https://websocketstest.com/');
10561069
I.waitForText('Work for You!');
@@ -1061,6 +1074,7 @@ describe('Playwright', function () {
10611074
});
10621075

10631076
it('should flush the WS messages', async () => {
1077+
if (process.env.BROWSER === 'firefox') this.skip();
10641078
await I.startRecordingWebSocketMessages();
10651079
I.amOnPage('https://websocketstest.com/');
10661080
I.waitForText('Work for You!');
@@ -1070,6 +1084,7 @@ describe('Playwright', function () {
10701084
});
10711085

10721086
it('should see recording WS messages', async () => {
1087+
if (process.env.BROWSER === 'firefox') this.skip();
10731088
await I.startRecordingWebSocketMessages();
10741089
await I.amOnPage('https://websocketstest.com/');
10751090
I.waitForText('Work for You!');
@@ -1078,6 +1093,7 @@ describe('Playwright', function () {
10781093
});
10791094

10801095
it('should not see recording WS messages', async () => {
1096+
if (process.env.BROWSER === 'firefox') this.skip();
10811097
await I.startRecordingWebSocketMessages();
10821098
await I.amOnPage('https://websocketstest.com/');
10831099
I.waitForText('Work for You!');

test/helper/webapi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ module.exports.tests = function () {
13991399
});
14001400

14011401
it('should check css property for several elements', async function () {
1402-
if (isHelper('TestCafe')) this.skip();
1402+
if (isHelper('TestCafe') || process.env.BROWSER === 'firefox') this.skip();
14031403

14041404
try {
14051405
await I.amOnPage('/');

0 commit comments

Comments
 (0)