@auxcode/auxta 0.1.6 → 0.1.7
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
|
@@ -3,7 +3,7 @@ import puppeteer from "../../puppeteer/puppeteer";
|
|
|
3
3
|
import { StepStatusEnum } from "../../auxta/enums/step-status.enum";
|
|
4
4
|
|
|
5
5
|
export class FunctionHelper {
|
|
6
|
-
public readonly
|
|
6
|
+
public readonly defaultTimeout: number = Number(process.env.AUXTA_TIMEOUT);
|
|
7
7
|
|
|
8
8
|
public log(keyword: string, name: string, status: StepStatusEnum){
|
|
9
9
|
log.push(keyword, name, status)
|
|
@@ -12,26 +12,27 @@ export class FunctionHelper {
|
|
|
12
12
|
public suggest(name: string){
|
|
13
13
|
log.addSuggestion(name)
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
private getEscapedText(text: string){
|
|
17
|
+
const splitedQuotes = text.replace(/'/g, `', "'", '`)
|
|
18
|
+
return `concat('${splitedQuotes}', '')`;
|
|
19
|
+
}
|
|
15
20
|
|
|
16
21
|
public async clickByText(selector: string, text: string, page = puppeteer.defaultPage) {
|
|
17
|
-
await page.waitForTimeout(this.
|
|
18
|
-
const
|
|
19
|
-
const escapedText = `concat('${splitedQuotes}', '')`;
|
|
20
|
-
const [linkHandlers] = await page.$x(`//${selector}[. = ${escapedText}]`);
|
|
22
|
+
await page.waitForTimeout(this.defaultTimeout);
|
|
23
|
+
const [linkHandlers] = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
21
24
|
|
|
22
25
|
if (linkHandlers) {
|
|
23
|
-
log.push('And', `I click ${
|
|
26
|
+
log.push('And', `I click on the ${text} ${selector}`, StepStatusEnum.PASSED);
|
|
24
27
|
await linkHandlers.click();
|
|
25
28
|
} else {
|
|
26
|
-
log.push('And', `I click ${
|
|
29
|
+
log.push('And', `I click on the ${text} ${selector}`, StepStatusEnum.FAILED);
|
|
27
30
|
throw new Error(`Link not found: ${text}`);
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
public async waitForSelectorWithText(selector: string, text: string) {
|
|
32
|
-
const
|
|
33
|
-
const escapedText = `concat('${splitedQuotes}', '')`;
|
|
34
|
-
const linkHandlers = await puppeteer.defaultPage.$x(`//${selector}[. = ${escapedText}]`);
|
|
35
|
+
const linkHandlers = await puppeteer.defaultPage.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
35
36
|
if (linkHandlers.length > 0) {
|
|
36
37
|
log.push('And', `I checked for ${text} and found it.`, StepStatusEnum.PASSED);
|
|
37
38
|
return true;
|
|
@@ -43,16 +44,23 @@ export class FunctionHelper {
|
|
|
43
44
|
|
|
44
45
|
public async goto(page: string) {
|
|
45
46
|
await puppeteer.defaultPage.goto(page);
|
|
47
|
+
log.push('And', `I go to the ${page} page`, StepStatusEnum.PASSED);
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
public async type(field: string, value: string) {
|
|
49
51
|
await puppeteer.defaultPage.type(field, value);
|
|
52
|
+
const elementName = await puppeteer.defaultPage.$eval(field, (e) => e.textContent);
|
|
53
|
+
log.push('And', `I type '${value}' into the ${elementName} field`, StepStatusEnum.PASSED);
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
public async waitForNetwork() {
|
|
53
57
|
await puppeteer.defaultPage.waitForNetworkIdle();
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
public async timeout(timeout = this.defaultTimeout) {
|
|
61
|
+
await puppeteer.defaultPage.waitForTimeout(timeout);
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
/**
|
|
57
65
|
* Waiting for selector with timeout 60000
|
|
58
66
|
*
|
|
@@ -63,7 +71,7 @@ export class FunctionHelper {
|
|
|
63
71
|
* @param page
|
|
64
72
|
*/
|
|
65
73
|
|
|
66
|
-
public async waitForSelector(option: string, selector: string, time: number = this.
|
|
74
|
+
public async waitForSelector(option: string, selector: string, time: number = this.defaultTimeout, page = puppeteer.defaultPage) {
|
|
67
75
|
await page.waitForSelector(selector, {
|
|
68
76
|
[option]: true,
|
|
69
77
|
timeout: time
|
|
@@ -71,17 +79,19 @@ export class FunctionHelper {
|
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
public async click(className: string, page = puppeteer.defaultPage) {
|
|
74
|
-
await page.waitForTimeout(this.
|
|
82
|
+
await page.waitForTimeout(this.defaultTimeout);
|
|
75
83
|
await page.click(className);
|
|
84
|
+
const elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
|
|
85
|
+
log.push('Then', `I click on ${elementName}`, StepStatusEnum.PASSED);
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
public async urlContains(selector: string) {
|
|
79
89
|
const url = puppeteer.defaultPage.url();
|
|
80
90
|
if (!url.includes(selector)) {
|
|
81
|
-
|
|
91
|
+
log.push('And', `I am on the ${selector} page`, StepStatusEnum.FAILED);
|
|
82
92
|
throw new Error(`I am not at the ${selector} page`)
|
|
83
93
|
}
|
|
84
|
-
|
|
94
|
+
log.push('And', `I am on the ${selector} page`, StepStatusEnum.PASSED);
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
}
|