@auxcode/auxta 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -20,29 +20,40 @@ export class FunctionHelper {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
public async clickByText(selector: string, text: string, page = puppeteer.defaultPage) {
|
|
23
|
-
await page.waitForTimeout(this.defaultTimeout);
|
|
24
|
-
const [linkHandlers] = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
25
|
-
|
|
26
23
|
const message = `I click on the '${text}' '${selector}'`;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
try{
|
|
25
|
+
await page.waitForSelector(selector, {
|
|
26
|
+
timeout: this.defaultTimeout
|
|
27
|
+
});
|
|
28
|
+
const [linkHandlers] = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
29
|
+
|
|
30
|
+
if (linkHandlers) {
|
|
31
|
+
log.push('Then', message, StatusOfStep.PASSED);
|
|
32
|
+
await linkHandlers.click();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
} catch (e){
|
|
33
36
|
}
|
|
37
|
+
log.push('Then', message, StatusOfStep.FAILED);
|
|
38
|
+
throw new Error(message);
|
|
39
|
+
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
public async waitForSelectorWithText(selector: string, text: string, page = puppeteer.defaultPage) {
|
|
37
|
-
const linkHandlers = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
38
43
|
const message = `I check for '${text}' on the current page`;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
try{
|
|
45
|
+
await page.waitForSelector(selector, {
|
|
46
|
+
timeout: this.defaultTimeout
|
|
47
|
+
});
|
|
48
|
+
const linkHandlers = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
49
|
+
if (linkHandlers.length > 0) {
|
|
50
|
+
log.push('And', message, StatusOfStep.PASSED);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}catch (e) {
|
|
45
54
|
}
|
|
55
|
+
log.push('And', message, StatusOfStep.FAILED);
|
|
56
|
+
throw new Error(message);
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
public async goto(url: string, page = puppeteer.defaultPage) {
|
|
@@ -105,15 +116,17 @@ export class FunctionHelper {
|
|
|
105
116
|
log.push('And', message, StatusOfStep.PASSED);
|
|
106
117
|
}
|
|
107
118
|
|
|
108
|
-
public async click(
|
|
119
|
+
public async click(selector: string, page = puppeteer.defaultPage) {
|
|
109
120
|
try{
|
|
110
|
-
await page.waitForSelector(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
await
|
|
121
|
+
await page.waitForSelector(selector, {
|
|
122
|
+
timeout: this.defaultTimeout
|
|
123
|
+
});
|
|
124
|
+
let elementName = await puppeteer.defaultPage.$eval(selector, (e) => e.textContent);
|
|
125
|
+
if (!elementName || elementName === ' ') elementName = selector;
|
|
126
|
+
await page.click(selector);
|
|
114
127
|
log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
|
|
115
128
|
} catch (e){
|
|
116
|
-
const msg = `I click on the '${
|
|
129
|
+
const msg = `I click on the '${selector}'`;
|
|
117
130
|
log.push('Then', msg, StatusOfStep.FAILED);
|
|
118
131
|
throw new Error(msg)
|
|
119
132
|
}
|