Skip to content

fix: seeCssPropertiesOnElements verification condition #4057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ jobs:
run: "BROWSER=firefox node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"
- name: run webkit tests
run: "BROWSER=webkit node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug"
- name: run unit tests
- name: run chromium unit tests
run: ./node_modules/.bin/mocha test/helper/Playwright_test.js --timeout 5000
10 changes: 10 additions & 0 deletions lib/colorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,25 @@ function isColorProperty(prop) {
'color',
'background',
'backgroundColor',
'background-color',
'borderColor',
'border-color',
'borderBottomColor',
'border-bottom-color',
'borderLeftColor',
'border-left-color',
'borderRightColor',
'borderTopColor',
'caretColor',
'columnRuleColor',
'outlineColor',
'textDecorationColor',
'border-right-color',
'border-top-color',
'caret-color',
'column-rule-color',
'outline-color',
'text-decoration-color',
].indexOf(prop) > -1;
}

Expand Down
17 changes: 7 additions & 10 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -2119,29 +2119,26 @@ class Playwright extends Helper {

const cssPropertiesCamelCase = convertCssPropertiesToCamelCase(cssProperties);
const elemAmount = res.length;
const commands = [];
let props = [];

for (const element of res) {
const cssProperties = await element.evaluate((el) => getComputedStyle(el));

Object.keys(cssPropertiesCamelCase).forEach(prop => {
for (const prop of Object.keys(cssProperties)) {
const cssProp = await this.grabCssPropertyFrom(locator, prop);
if (isColorProperty(prop)) {
props.push(convertColorToRGBA(cssProperties[prop]));
props.push(convertColorToRGBA(cssProp));
} else {
props.push(cssProperties[prop]);
props.push(cssProp);
}
});
}
}

const values = Object.keys(cssPropertiesCamelCase).map(key => cssPropertiesCamelCase[key]);
if (!Array.isArray(props)) props = [props];
let chunked = chunkArray(props, values.length);
chunked = chunked.filter((val) => {
for (let i = 0; i < val.length; ++i) {
const _acutal = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(val[i], 10);
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
if (_acutal !== _expected) return false;
// eslint-disable-next-line eqeqeq
if (val[i] != values[i]) return false;
}
return true;
});
Expand Down
35 changes: 15 additions & 20 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1770,31 +1770,26 @@ class Puppeteer extends Helper {

const cssPropertiesCamelCase = convertCssPropertiesToCamelCase(cssProperties);
const elemAmount = res.length;
const commands = [];
res.forEach((el) => {
Object.keys(cssPropertiesCamelCase).forEach((prop) => {
commands.push(el.executionContext()
.evaluate((el) => {
const style = window.getComputedStyle ? getComputedStyle(el) : el.currentStyle;
return JSON.parse(JSON.stringify(style));
}, el)
.then((props) => {
if (isColorProperty(prop)) {
return convertColorToRGBA(props[prop]);
}
return props[prop];
}));
});
});
let props = await Promise.all(commands);
let props = [];

for (const element of res) {
for (const prop of Object.keys(cssProperties)) {
const cssProp = await this.grabCssPropertyFrom(locator, prop);
if (isColorProperty(prop)) {
props.push(convertColorToRGBA(cssProp));
} else {
props.push(cssProp);
}
}
}

const values = Object.keys(cssPropertiesCamelCase).map(key => cssPropertiesCamelCase[key]);
if (!Array.isArray(props)) props = [props];
let chunked = chunkArray(props, values.length);
chunked = chunked.filter((val) => {
for (let i = 0; i < val.length; ++i) {
const _acutal = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(val[i], 10);
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
if (_acutal !== _expected) return false;
// eslint-disable-next-line eqeqeq
if (val[i] != values[i]) return false;
}
return true;
});
Expand Down
16 changes: 16 additions & 0 deletions test/helper/Playwright_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Playwright', function () {
I = new Playwright({
url: siteUrl,
windowSize: '500x700',
browser: process.env.BROWSER || 'chromium',
show: false,
waitForTimeout: 5000,
waitForAction: 500,
Expand Down Expand Up @@ -112,6 +113,17 @@ describe('Playwright', function () {
});
});

describe('#seeCssPropertiesOnElements', () => {
it('should check background-color css property for given element', async () => {
try {
await I.amOnPage('https://codecept.io/helpers/Playwright/');
await I.seeCssPropertiesOnElements('.navbar', { 'background-color': 'rgb(128, 90, 213)' });
} catch (e) {
e.message.should.include('expected element (.navbar) to have CSS property { \'background-color\': \'rgb(128, 90, 213)\' }');
}
});
});

webApiTests.tests();

describe('#click', () => {
Expand Down Expand Up @@ -1051,6 +1063,7 @@ describe('Playwright', function () {

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

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

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

it('should not see recording WS messages', async () => {
if (process.env.BROWSER === 'firefox') this.skip();
await I.startRecordingWebSocketMessages();
await I.amOnPage('https://websocketstest.com/');
I.waitForText('Work for You!');
Expand Down
2 changes: 1 addition & 1 deletion test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ module.exports.tests = function () {
});

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

try {
await I.amOnPage('/');
Expand Down