@auxcode/auxta 0.3.1 → 0.3.5

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.5",
4
4
  "description": "",
5
5
  "main": "src/AuxTA.ts",
6
6
  "scripts": {
package/src/AuxTA.ts CHANGED
@@ -62,14 +62,14 @@ class AuxTA extends FunctionHelper {
62
62
  if (overrideConfig) {
63
63
  if (overrideConfig.digitalProduct) this.uploadModel.digitalProduct = overrideConfig.digitalProduct
64
64
  if (overrideConfig.environment) this.uploadModel.environment = overrideConfig.environment
65
- if (overrideConfig.baseUrl) this.uploadModel.baseUrl = overrideConfig.baseUrl
65
+ if (overrideConfig.baseURL) this.uploadModel.baseUrl = overrideConfig.baseURL
66
66
  this.config = setupOverrideConfig(overrideConfig)
67
67
  }
68
68
  }
69
69
 
70
70
  public async startBrowser(event: any, callback: any, feature: string, scenario: string, overrideConfig?: any, singleFeature = false) {
71
71
  this.changeModelData(overrideConfig);
72
- if (singleFeature) {
72
+ if (singleFeature && process.env.ENVIRONMENT !== 'LOCAL') {
73
73
  if (process.env.ENVIRONMENT === 'LIVE' && event.queryStringParameters.token !== this.config.token)
74
74
  return {statusCode: 401, message: 'Unauthorized'}
75
75
  this.uploadModel.reportId = await createEmptyReport(this.uploadModel);
@@ -24,6 +24,8 @@ export function setupConfig(jsonConfig: any) {
24
24
  export function setupOverrideConfig(overrideConfig: any){
25
25
  if (overrideConfig.baseURL) config.baseURL = overrideConfig.baseURL;
26
26
  if (overrideConfig.digitalProduct) config.digitalProduct = overrideConfig.digitalProduct;
27
+ if (overrideConfig.screenWidth) config.screenWidth = overrideConfig.screenWidth;
28
+ if (overrideConfig.screenHeight) config.screenHeight = overrideConfig.screenHeight;
27
29
  return config;
28
30
  }
29
31
 
@@ -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,26 +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) {
115
+ public async click(selector: string, logMessages = true, page = puppeteer.defaultPage) {
109
116
  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);
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);
114
123
  log.push('Then', `I click on the '${elementName}'`, StatusOfStep.PASSED);
115
124
  } catch (e){
116
- const msg = `I click on the '${className}'`;
125
+ const msg = `I click on the '${selector}'`;
117
126
  log.push('Then', msg, StatusOfStep.FAILED);
118
127
  throw new Error(msg)
119
128
  }
120
129
  }
121
130
 
122
- public async urlContains(selector: string) {
123
- const url = puppeteer.defaultPage.url();
131
+ public async urlContains(selector: string, page = puppeteer.defaultPage) {
132
+ const url = page.url();
124
133
  let message = `I am on the ${selector} page`
125
134
  if (!url.includes(selector)) {
126
135
  log.push('And', message, StatusOfStep.FAILED);
127
- throw new Error(`I am not at the '${selector}' page`)
136
+ throw new Error(message)
128
137
  }
129
138
  log.push('And', message, StatusOfStep.PASSED);
130
139
  }