Skip to content

Commit b061fcc

Browse files
committed
Fix
1 parent 9ea804f commit b061fcc

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

test/browser/index.js

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,28 @@ const { TARGET_URL } = process.env;
1010
/** @type {import("nightwatch").NightwatchTestFunctions} */
1111
module.exports = {
1212
/** @param {import("nightwatch").NightwatchBrowser} client */
13-
async ["Browser Test"](client) {
14-
let response = null;
15-
let success = false;
16-
17-
try {
18-
response = await client.url(
19-
TARGET_URL || "http://127.0.0.1:8000/power.html",
20-
)
21-
.waitForElementPresent("#mocha-report .suite:nth-of-type(4)", 30000)
22-
.findElements("#mocha-report .test .error");
23-
} catch (e) {
24-
if (e.name === "NoSuchElementError") {
25-
success = true;
26-
} else {
27-
// unexpected error
28-
throw e;
13+
["Browser Test"](client) {
14+
client.url(TARGET_URL || "http://127.0.0.1:8000/power.html")
15+
.waitForElementPresent("#mocha-report .suite:nth-of-type(4)", 30000)
16+
.elements("css selector", "#mocha-report .test .error", async (result) => {
17+
// unexpected error
18+
client.verify.ok(result.status === 0, "Check unexpected error");
19+
if (result.status === 0) {
20+
throw result.value;
2921
}
30-
}
3122

32-
client.verify.ok(success, "Check error elements");
33-
if (success) {
34-
return;
35-
}
23+
const success = result.value == null || result.value.length === 0;
24+
client.verify.ok(success, "Check error elements");
25+
if (success) {
26+
return;
27+
}
3628

37-
// show error log
38-
for (const element of response.value) {
39-
const id = element.getId();
40-
const { value: error } = await client.elementIdText(id);
41-
client.verify.ok(false, `\n\n${red}${error}${reset}\n\n`);
42-
}
29+
// show error log
30+
for (const element of result.value) {
31+
const { value: error } = await client.elementIdText(element.ELEMENT);
32+
client.verify.ok(false, `\n\n${red}${error}${reset}\n\n`);
33+
}
34+
});
4335
},
4436

4537
afterEach(client, done) {

0 commit comments

Comments
 (0)