Provides tool for running data driven tests in webdriverio.
npm install @rpii/wdio-data-drivensh
npm i @rpii/wdio-data-driven --save
`
#### Example 1: Simple usage
1. Create DataDrivenTest instance passing a function representing the body of the test
(the Arrange
TestFn
Assert_ functions).
2. Call forCases method with object containing names and data for test cases. Use disabled parameter to deactivate test case(see example).
3. Pass in a spreadsheet with the credentials to be tested.
`js
import DataDrivenTest from '@rpii/wdio-data-driven';
import {authConfig} from '../configs/auth';
suite('login test suite', function () {
test('user login missing password', function () {
new DataDrivenTest(browser, function(dataSet, name) {
LoginPage.loginFn(dataSet,LoginPage.assertInvalidCredentials.bind(LoginPage));
})
.forCasesInSpreadsheet('./test/data/credentials.xlsx', 'bad-credentials');
});
};
`
#### Example 2: Building and reusing of "test blanks"
1. Create DataDrivenTest instance without parameters for our "test blank".
2. Call withArrange method passing Arrange function of "test blank".
3. Call testFn method passing Action function of "test blank".
4. Call withAssert defining the assert for this case.
5. Now you can reuse "test blank" calling withAssert and forCases methods with different _Assert_ functions and data in each particular test.
`js
import DataDrivenTest from '@rpii/wdio-data-driven';
import {mother} from '../mother';
// . Create "test blank"
let submitLoginForm = new DataDrivenTest()
.testFn(function(dt) {
this.browser.page.login().section.loginForm.fillAndSubmit(dt.email, dt.pass)
})
.withArrange(function(cb) {
browser.logout(cb)
});
suite('invalid email test suite', function () {
test('Login is invalid email: show error': function () {
// . Use "test blank" with specific assertion and test cases
submitLoginForm
.withAssert((dt, nm) => browser.page.login().assertNoProgress(nm))
.forCases({
"1. ": {email: "a", pass: mother.Valid.PASS},
"2. ": {email: "@b", pass: mother.Valid.PASS},
"3. ": {email: "@b.", pass: mother.Valid.PASS},
"4. ": {email: "@b.c", pass: mother.Valid.PASS},
"5. ": {email: "a@b", pass: mother.Valid.PASS},
"6. ": {email: "a@b.", pass: mother.Valid.PASS},
"7. ": {email: "a@b.c", pass: mother.Valid.PASS},
"8. ": {email: "й@ц.ук", pass: mother.Valid.PASS},
});
});
test('Login is valid email: show progress': function () {
// . Use "test blank" with specific assertion and test cases
submitLoginForm
.withAssert((dt, nm) => browser.page.login().assertProgressDisplayed(nm))
.forCases({
"1. ": {email: "a@b.cd"},
"2. ": {email: "1#$%&'*+/=?^-_{|}~.a@b.cd"},
{|}~.a@b.cd"},
{ name: "3. ", email: "a@1-b.cd"},
{ name: "4. ", email: "a@b.12"}
];
});
test('Login is valid email: show progress': function () {
// . Use "test blank" with specific assertion and test cases
submitLoginForm
.withAssert((dt, nm) => browser.page.login().assertProgressDisplayed(nm))
.forCases(arrayTest);
}
``