@rich-automation/lotto 0.1.6 → 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,6 +5,7 @@ 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
+ ENVIRONMENT_ALERT_CONFIRM: 'input[value="확인"][onclick="javascript:closepopupLayerAlert();"]',
8
9
  PURCHASE_TYPE_RANDOM_BTN: 'a[href="#divWay2Buy1"]#num2',
9
10
  PURCHASE_AMOUNT_SELECT: 'select#amoundApply',
10
11
  PURCHASE_AMOUNT_CONFIRM_BTN: 'input[value="확인"]#btnSelectNum',
@@ -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,6 +2,7 @@ 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
+ ENVIRONMENT_ALERT_CONFIRM: 'input[value="확인"][onclick="javascript:closepopupLayerAlert();"]',
5
6
  PURCHASE_TYPE_RANDOM_BTN: 'a[href="#divWay2Buy1"]#num2',
6
7
  PURCHASE_AMOUNT_SELECT: 'select#amoundApply',
7
8
  PURCHASE_AMOUNT_CONFIRM_BTN: 'input[value="확인"]#btnSelectNum',
@@ -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.6",
3
+ "version": "0.1.7",
4
4
  "description": "Lotto module",
5
5
  "publishConfig": {
6
6
  "access": "public",