@rich-automation/lotto 0.1.5 → 0.1.7

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.
@@ -5,10 +5,11 @@ exports.SELECTORS = {
5
5
  ID_INPUT: '#userId',
6
6
  PWD_INPUT: '#article > div:nth-child(2) > div > form > div > div.inner > fieldset > div.form > input[type=password]:nth-child(2)',
7
7
  LOGIN_BUTTON: '#article > div:nth-child(2) > div > form > div > div.inner > fieldset > div.form > a',
8
- PURCHASE_TYPE_RANDOM_BTN: '#tabWay2Buy a#num2',
8
+ ENVIRONMENT_ALERT_CONFIRM: 'input[value="확인"][onclick="javascript:closepopupLayerAlert();"]',
9
+ PURCHASE_TYPE_RANDOM_BTN: 'a[href="#divWay2Buy1"]#num2',
9
10
  PURCHASE_AMOUNT_SELECT: 'select#amoundApply',
10
- PURCHASE_AMOUNT_CONFIRM_BTN: '#btnSelectNum',
11
- PURCHASE_BTN: '#btnBuy',
12
- PURCHASE_CONFIRM_BTN: '#popupLayerConfirm .btns > input[value="확인"]',
11
+ PURCHASE_AMOUNT_CONFIRM_BTN: 'input[value="확인"]#btnSelectNum',
12
+ PURCHASE_BTN: 'input[value="구매하기"]#btnBuy',
13
+ PURCHASE_CONFIRM_BTN: 'input[value="확인"][onclick="javascript:closepopupLayerConfirm(true);"]',
13
14
  PURCHASE_NUMBER_LIST: '#reportRow .nums'
14
15
  };
@@ -16,10 +16,10 @@ const playwright_page_1 = require("./playwright.page");
16
16
  const constants_1 = require("../../constants");
17
17
  class PlaywrightController {
18
18
  constructor(configs, logger) {
19
- this.getBrowser = () => __awaiter(this, void 0, void 0, function* () {
19
+ this.getBrowserContext = () => __awaiter(this, void 0, void 0, function* () {
20
20
  const p = (0, deferred_1.deferred)();
21
- if (this.browser) {
22
- p.resolve(this.browser);
21
+ if (this.context) {
22
+ p.resolve(this.context);
23
23
  }
24
24
  else {
25
25
  let retry = 0;
@@ -28,9 +28,9 @@ class PlaywrightController {
28
28
  clearInterval(interval);
29
29
  p.reject(new Error('Browser is not initialized'));
30
30
  }
31
- else if (this.browser) {
31
+ else if (this.context) {
32
32
  clearInterval(interval);
33
- p.resolve(this.browser);
33
+ p.resolve(this.context);
34
34
  }
35
35
  retry++;
36
36
  }, constants_1.CONST.BROWSER_INIT_RETRY_TIMEOUT);
@@ -38,7 +38,7 @@ class PlaywrightController {
38
38
  return p.promise;
39
39
  });
40
40
  this.focus = (pageIndex = -1) => __awaiter(this, void 0, void 0, function* () {
41
- const browser = yield this.getBrowser();
41
+ const browser = yield this.getBrowserContext();
42
42
  const pages = browser.pages();
43
43
  if (pages.length === 0) {
44
44
  const page = yield browser.newPage();
@@ -53,11 +53,12 @@ class PlaywrightController {
53
53
  }
54
54
  });
55
55
  this.close = () => __awaiter(this, void 0, void 0, function* () {
56
- const browser = yield this.getBrowser();
57
- return browser.close();
56
+ const context = yield this.getBrowserContext();
57
+ yield context.close();
58
+ return this.browser.close();
58
59
  });
59
60
  this.cleanPages = (remainingPageIndex) => __awaiter(this, void 0, void 0, function* () {
60
- const browser = yield this.getBrowser();
61
+ const browser = yield this.getBrowserContext();
61
62
  const pages = browser.pages();
62
63
  const promises = pages.map((page, index) => __awaiter(this, void 0, void 0, function* () {
63
64
  if (!remainingPageIndex.includes(index)) {
@@ -68,7 +69,10 @@ class PlaywrightController {
68
69
  });
69
70
  this.configs = configs;
70
71
  this.logger = logger;
71
- playwright_1.chromium.launch(this.configs).then((browser) => __awaiter(this, void 0, void 0, function* () { return (this.browser = yield browser.newContext()); }));
72
+ playwright_1.chromium.launch(this.configs).then((browser) => __awaiter(this, void 0, void 0, function* () {
73
+ this.browser = browser;
74
+ this.context = yield browser.newContext();
75
+ }));
72
76
  }
73
77
  }
74
78
  exports.PlaywrightController = PlaywrightController;
@@ -106,6 +106,11 @@ class LottoService {
106
106
  this.logger.debug('[purchase]', 'move to lotto game page');
107
107
  const page = yield this.browserController.focus(0);
108
108
  yield page.goto(urls_1.URLS.LOTTO_645);
109
+ // remove alert in linux env (비정상적인 방법으로 접속)
110
+ if (process.env.CI) {
111
+ this.logger.debug('[purchase]', 'click environment alert confirm');
112
+ yield page.click(selectors_1.SELECTORS.ENVIRONMENT_ALERT_CONFIRM);
113
+ }
109
114
  // click auto button
110
115
  this.logger.debug('[purchase]', 'click purchase type button -> auto');
111
116
  yield page.click(selectors_1.SELECTORS.PURCHASE_TYPE_RANDOM_BTN);
@@ -2,10 +2,11 @@ export const SELECTORS = {
2
2
  ID_INPUT: '#userId',
3
3
  PWD_INPUT: '#article > div:nth-child(2) > div > form > div > div.inner > fieldset > div.form > input[type=password]:nth-child(2)',
4
4
  LOGIN_BUTTON: '#article > div:nth-child(2) > div > form > div > div.inner > fieldset > div.form > a',
5
- PURCHASE_TYPE_RANDOM_BTN: '#tabWay2Buy a#num2',
5
+ ENVIRONMENT_ALERT_CONFIRM: 'input[value="확인"][onclick="javascript:closepopupLayerAlert();"]',
6
+ PURCHASE_TYPE_RANDOM_BTN: 'a[href="#divWay2Buy1"]#num2',
6
7
  PURCHASE_AMOUNT_SELECT: 'select#amoundApply',
7
- PURCHASE_AMOUNT_CONFIRM_BTN: '#btnSelectNum',
8
- PURCHASE_BTN: '#btnBuy',
9
- PURCHASE_CONFIRM_BTN: '#popupLayerConfirm .btns > input[value="확인"]',
8
+ PURCHASE_AMOUNT_CONFIRM_BTN: 'input[value="확인"]#btnSelectNum',
9
+ PURCHASE_BTN: 'input[value="구매하기"]#btnBuy',
10
+ PURCHASE_CONFIRM_BTN: 'input[value="확인"][onclick="javascript:closepopupLayerConfirm(true);"]',
10
11
  PURCHASE_NUMBER_LIST: '#reportRow .nums'
11
12
  };
@@ -14,10 +14,10 @@ import { CONST } from '../../constants';
14
14
  import {} from '../../logger';
15
15
  export class PlaywrightController {
16
16
  constructor(configs, logger) {
17
- this.getBrowser = () => __awaiter(this, void 0, void 0, function* () {
17
+ this.getBrowserContext = () => __awaiter(this, void 0, void 0, function* () {
18
18
  const p = deferred();
19
- if (this.browser) {
20
- p.resolve(this.browser);
19
+ if (this.context) {
20
+ p.resolve(this.context);
21
21
  }
22
22
  else {
23
23
  let retry = 0;
@@ -26,9 +26,9 @@ export class PlaywrightController {
26
26
  clearInterval(interval);
27
27
  p.reject(new Error('Browser is not initialized'));
28
28
  }
29
- else if (this.browser) {
29
+ else if (this.context) {
30
30
  clearInterval(interval);
31
- p.resolve(this.browser);
31
+ p.resolve(this.context);
32
32
  }
33
33
  retry++;
34
34
  }, CONST.BROWSER_INIT_RETRY_TIMEOUT);
@@ -36,7 +36,7 @@ export class PlaywrightController {
36
36
  return p.promise;
37
37
  });
38
38
  this.focus = (pageIndex = -1) => __awaiter(this, void 0, void 0, function* () {
39
- const browser = yield this.getBrowser();
39
+ const browser = yield this.getBrowserContext();
40
40
  const pages = browser.pages();
41
41
  if (pages.length === 0) {
42
42
  const page = yield browser.newPage();
@@ -51,11 +51,12 @@ export class PlaywrightController {
51
51
  }
52
52
  });
53
53
  this.close = () => __awaiter(this, void 0, void 0, function* () {
54
- const browser = yield this.getBrowser();
55
- return browser.close();
54
+ const context = yield this.getBrowserContext();
55
+ yield context.close();
56
+ return this.browser.close();
56
57
  });
57
58
  this.cleanPages = (remainingPageIndex) => __awaiter(this, void 0, void 0, function* () {
58
- const browser = yield this.getBrowser();
59
+ const browser = yield this.getBrowserContext();
59
60
  const pages = browser.pages();
60
61
  const promises = pages.map((page, index) => __awaiter(this, void 0, void 0, function* () {
61
62
  if (!remainingPageIndex.includes(index)) {
@@ -66,6 +67,9 @@ export class PlaywrightController {
66
67
  });
67
68
  this.configs = configs;
68
69
  this.logger = logger;
69
- chromium.launch(this.configs).then((browser) => __awaiter(this, void 0, void 0, function* () { return (this.browser = yield browser.newContext()); }));
70
+ chromium.launch(this.configs).then((browser) => __awaiter(this, void 0, void 0, function* () {
71
+ this.browser = browser;
72
+ this.context = yield browser.newContext();
73
+ }));
70
74
  }
71
75
  }
@@ -100,6 +100,11 @@ export class LottoService {
100
100
  this.logger.debug('[purchase]', 'move to lotto game page');
101
101
  const page = yield this.browserController.focus(0);
102
102
  yield page.goto(URLS.LOTTO_645);
103
+ // remove alert in linux env (비정상적인 방법으로 접속)
104
+ if (process.env.CI) {
105
+ this.logger.debug('[purchase]', 'click environment alert confirm');
106
+ yield page.click(SELECTORS.ENVIRONMENT_ALERT_CONFIRM);
107
+ }
103
108
  // click auto button
104
109
  this.logger.debug('[purchase]', 'click purchase type button -> auto');
105
110
  yield page.click(SELECTORS.PURCHASE_TYPE_RANDOM_BTN);
@@ -2,6 +2,7 @@ export declare const SELECTORS: {
2
2
  ID_INPUT: string;
3
3
  PWD_INPUT: string;
4
4
  LOGIN_BUTTON: string;
5
+ ENVIRONMENT_ALERT_CONFIRM: string;
5
6
  PURCHASE_TYPE_RANDOM_BTN: string;
6
7
  PURCHASE_AMOUNT_SELECT: string;
7
8
  PURCHASE_AMOUNT_CONFIRM_BTN: string;
@@ -1,13 +1,14 @@
1
1
  import type { BrowserConfigs, BrowserControllerInterface } from '../../types';
2
- import type { BrowserContext } from 'playwright';
2
+ import type { Browser, BrowserContext } from 'playwright';
3
3
  import { PlaywrightPage } from './playwright.page';
4
4
  import { type LoggerInterface } from '../../logger';
5
5
  export declare class PlaywrightController implements BrowserControllerInterface {
6
6
  configs: BrowserConfigs;
7
7
  logger: LoggerInterface;
8
- browser: BrowserContext;
8
+ browser: Browser;
9
+ context: BrowserContext;
9
10
  constructor(configs: BrowserConfigs, logger: LoggerInterface);
10
- private getBrowser;
11
+ private getBrowserContext;
11
12
  focus: (pageIndex?: number) => Promise<PlaywrightPage>;
12
13
  close: () => Promise<void>;
13
14
  cleanPages: (remainingPageIndex: number[]) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rich-automation/lotto",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Lotto module",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -22,7 +22,6 @@
22
22
  "files": [
23
23
  "lib",
24
24
  "package.json",
25
- "playwright.config.ts",
26
25
  "README.md"
27
26
  ],
28
27
  "packageManager": "yarn@1.22.19",
@@ -37,7 +36,7 @@
37
36
  "build:dts": "tsc --project tsconfig.json --emitDeclarationOnly --declaration --declarationDir lib/typescript",
38
37
  "test": "jest --forceExit --detectOpenHandles",
39
38
  "install:puppeteer": "node ./node_modules/puppeteer/install.js",
40
- "install:playwright": "npx playwright install --with-deps",
39
+ "install:playwright": "npx playwright install chromium --with-deps",
41
40
  "fix": "yarn fix:eslint && yarn fix:prettier",
42
41
  "fix:eslint": "eslint --fix src --ext js,jsx,ts,tsx ",
43
42
  "fix:prettier": "prettier --write \"src/**/*.{ts,tsx,js}\"",
@@ -56,7 +55,6 @@
56
55
  "@babel/core": "^7.21.4",
57
56
  "@babel/preset-env": "^7.21.4",
58
57
  "@babel/preset-typescript": "^7.21.4",
59
- "@playwright/test": "^1.35.0",
60
58
  "@types/jest": "^29.5.0",
61
59
  "@typescript-eslint/eslint-plugin": "^5.58.0",
62
60
  "@typescript-eslint/parser": "^5.58.0",
@@ -1,66 +0,0 @@
1
- import { defineConfig, devices } from '@playwright/test';
2
-
3
- /**
4
- * Read environment variables from file.
5
- * https://github.com/motdotla/dotenv
6
- */
7
- // require('dotenv').config();
8
-
9
- /**
10
- * See https://playwright.dev/docs/test-configuration.
11
- */
12
- export default defineConfig({
13
- testDir: './src/__tests__',
14
- /* Run tests in files in parallel */
15
- fullyParallel: true,
16
- /* Fail the build on CI if you accidentally left test.only in the source code. */
17
- forbidOnly: !!process.env.CI,
18
- /* Retry on CI only */
19
- retries: process.env.CI ? 2 : 0,
20
- /* Opt out of parallel tests on CI. */
21
- workers: process.env.CI ? 1 : undefined,
22
- /* Reporter to use. See https://playwright.dev/docs/test-reporters */
23
- reporter: 'html',
24
- /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
25
- use: {
26
- /* Base URL to use in actions like `await page.goto('/')`. */
27
- // baseURL: 'http://127.0.0.1:3000',
28
-
29
- /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30
- trace: 'on-first-retry',
31
- },
32
-
33
- /* Configure projects for major browsers */
34
- projects: [
35
- {
36
- name: 'Google Chrome',
37
- use: { ...devices['Desktop Chrome'], channel: 'chrome' },
38
- },
39
- // {
40
- // name: 'chromium',
41
- // use: { ...devices['Desktop Chrome'] },
42
- // },
43
- /* Test against mobile viewports. */
44
- // {
45
- // name: 'Mobile Chrome',
46
- // use: { ...devices['Pixel 5'] },
47
- // },
48
- // {
49
- // name: 'Mobile Safari',
50
- // use: { ...devices['iPhone 12'] },
51
- // },
52
-
53
- /* Test against branded browsers. */
54
- // {
55
- // name: 'Microsoft Edge',
56
- // use: { ...devices['Desktop Edge'], channel: 'msedge' },
57
- // },
58
- ],
59
-
60
- /* Run your local dev server before starting the tests */
61
- // webServer: {
62
- // command: 'npm run start',
63
- // url: 'http://127.0.0.1:3000',
64
- // reuseExistingServer: !process.env.CI,
65
- // },
66
- });