codeceptjs
Advanced tools
Changelog
3.6.0
🛩️ Features
heal.addRecipe('reloadPageIfModalIsNotVisisble', {
steps: [
'click',
],
fn: async ({ error, step }) => {
// this function will be executed only if test failed with
// "model is not visible" message
if (error.message.include('modal is not visible')) return;
// we return a function that will refresh a page
// and tries to perform last step again
return async ({ I }) => {
I.reloadPage();
I.wait(1);
await step.run();
};
// if a function succeeds, test continues without an error
},
});
Breaking Change AI features refactored. Read updated AI guide:
openai
--ai
option added to explicitly enable AI featuresOpenAI
helper renamed to AI
feat(puppeteer): network traffic manipulation. See #4263 by @KobeNguyenT
startRecordingTraffic
grabRecordedNetworkTraffics
flushNetworkTraffics
stopRecordingTraffic
seeTraffic
dontSeeTraffic
feat(Puppeteer): recording WS messages. See #4264 by @KobeNguyenT
Recording WS messages:
I.startRecordingWebSocketMessages();
I.amOnPage('https://websocketstest.com/');
I.waitForText('Work for You!');
const wsMessages = I.grabWebSocketMessages();
expect(wsMessages.length).to.greaterThan(0);
flushing WS messages:
I.startRecordingWebSocketMessages();
I.amOnPage('https://websocketstest.com/');
I.waitForText('Work for You!');
I.flushWebSocketMessages();
const wsMessages = I.grabWebSocketMessages();
expect(wsMessages.length).to.equal(0);
Examples:
// recording traffics and verify the traffic
I.startRecordingTraffic();
I.amOnPage('https://codecept.io/');
I.seeTraffic({ name: 'traffics', url: 'https://codecept.io/img/companies/BC_LogoScreen_C.jpg' });
// check the traffic with advanced params
I.amOnPage('https://openai.com/blog/chatgpt');
I.startRecordingTraffic();
I.seeTraffic({
name: 'sentry event',
url: 'https://images.openai.com/blob/cf717bdb-0c8c-428a-b82b-3c3add87a600',
parameters: {
width: '1919',
height: '1138',
},
});
_react
, _vue
, data-testid
attribute. See #4255 by @KobeNguyenTScenario('using playwright locator @Playwright', () => {
I.amOnPage('https://codecept.io/test-react-calculator/');
I.click('7');
I.click({ pw: '_react=t[name = "="]' });
I.seeElement({ pw: '_react=t[value = "7"]' });
I.click({ pw: '_react=t[name = "+"]' });
I.click({ pw: '_react=t[name = "3"]' });
I.click({ pw: '_react=t[name = "="]' });
I.seeElement({ pw: '_react=t[value = "10"]' });
});
Scenario('using playwright data-testid attribute @Playwright', () => {
I.amOnPage('/');
const webElements = await I.grabWebElements({ pw: '[data-testid="welcome"]' });
assert.equal(webElements[0]._selector, '[data-testid="welcome"] >> nth=0');
assert.equal(webElements.length, 1);
});
Network requests & responses can be mocked and modified. Use mockRoute
which strictly follows Puppeteer's setRequestInterception API.
I.mockRoute('https://reqres.in/api/comments/1', request => {
request.respond({
status: 200,
headers: { 'Access-Control-Allow-Origin': '*' },
contentType: 'application/json',
body: '{"name": "this was mocked" }',
});
})
I.mockRoute('**/*.{png,jpg,jpeg}', route => route.abort());
// To disable mocking for a route call `stopMockingRoute`
// for previously mocked URL
I.stopMockingRoute('**/*.{png,jpg,jpeg}');
To master request intercepting use HTTPRequest object passed into mock request handler.
🐛 Bug Fixes
Changelog
3.5.15
❤️ Thanks all to those who contributed to make this release! ❤️
🛩️ Features
Once all the tests are completed, codecept
will create and store coverage in output/coverage
folder, as shown below.
Open index.html
in your browser to view the full interactive coverage report.
🐛 Bug Fixes
dry-run command now supports test level grep.
Tests from /Users/t/Desktop/projects/codeceptjs-rest-demo:@jaja
GET tests -- /Users/t/Desktop/projects/codeceptjs-rest-demo/src/GET_test.ts -- 4 tests
☐ Verify getting a single user @jaja
☐ Verify getting list of users @jaja
PUT tests -- /Users/t/Desktop/projects/codeceptjs-rest-demo/src/PUT_test.ts -- 4 tests
☐ Verify creating new user @Jaja
Total: 2 suites | 3 tests
--- DRY MODE: No tests were executed ---
➜ codeceptjs-rest-demo git:(master) ✗ npx codeceptjs dry-run
Tests from /Users/t/Desktop/projects/codeceptjs-rest-demo:
DELETE tests -- /Users/t/Desktop/projects/codeceptjs-rest-demo/src/DELETE_test.ts -- 4 tests
☐ Verify deleting a user
GET tests -- /Users/t/Desktop/projects/codeceptjs-rest-demo/src/GET_test.ts -- 4 tests
☐ Verify a successful call
☐ Verify a not found call
☐ Verify getting a single user @jaja
☐ Verify getting list of users @jaja
POST tests -- /Users/tDesktop/projects/codeceptjs-rest-demo/src/POST_test.ts -- 4 tests
☐ Verify creating new user
☐ Verify uploading a file
PUT tests -- /Users/tDesktop/projects/codeceptjs-rest-demo/src/PUT_test.ts -- 4 tests
☐ Verify creating new user @Jaja
Total: 4 suites | 8 tests
--- DRY MODE: No tests were executed ---
Changelog
3.5.14
❤️ Thanks all to those who contributed to make this release! ❤️
🐛 Bug Fixes
joi
package - by @KobeNguyenTChangelog
3.5.13
❤️ Thanks all to those who contributed to make this release! ❤️
🛩️ Features
startRecordingTraffic
grabRecordedNetworkTraffics
flushNetworkTraffics
stopRecordingTraffic
seeTraffic
dontSeeTraffic
Examples:
// recording traffics and verify the traffic
I.startRecordingTraffic();
I.amOnPage('https://codecept.io/');
I.seeTraffic({ name: 'traffics', url: 'https://codecept.io/img/companies/BC_LogoScreen_C.jpg' });
// check the traffic with advanced params
I.amOnPage('https://openai.com/blog/chatgpt');
I.startRecordingTraffic();
I.seeTraffic({
name: 'sentry event',
url: 'https://images.openai.com/blob/cf717bdb-0c8c-428a-b82b-3c3add87a600',
parameters: {
width: '1919',
height: '1138',
},
});
I.waitForCookie("token");
🐛 Bug Fixes
':nth-child'
into the arrayconst limitation = [':nth-of-type', ':first-of-type', ':last-of-type', ':nth-last-child', ':nth-last-of-type', ':checked', ':disabled', ':enabled', ':required', ':lang'];
fixes the issue. Then an old conversion way over css-to-xpath
is used.
📖 Documentation
🛩️ Several bugfixes and improvements for Codecept-UI