@auxcode/auxta 0.1.8 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "main": "src/AuxTA.ts",
6
6
  "scripts": {
package/src/AuxTA.ts CHANGED
@@ -20,20 +20,19 @@ class AuxTA extends FunctionHelper {
20
20
  super();
21
21
  let file;
22
22
  try {
23
- //todo find a better way to load the file
24
- let currentDir = "../"
23
+ let currentDir = ""
25
24
  while (true) {
26
25
  file = path.join(__dirname, currentDir, "auxta.json");
27
- try {
28
- fs.accessSync(file, fs.constants.R_OK | fs.constants.W_OK)
29
- break;
30
- } catch {
26
+ if (!fs.existsSync(file)) {
31
27
  currentDir += "../"
32
28
  if (currentDir.length >= 30) {
29
+ console.log("auxta.json file not found!")
33
30
  process.exit(1);
34
31
  return;
35
32
  }
33
+ continue;
36
34
  }
35
+ break;
37
36
  }
38
37
  const jsonConfig = JSON.parse(fs.readFileSync(file).toString());
39
38
  try {
@@ -43,7 +42,7 @@ class AuxTA extends FunctionHelper {
43
42
  }
44
43
  this.uploadModel = new UploadModel(jsonConfig.organization, jsonConfig.baseURL, jsonConfig.digitalProduct);
45
44
  } catch (e: any) {
46
- console.log("Missing or corrupted config: suitesList.json. Searching in location:", file)
45
+ console.log("Missing or corrupted config: auxta.json. Searching in location:", file)
47
46
  console.log(e);
48
47
  process.exit(1);
49
48
  }
@@ -26,7 +26,7 @@ export let config = {
26
26
  netlifyPath: "",
27
27
  digitalProduct: "",
28
28
  token: "",
29
- timeout: 1000,
29
+ timeout: 10000,
30
30
  suitesList: [],
31
31
  auxtaCredentials: {
32
32
  email: "",
@@ -36,16 +36,20 @@ function headers(token: string) {
36
36
  }
37
37
 
38
38
  async function auth() {
39
- //todo what happens if credentials are invalid?
40
- return (await axios.post(
39
+ return axios.post(
41
40
  config.auxtaURL + 'login',
42
41
  config.auxtaCredentials,
43
42
  {
44
43
  headers: {
45
44
  'Content-Type': 'application/json',
46
45
  }
47
- }
48
- )).data.token;
46
+ })
47
+ .then(({data}) => {
48
+ return data.token
49
+ })
50
+ .catch(() => {
51
+ throw new Error("Invalid login credentials")
52
+ });
49
53
  }
50
54
 
51
55
  export async function createEmptyReport(body: any): Promise<string> {
@@ -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 = Number(process.env.AUXTA_TIMEOUT);
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('And', `I click on the ${text} ${selector}`, StepStatusEnum.PASSED);
28
+ log.push('Then', message, StepStatusEnum.PASSED);
27
29
  await linkHandlers.click();
28
30
  } else {
29
- log.push('And', `I click on the ${text} ${selector}`, StepStatusEnum.FAILED);
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', `I checked for ${text} and found it.`, StepStatusEnum.PASSED);
40
+ log.push('And', message, StepStatusEnum.PASSED);
38
41
  return true;
39
42
  } else {
40
- log.push('And', `I checked for ${text} and found it.`, StepStatusEnum.FAILED);
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('And', `I go to the ${page} page`, StepStatusEnum.PASSED);
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
- const elementName = await puppeteer.defaultPage.$eval(field, (e) => e.textContent);
53
- log.push('And', `I type '${value}' into the ${elementName} field`, StepStatusEnum.PASSED);
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
- await page.waitForSelector(selector, {
76
- [option]: true,
77
- timeout: time
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
- const elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
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', `I am on the ${selector} page`, StepStatusEnum.FAILED);
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', `I am on the ${selector} page`, StepStatusEnum.PASSED);
107
+ log.push('And', message, StepStatusEnum.PASSED);
95
108
  }
96
109
 
97
110
  }