@auxcode/auxta 0.1.11 → 0.2.0
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 +1 -1
- package/src/AuxTA.ts +0 -6
- package/src/auxta/configs/config.ts +1 -1
- package/src/macros/helpers/code.helper.ts +28 -15
package/package.json
CHANGED
package/src/AuxTA.ts
CHANGED
|
@@ -24,12 +24,6 @@ class AuxTA extends FunctionHelper {
|
|
|
24
24
|
while (true) {
|
|
25
25
|
file = path.join(__dirname, currentDir, "auxta.json");
|
|
26
26
|
if (!fs.existsSync(file)) {
|
|
27
|
-
console.log("Current dir: ", file)
|
|
28
|
-
console.log("Files: ")
|
|
29
|
-
const files = fs.readdirSync(path.join(__dirname, currentDir));
|
|
30
|
-
files.forEach(file => {
|
|
31
|
-
console.log("- " + file);
|
|
32
|
-
});
|
|
33
27
|
currentDir += "../"
|
|
34
28
|
if (currentDir.length >= 30) {
|
|
35
29
|
console.log("auxta.json file not found!")
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import log from "../../auxta/services/log.service";
|
|
2
2
|
import puppeteer from "../../puppeteer/puppeteer";
|
|
3
3
|
import { StepStatusEnum } from "../../auxta/enums/step-status.enum";
|
|
4
|
+
import { config } from "../../auxta/configs/config";
|
|
4
5
|
|
|
5
6
|
export class FunctionHelper {
|
|
6
|
-
public readonly defaultTimeout: number =
|
|
7
|
+
public readonly defaultTimeout: number = config.timeout;
|
|
7
8
|
|
|
8
9
|
public log(keyword: string, name: string, status: StepStatusEnum){
|
|
9
10
|
log.push(keyword, name, status)
|
|
@@ -22,35 +23,38 @@ export class FunctionHelper {
|
|
|
22
23
|
await page.waitForTimeout(this.defaultTimeout);
|
|
23
24
|
const [linkHandlers] = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
24
25
|
|
|
26
|
+
const message = `I click on the ${text} ${selector}`;
|
|
25
27
|
if (linkHandlers) {
|
|
26
|
-
log.push('
|
|
28
|
+
log.push('Then', message, StepStatusEnum.PASSED);
|
|
27
29
|
await linkHandlers.click();
|
|
28
30
|
} else {
|
|
29
|
-
log.push('
|
|
31
|
+
log.push('Then', message, StepStatusEnum.FAILED);
|
|
30
32
|
throw new Error(`Link not found: ${text}`);
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
public async waitForSelectorWithText(selector: string, text: string) {
|
|
35
37
|
const linkHandlers = await puppeteer.defaultPage.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
|
|
38
|
+
const message = `I check for ${text}`;
|
|
36
39
|
if (linkHandlers.length > 0) {
|
|
37
|
-
log.push('And',
|
|
40
|
+
log.push('And', message, StepStatusEnum.PASSED);
|
|
38
41
|
return true;
|
|
39
42
|
} else {
|
|
40
|
-
log.push('And',
|
|
43
|
+
log.push('And', message, StepStatusEnum.FAILED);
|
|
41
44
|
throw new Error(`Link not found: ${text}`);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
public async goto(page: string) {
|
|
46
49
|
await puppeteer.defaultPage.goto(page);
|
|
47
|
-
log.push('
|
|
50
|
+
log.push('Then', `I go to the ${page} page`, StepStatusEnum.PASSED);
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
public async type(field: string, value: string) {
|
|
51
54
|
await puppeteer.defaultPage.type(field, value);
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
let elementName = await puppeteer.defaultPage.$eval(field, (e) => e.textContent);
|
|
56
|
+
if (!elementName || elementName === ' ') elementName = field;
|
|
57
|
+
log.push('Then', `I type '${value}' into the ${elementName} field`, StepStatusEnum.PASSED);
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
public async waitForNetwork() {
|
|
@@ -72,26 +76,35 @@ export class FunctionHelper {
|
|
|
72
76
|
*/
|
|
73
77
|
|
|
74
78
|
public async waitForSelector(option: string, selector: string, time: number = this.defaultTimeout, page = puppeteer.defaultPage) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
const message = `I check for the ${selector} element to be ${option}`;
|
|
80
|
+
try{
|
|
81
|
+
await page.waitForSelector(selector, {
|
|
82
|
+
[option]: true,
|
|
83
|
+
timeout: time
|
|
84
|
+
});
|
|
85
|
+
} catch (e){
|
|
86
|
+
log.push('And', message, StepStatusEnum.FAILED);
|
|
87
|
+
throw new Error(message)
|
|
88
|
+
}
|
|
89
|
+
log.push('And', message, StepStatusEnum.PASSED);
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
public async click(className: string, page = puppeteer.defaultPage) {
|
|
82
93
|
await page.waitForTimeout(this.defaultTimeout);
|
|
83
|
-
|
|
94
|
+
let elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
|
|
95
|
+
if (!elementName || elementName === ' ') elementName = className;
|
|
84
96
|
await page.click(className);
|
|
85
97
|
log.push('Then', `I click on ${elementName}`, StepStatusEnum.PASSED);
|
|
86
98
|
}
|
|
87
99
|
|
|
88
100
|
public async urlContains(selector: string) {
|
|
89
101
|
const url = puppeteer.defaultPage.url();
|
|
102
|
+
let message = `I am on the ${selector} page`
|
|
90
103
|
if (!url.includes(selector)) {
|
|
91
|
-
log.push('And',
|
|
104
|
+
log.push('And', message, StepStatusEnum.FAILED);
|
|
92
105
|
throw new Error(`I am not at the ${selector} page`)
|
|
93
106
|
}
|
|
94
|
-
log.push('And',
|
|
107
|
+
log.push('And', message, StepStatusEnum.PASSED);
|
|
95
108
|
}
|
|
96
109
|
|
|
97
110
|
}
|