Reputation: 8258
I'm trying to run WebdriverIO tests based on dynamic data.
So far I have something like this:
JSON file:
{
"items": [
{
"name": "Item 1",
"value": 5000
}, {
"name": "Item 2",
"value": 6000
},
{
"name": "Item 3",
"value": 7000
}
]
}
spec file
import * as data from './items.data.json';
describe('Desc', () => {
data.items.forEach((item: any) => {
// Driver runs all these first...
// before(async () => {
// await MainPage.registerItem(item.name, item.value);
// });
// Need to have this rather than the before
it('Set up', async () => {
await MainPage.registerItem(item.name, item.value);
});
it('Should test something', async () => {
await OtherPage.doSomething(item.name, item.value);
});
});
});
This works but the before
does not behave as expected and an it
is required. Is there a better way of doing this?
Upvotes: 0
Views: 427
Reputation: 19939
import * as data from './items.data.json';
data.items.forEach((item: any) => {
describe('Desc', () => {
// Driver runs all these first...
// before(async () => {
// await MainPage.registerItem(item.name, item.value);
// });
// Need to have this rather than the before
it('Set up', async () => {
await MainPage.registerItem(item.name, item.value);
});
it('Should test something', async () => {
await OtherPage.doSomething(item.name, item.value);
});
});
});
just get the forloop with describe as before executes for each describe , else use beforeEach
Upvotes: 1