@auxcode/auxta 0.1.5 → 0.1.9

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.5",
3
+ "version": "0.1.9",
4
4
  "description": "",
5
5
  "main": "src/AuxTA.ts",
6
6
  "scripts": {
package/src/AuxTA.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import puppeteer, { Puppeteer } from "./puppeteer/puppeteer";
2
- import f, { FunctionHelper } from "./macros/helpers/code.helper";
2
+ import { FunctionHelper } from "./macros/helpers/code.helper";
3
3
  import path from "path";
4
4
  import fs from "fs";
5
5
  import StepStatusEnum from "./auxta/enums/step-status.enum";
@@ -11,25 +11,33 @@ import { createEmptyReport } from "./auxta/services/report.service";
11
11
 
12
12
  dotenv.config();
13
13
 
14
- class AuxTA {
14
+ class AuxTA extends FunctionHelper {
15
15
  public puppeteer: Puppeteer = puppeteer;
16
- public functions: FunctionHelper = f;
17
16
 
18
17
  private readonly uploadModel: UploadModel;
19
18
 
20
19
  constructor() {
20
+ super();
21
21
  let file;
22
22
  try {
23
23
  //todo find a better way to load the file
24
- let currentDir = "../"
24
+ let currentDir = ""
25
25
  while (true) {
26
26
  file = path.join(__dirname, currentDir, "auxta.json");
27
27
  try {
28
28
  fs.accessSync(file, fs.constants.R_OK | fs.constants.W_OK)
29
29
  break;
30
30
  } catch {
31
+ console.log("Current dir: ", file)
32
+ console.log("Files: ")
33
+ fs.readdir(path.join(__dirname, currentDir), (err, files) => {
34
+ files.forEach(file => {
35
+ console.log("- " + file);
36
+ });
37
+ });
31
38
  currentDir += "../"
32
- if (currentDir.length >= 30) {
39
+ if (currentDir.length >= 50) {
40
+ console.log("auxta.json file not found!")
33
41
  process.exit(1);
34
42
  return;
35
43
  }
@@ -43,7 +51,7 @@ class AuxTA {
43
51
  }
44
52
  this.uploadModel = new UploadModel(jsonConfig.organization, jsonConfig.baseURL, jsonConfig.digitalProduct);
45
53
  } catch (e: any) {
46
- console.log("Missing or corrupted config: suitesList.json. Searching in location:", file)
54
+ console.log("Missing or corrupted config: auxta.json. Searching in location:", file)
47
55
  console.log(e);
48
56
  process.exit(1);
49
57
  }
@@ -72,7 +80,4 @@ export const StepStatus = StepStatusEnum;
72
80
 
73
81
  const auxta: AuxTA = new AuxTA();
74
82
 
75
- export const auxtaRun = auxta.run;
76
- export const auxtaFunc = auxta.functions;
77
-
78
83
  export default auxta;
@@ -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> {
@@ -3,7 +3,7 @@ import puppeteer from "../../puppeteer/puppeteer";
3
3
  import { StepStatusEnum } from "../../auxta/enums/step-status.enum";
4
4
 
5
5
  export class FunctionHelper {
6
- public readonly timeout: number = Number(process.env.AUXTA_TIMEOUT);
6
+ public readonly defaultTimeout: number = Number(process.env.AUXTA_TIMEOUT);
7
7
 
8
8
  public log(keyword: string, name: string, status: StepStatusEnum){
9
9
  log.push(keyword, name, status)
@@ -12,26 +12,27 @@ export class FunctionHelper {
12
12
  public suggest(name: string){
13
13
  log.addSuggestion(name)
14
14
  }
15
+
16
+ private getEscapedText(text: string){
17
+ const splitedQuotes = text.replace(/'/g, `', "'", '`)
18
+ return `concat('${splitedQuotes}', '')`;
19
+ }
15
20
 
16
21
  public async clickByText(selector: string, text: string, page = puppeteer.defaultPage) {
17
- await page.waitForTimeout(this.timeout);
18
- const splitedQuotes = text.replace(/'/g, `', "'", '`)
19
- const escapedText = `concat('${splitedQuotes}', '')`;
20
- const [linkHandlers] = await page.$x(`//${selector}[. = ${escapedText}]`);
22
+ await page.waitForTimeout(this.defaultTimeout);
23
+ const [linkHandlers] = await page.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
21
24
 
22
25
  if (linkHandlers) {
23
- log.push('And', `I click ${selector} with text ${text}`, StepStatusEnum.PASSED);
26
+ log.push('And', `I click on the ${text} ${selector}`, StepStatusEnum.PASSED);
24
27
  await linkHandlers.click();
25
28
  } else {
26
- log.push('And', `I click ${selector} with text ${text}`, StepStatusEnum.FAILED);
29
+ log.push('And', `I click on the ${text} ${selector}`, StepStatusEnum.FAILED);
27
30
  throw new Error(`Link not found: ${text}`);
28
31
  }
29
32
  }
30
33
 
31
34
  public async waitForSelectorWithText(selector: string, text: string) {
32
- const splitedQuotes = text.replace(/'/g, `', "'", '`)
33
- const escapedText = `concat('${splitedQuotes}', '')`;
34
- const linkHandlers = await puppeteer.defaultPage.$x(`//${selector}[. = ${escapedText}]`);
35
+ const linkHandlers = await puppeteer.defaultPage.$x(`//${selector}[. = ${this.getEscapedText(text)}]`);
35
36
  if (linkHandlers.length > 0) {
36
37
  log.push('And', `I checked for ${text} and found it.`, StepStatusEnum.PASSED);
37
38
  return true;
@@ -43,16 +44,23 @@ export class FunctionHelper {
43
44
 
44
45
  public async goto(page: string) {
45
46
  await puppeteer.defaultPage.goto(page);
47
+ log.push('And', `I go to the ${page} page`, StepStatusEnum.PASSED);
46
48
  }
47
49
 
48
50
  public async type(field: string, value: string) {
49
51
  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);
50
54
  }
51
55
 
52
56
  public async waitForNetwork() {
53
57
  await puppeteer.defaultPage.waitForNetworkIdle();
54
58
  }
55
59
 
60
+ public async timeout(timeout = this.defaultTimeout) {
61
+ await puppeteer.defaultPage.waitForTimeout(timeout);
62
+ }
63
+
56
64
  /**
57
65
  * Waiting for selector with timeout 60000
58
66
  *
@@ -63,7 +71,7 @@ export class FunctionHelper {
63
71
  * @param page
64
72
  */
65
73
 
66
- public async waitForSelector(option: string, selector: string, time: number = this.timeout, page = puppeteer.defaultPage) {
74
+ public async waitForSelector(option: string, selector: string, time: number = this.defaultTimeout, page = puppeteer.defaultPage) {
67
75
  await page.waitForSelector(selector, {
68
76
  [option]: true,
69
77
  timeout: time
@@ -71,17 +79,19 @@ export class FunctionHelper {
71
79
  }
72
80
 
73
81
  public async click(className: string, page = puppeteer.defaultPage) {
74
- await page.waitForTimeout(this.timeout);
82
+ await page.waitForTimeout(this.defaultTimeout);
83
+ const elementName = await puppeteer.defaultPage.$eval(className, (e) => e.textContent);
75
84
  await page.click(className);
85
+ log.push('Then', `I click on ${elementName}`, StepStatusEnum.PASSED);
76
86
  }
77
87
 
78
88
  public async urlContains(selector: string) {
79
89
  const url = puppeteer.defaultPage.url();
80
90
  if (!url.includes(selector)) {
81
- await log.push('And', `I am on the ${selector} page`, StepStatusEnum.FAILED);
91
+ log.push('And', `I am on the ${selector} page`, StepStatusEnum.FAILED);
82
92
  throw new Error(`I am not at the ${selector} page`)
83
93
  }
84
- await log.push('And', `I am on the ${selector} page`, StepStatusEnum.PASSED);
94
+ log.push('And', `I am on the ${selector} page`, StepStatusEnum.PASSED);
85
95
  }
86
96
 
87
97
  }