@auxcode/auxta 0.3.0 → 0.3.4

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.0",
3
+ "version": "0.3.4",
4
4
  "description": "",
5
5
  "main": "src/AuxTA.ts",
6
6
  "scripts": {
@@ -3,6 +3,7 @@ import { config } from "../configs/config";
3
3
 
4
4
  export function startSuite(suites: string[], reportId?: string) {
5
5
  console.log('Starting next suite: ' + suites[0]);
6
+ //todo on error, end the test
6
7
  return axios.post(
7
8
  `${config.netlifyPath}.netlify/functions/${suites.shift()}?token=${config.token}`,
8
9
  { nextSuites: suites, reportId: reportId}
@@ -20,29 +20,36 @@ 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
+ const [linkHandlers] = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
26
+
27
+ if (linkHandlers) {
28
+ await linkHandlers.click();
29
+ log.push('Then', message, StatusOfStep.PASSED);
30
+ return;
31
+ }
32
+ } catch (e){
33
33
  }
34
+ log.push('Then', message, StatusOfStep.FAILED);
35
+ throw new Error(message);
34
36
  }
35
37
 
36
38
  public async waitForSelectorWithText(selector: string, text: string, page = puppeteer.defaultPage) {
37
- const linkHandlers = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
38
39
  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}`);
40
+ try{
41
+ await page.waitForSelector(selector, {
42
+ timeout: this.defaultTimeout
43
+ });
44
+ const linkHandlers = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
45
+ if (linkHandlers.length > 0) {
46
+ log.push('And', message, StatusOfStep.PASSED);
47
+ return true;
48
+ }
49
+ }catch (e) {
45
50
  }
51
+ log.push('And', message, StatusOfStep.FAILED);
52
+ throw new Error(message);
46
53
  }
47
54
 
48
55
  public async goto(url: string, page = puppeteer.defaultPage) {
@@ -105,20 +112,28 @@ export class FunctionHelper {
105
112
  log.push('And', message, StatusOfStep.PASSED);
106
113
  }
107
114
 
108
- public async click(className: string, page = puppeteer.defaultPage) {
109
- await page.waitForTimeout(this.defaultTimeout);
110
- let elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
111
- if (!elementName || elementName === ' ') elementName = className;
112
- await page.click(className);
113
- log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
115
+ public async click(selector: string, page = puppeteer.defaultPage) {
116
+ try{
117
+ await page.waitForSelector(selector, {
118
+ timeout: this.defaultTimeout
119
+ });
120
+ let elementName = await page.$eval(selector, (e) => e.textContent);
121
+ if (!elementName || elementName === ' ') elementName = selector;
122
+ await page.click(selector);
123
+ log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
124
+ } catch (e){
125
+ const msg = `I click on the '${selector}'`;
126
+ log.push('Then', msg, StatusOfStep.FAILED);
127
+ throw new Error(msg)
128
+ }
114
129
  }
115
130
 
116
- public async urlContains(selector: string) {
117
- const url = puppeteer.defaultPage.url();
131
+ public async urlContains(selector: string, page = puppeteer.defaultPage) {
132
+ const url = page.url();
118
133
  let message = `I am on the ${selector} page`
119
134
  if (!url.includes(selector)) {
120
135
  log.push('And', message, StatusOfStep.FAILED);
121
- throw new Error(`I am not at the '${selector}' page`)
136
+ throw new Error(message)
122
137
  }
123
138
  log.push('And', message, StatusOfStep.PASSED);
124
139
  }