I tried doing like this:
JavaScript
x
3
1
await browser.url(https://webdriver.io/');
2
expect(browser).toHaveText('h1')
3
so tried:
JavaScript
1
3
1
await browser.url(https://webdriver.io/');
2
await browser.findElement('xpath', 'h1')
3
But it doesn’t help
Advertisement
Answer
this is how i solved the issue:
JavaScript
1
32
32
1
const url = 'https://webdriver.io/';
2
const crossFetch = require('cross-fetch');
3
const links = [];
4
5
describe('test', async () => {
6
beforeEach(async function () {
7
const result = await crossFetch(`${url}/wp-json/wp/v2/pages/?per_page=100`);
8
const pages = await result.json();
9
pages.forEach(page => links.push(page.link));
10
});
11
12
it('Check Headers', async () => {
13
const errorsUrls = [];
14
15
for (const url of links) {
16
await browser.url(url);
17
const classNameAndText = await $('h3');
18
19
if (typeof classNameAndText.error !== 'undefined') {
20
errorsUrls.push(url);
21
}
22
}
23
24
if (errorsUrls.length > 0) {
25
throw new Error( `
26
Header Not Found:
27
${errorsUrls.join('rn')}
28
`);
29
}
30
})
31
});
32