@auxcode/auxta 0.1.9 → 0.2.1

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/README.md CHANGED
@@ -36,9 +36,13 @@ npm i
36
36
  # Default 1000
37
37
  "timeout": 1000,
38
38
  # The credentials of the user that uploads the tests to the site
39
- "email": "",
40
- "password": "",
41
- "token": ""
39
+ "email": "string",
40
+ "password": "string",
41
+ "token": "string"
42
+ # Screen width and height used in the testing
43
+ # Allows testing from mobile devices screens
44
+ "screenWidth": 1920,
45
+ "screenHeight": 1080,
42
46
  }
43
47
 
44
48
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "main": "src/AuxTA.ts",
6
6
  "scripts": {
package/src/AuxTA.ts CHANGED
@@ -20,28 +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
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 {
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
- });
26
+ if (!fs.existsSync(file)) {
38
27
  currentDir += "../"
39
- if (currentDir.length >= 50) {
28
+ if (currentDir.length >= 30) {
40
29
  console.log("auxta.json file not found!")
41
30
  process.exit(1);
42
31
  return;
43
32
  }
33
+ continue;
44
34
  }
35
+ break;
45
36
  }
46
37
  const jsonConfig = JSON.parse(fs.readFileSync(file).toString());
47
38
  try {
@@ -16,6 +16,8 @@ export function setupConfig(jsonConfig: any) {
16
16
  if (!jsonConfig.suitesList) throw new Error("suitesList");
17
17
  config.suitesList = jsonConfig.suitesList;
18
18
  if (jsonConfig.timeout) config.timeout = jsonConfig.timeout;
19
+ if (jsonConfig.screenWidth) config.screenWidth = jsonConfig.screenWidth;
20
+ if (jsonConfig.screenHeight) config.screenHeight = jsonConfig.screenHeight;
19
21
  }
20
22
 
21
23
  export let config = {
@@ -26,7 +28,9 @@ export let config = {
26
28
  netlifyPath: "",
27
29
  digitalProduct: "",
28
30
  token: "",
29
- timeout: 1000,
31
+ screenWidth: 1920,
32
+ screenHeight: 1080,
33
+ timeout: 10000,
30
34
  suitesList: [],
31
35
  auxtaCredentials: {
32
36
  email: "",
@@ -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
  }
@@ -14,17 +14,23 @@ export class Puppeteer {
14
14
  private browser!: puppeteer_core.Browser;
15
15
 
16
16
  public async startBrowser() {
17
+ let args = [
18
+ '--start-maximized',
19
+ '--no-sandbox',
20
+ '--disable-setuid-sandbox',
21
+ '--disable-dev-shm-usage',
22
+ '--single-process'
23
+ ];
24
+ if (process.env.ENVIRONMENT != 'LOCAL')
25
+ args.push(`--window-size=${config.screenWidth},${config.screenHeight}`)
17
26
  this.browser = await chromium.puppeteer.launch({
18
27
  executablePath: process.env.NODE_ENV !== 'production' ? undefined : await chromium.executablePath,
19
- args: [
20
- '--start-maximized',
21
- '--no-sandbox',
22
- '--disable-setuid-sandbox',
23
- '--disable-dev-shm-usage',
24
- '--single-process'
25
- ],
26
- defaultViewport: null,
27
- // Return back to headless for commit
28
+ args,
29
+ defaultViewport: process.env.ENVIRONMENT == 'LOCAL' ? null : {
30
+ width: config.screenWidth,
31
+ height: config.screenHeight
32
+ },
33
+ // Return back to headless for netlify
28
34
  headless: process.env.ENVIRONMENT == 'LOCAL' ? false : chromium.headless
29
35
  });
30
36
  this.defaultPage = (await this.browser.pages())[0];