Nowadays there is better solution for most of the helpers implemented in this library: @testing-library/testcafe
This package exists to DRY up tests when they are scattered across multiple directories.
For example, if platformOS project is made of many modules and modules have to be tested individually, but also project has to be tested as a whole.
You can see example source code: examples
All functions are pure functions and are made with dependency injection in mind.
Provide the input (module itself does not include TestCafe as dependency) and you will get the output. All methods are async, so do not forget about await
ing for values.
npm i @platform-os/testcafe-helpers
import {
checkLiquidErrors,
getResultElement,
getResultText,
getBtAlertElement,
getBtAlertText
} from '@platform-os/testcafe-helpers';
Checks html body content liquid errors.
test('checkLiquidErrors', async t => {
await checkLiquidErrors({ t, Selector });
});
Gets TestCafe element marked using data-result
data attribute in html.
For HTML: <p data-result="money_total">50</p>
test('getResultElement', async t => {
const resultElement = await getResultElement({ name: 'money_total', Selector });
const attr = resultElement.getAttribute('data-result');
await t.expect(attr).eql('money_total');
});
Returns textContent
of an element marked using data-result
data attribute in html.
For HTML: <p data-result="money_total">50</p>
test('getResultText', async t => {
const resultText = await getResultText({ name: 'money_total', Selector });
await t.expect(resultText).eql('50');
});
Gets TestCafe element marked using default Twitter Bootstrap alert css class. type
defaults to success
.
For HTML: <div class="alert alert-danger">Error</div><div class="alert alert-success">Success</div>
test('getBtAlertElement', async t => {
const dangerElement = await getBtAlertElement({ type: 'danger', Selector });
const dangerText = await dangerElement.innerText;
const noTypeElement = await getBtAlertElement({ Selector });
const noTypeText = await noTypeElement.innerText;
await t.expect(dangerText).contains('Error');
await t.expect(noTypeText).contains('Success');
});
Returns textContent
of an alert marked using default Twitter Bootstrap alert css class. type
defaults to success
.
For HTML: <div class="alert alert-danger">Error</div><div class="alert alert-success">Success</div>
test('getBtAlertText', async t => {
const danger = await getBtAlertText({ type: 'danger', Selector });
const noType = await getBtAlertText({ Selector });
await t.expect(danger).contains('Error');
await t.expect(noType).contains('Success');
});
Returns an object with two objects inside: raw
and computed
.
Contains raw data from window.performance.timing
.
Computed contains couple commonly used metrics that will give you basic overview on the performance.
ttfb
- fromnavigationStart
tillresponseEnd
dns
- fromdomainLookupStart
tilldomainLookupEnd
tcp
- fromconnectStart
tillconnectEnd
domReady
- fromnavigationStart
tilldomComplete
networkLatency
-fetchStart
tillresponseEnd
processing
-loadEventEnd
tillresponseEnd
everything
-loadEventEnd
tillnavigationStart
test('DOM ready under 2s', async t => {
const perf = await getPerformanceMetrics({ t });
const computed = perf.computed;
await t.expect(computed.domReady).lt(2000);
});