@auxcode/auxta 0.2.8 → 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.2.8",
3
+ "version": "0.3.2",
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,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) {
@@ -52,6 +63,9 @@ export class FunctionHelper {
52
63
 
53
64
  public async type(field: string, value: string, page = puppeteer.defaultPage) {
54
65
  try{
66
+ await page.waitForSelector(field, {
67
+ timeout: this.defaultTimeout
68
+ });
55
69
  await page.type(field, value);
56
70
  let elementName = await page.$eval(field, (e) => e.textContent);
57
71
  if (!elementName || elementName === ' ') elementName = field;
@@ -102,12 +116,20 @@ export class FunctionHelper {
102
116
  log.push('And', message, StatusOfStep.PASSED);
103
117
  }
104
118
 
105
- public async click(className: string, page = puppeteer.defaultPage) {
106
- await page.waitForTimeout(this.defaultTimeout);
107
- let elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
108
- if (!elementName || elementName === ' ') elementName = className;
109
- await page.click(className);
110
- log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
119
+ public async click(selector: string, page = puppeteer.defaultPage) {
120
+ try{
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);
127
+ log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
128
+ } catch (e){
129
+ const msg = `I click on the '${selector}'`;
130
+ log.push('Then', msg, StatusOfStep.FAILED);
131
+ throw new Error(msg)
132
+ }
111
133
  }
112
134
 
113
135
  public async urlContains(selector: string) {
@@ -88,8 +88,8 @@ export class Puppeteer {
88
88
 
89
89
  private static setupHeader(event: any, uploadModel: UploadModel) {
90
90
  let close = true;
91
- if (process.env.ENVIRONMENT !== 'LOCAL') {
92
- const body = JSON.parse(event.body);
91
+ if (process.env.ENVIRONMENT !== 'LOCAL' && event.body) {
92
+ const body = JSON.parse(event.body)
93
93
  uploadModel.reportId = body.reportId;
94
94
  uploadModel.nextSuites = body.nextSuites;
95
95
  } else if (event.queryStringParameters.close) {