@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "",
5
5
  "main": "src/AuxTA.ts",
6
6
  "scripts": {
@@ -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
- if (linkHandlers) {
28
- log.push('Then', message, StatusOfStep.PASSED);
29
- await linkHandlers.click();
30
- } else {
31
- log.push('Then', message, StatusOfStep.FAILED);
32
- throw new Error(`Link not found: ${text}`);
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
- if (linkHandlers.length > 0) {
40
- log.push('And', message, StatusOfStep.PASSED);
41
- return true;
42
- } else {
43
- log.push('And', message, StatusOfStep.FAILED);
44
- throw new Error(`Link not found: ${text}`);
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(className: string, page = puppeteer.defaultPage) {
119
+ public async click(selector: string, page = puppeteer.defaultPage) {
109
120
  try{
110
- await page.waitForSelector(className);
111
- let elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
112
- if (!elementName || elementName === ' ') elementName = className;
113
- await page.click(className);
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 '${className}'`;
129
+ const msg = `I click on the '${selector}'`;
117
130
  log.push('Then', msg, StatusOfStep.FAILED);
118
131
  throw new Error(msg)
119
132
  }