codeceptjs 3.6.5-beta.4 → 3.6.5-beta.5

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/lib/helper/AI.js CHANGED
@@ -10,17 +10,21 @@ const { beautify } = require('../utils')
10
10
  const output = require('../output')
11
11
  const { registerVariable } = require('../pause')
12
12
 
13
+ const gtpRole = {
14
+ user: 'user',
15
+ }
16
+
13
17
  /**
14
18
  * AI Helper for CodeceptJS.
15
19
  *
16
20
  * This helper class provides integration with the AI GPT-3.5 or 4 language model for generating responses to questions or prompts within the context of web pages. It allows you to interact with the GPT-3.5 model to obtain intelligent responses based on HTML fragments or general prompts.
17
- * This helper should be enabled with any web helpers like Playwright or Puppeteer or WebDrvier to ensure the HTML context is available.
21
+ * This helper should be enabled with any web helpers like Playwright or Puppeteer or WebDriver to ensure the HTML context is available.
18
22
  *
19
23
  * Use it only in development mode. It is recommended to run it only inside pause() mode.
20
24
  *
21
25
  * ## Configuration
22
26
  *
23
- * This helper should be configured in codecept.json or codecept.conf.js
27
+ * This helper should be configured in codecept.conf.{js|ts}
24
28
  *
25
29
  * * `chunkSize`: (optional, default: 80000) - The maximum number of characters to send to the AI API at once. We split HTML fragments by 8000 chars to not exceed token limit. Increase this value if you use GPT-4.
26
30
  */
@@ -33,6 +37,7 @@ class AI extends Helper {
33
37
  chunkSize: 80000,
34
38
  }
35
39
  this.options = { ...this.options, ...config }
40
+ this.aiAssistant.enable(this.config)
36
41
  }
37
42
 
38
43
  _beforeSuite() {
@@ -68,8 +73,8 @@ class AI extends Helper {
68
73
 
69
74
  for (const chunk of htmlChunks) {
70
75
  const messages = [
71
- { role: 'user', content: prompt },
72
- { role: 'user', content: `Within this HTML: ${minifyHtml(chunk)}` },
76
+ { role: gtpRole.user, content: prompt },
77
+ { role: gtpRole.user, content: `Within this HTML: ${minifyHtml(chunk)}` },
73
78
  ]
74
79
 
75
80
  if (htmlChunks.length > 1)
@@ -104,8 +109,8 @@ class AI extends Helper {
104
109
  const html = await this.helper.grabHTMLFrom(locator)
105
110
 
106
111
  const messages = [
107
- { role: 'user', content: prompt },
108
- { role: 'user', content: `Within this HTML: ${minifyHtml(html)}` },
112
+ { role: gtpRole.user, content: prompt },
113
+ { role: gtpRole.user, content: `Within this HTML: ${minifyHtml(html)}` },
109
114
  ]
110
115
 
111
116
  const response = await this._processAIRequest(messages)
@@ -121,7 +126,7 @@ class AI extends Helper {
121
126
  * @returns {Promise<string>} - A Promise that resolves to the generated response from the GPT model.
122
127
  */
123
128
  async askGptGeneralPrompt(prompt) {
124
- const messages = [{ role: 'user', content: prompt }]
129
+ const messages = [{ role: gtpRole.user, content: prompt }]
125
130
 
126
131
  const response = await this._processAIRequest(messages)
127
132
 
@@ -156,40 +161,45 @@ class AI extends Helper {
156
161
  * @returns {Promise<Object>} A promise that resolves to the requested page object.
157
162
  */
158
163
  async askForPageObject(pageName, extraPrompt = null, locator = null) {
159
- const html = locator ? await this.helper.grabHTMLFrom(locator) : await this.helper.grabSource()
160
-
161
164
  const spinner = ora(' Processing AI request...').start()
162
- await this.aiAssistant.setHtmlContext(html)
163
- const response = await this.aiAssistant.generatePageObject(extraPrompt, locator)
164
- spinner.stop()
165
165
 
166
- if (!response[0]) {
167
- output.error('No response from AI')
168
- return ''
169
- }
166
+ try {
167
+ const html = locator ? await this.helper.grabHTMLFrom(locator) : await this.helper.grabSource()
168
+ await this.aiAssistant.setHtmlContext(html)
169
+ const response = await this.aiAssistant.generatePageObject(extraPrompt, locator)
170
+ spinner.stop()
171
+
172
+ if (!response[0]) {
173
+ output.error('No response from AI')
174
+ return ''
175
+ }
170
176
 
171
- const code = beautify(response[0])
177
+ const code = beautify(response[0])
172
178
 
173
- output.print('----- Generated PageObject ----')
174
- output.print(code)
175
- output.print('-------------------------------')
179
+ output.print('----- Generated PageObject ----')
180
+ output.print(code)
181
+ output.print('-------------------------------')
176
182
 
177
- const fileName = path.join(output_dir, `${pageName}Page-${Date.now()}.js`)
183
+ const fileName = path.join(output_dir, `${pageName}Page-${Date.now()}.js`)
178
184
 
179
- output.print(output.styles.bold(`Page object for ${pageName} is saved to ${output.styles.bold(fileName)}`))
180
- fs.writeFileSync(fileName, code)
185
+ output.print(output.styles.bold(`Page object for ${pageName} is saved to ${output.styles.bold(fileName)}`))
186
+ fs.writeFileSync(fileName, code)
181
187
 
182
- try {
183
- registerVariable('page', require(fileName))
184
- output.success('Page object registered for this session as `page` variable')
185
- output.print('Use `=>page.methodName()` in shell to run methods of page object')
186
- output.print('Use `click(page.locatorName)` to check locators of page object')
187
- } catch (err) {
188
- output.error('Error while registering page object')
189
- output.error(err.message)
190
- }
188
+ try {
189
+ registerVariable('page', require(fileName))
190
+ output.success('Page object registered for this session as `page` variable')
191
+ output.print('Use `=>page.methodName()` in shell to run methods of page object')
192
+ output.print('Use `click(page.locatorName)` to check locators of page object')
193
+ } catch (err) {
194
+ output.error('Error while registering page object')
195
+ output.error(err.message)
196
+ }
191
197
 
192
- return code
198
+ return code
199
+ } catch (e) {
200
+ spinner.stop()
201
+ throw Error(`Something went wrong! ${e.message}`)
202
+ }
193
203
  }
194
204
 
195
205
  async _processAIRequest(messages) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "3.6.5-beta.4",
3
+ "version": "3.6.5-beta.5",
4
4
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
5
5
  "keywords": [
6
6
  "acceptance",
@@ -90,7 +90,7 @@
90
90
  "cross-spawn": "7.0.3",
91
91
  "css-to-xpath": "0.1.0",
92
92
  "csstoxpath": "1.6.0",
93
- "devtools": "8.38.2",
93
+ "devtools": "8.39.0",
94
94
  "envinfo": "7.11.1",
95
95
  "escape-string-regexp": "4.0.0",
96
96
  "figures": "3.2.0",
@@ -104,7 +104,7 @@
104
104
  "lodash.clonedeep": "4.5.0",
105
105
  "lodash.merge": "4.6.2",
106
106
  "mkdirp": "1.0.4",
107
- "mocha": "10.4.0",
107
+ "mocha": "10.5.2",
108
108
  "monocart-coverage-reports": "2.8.3",
109
109
  "ms": "2.1.3",
110
110
  "ora-classic": "5.4.2",
@@ -117,17 +117,17 @@
117
117
  "uuid": "9.0"
118
118
  },
119
119
  "optionalDependencies": {
120
- "@codeceptjs/detox-helper": "1.0.7"
120
+ "@codeceptjs/detox-helper": "1.0.8"
121
121
  },
122
122
  "devDependencies": {
123
123
  "@codeceptjs/mock-request": "0.3.1",
124
124
  "@faker-js/faker": "7.6.0",
125
125
  "@pollyjs/adapter-puppeteer": "6.0.6",
126
126
  "@pollyjs/core": "5.1.0",
127
- "@types/chai": "4.3.12",
127
+ "@types/chai": "4.3.16",
128
128
  "@types/inquirer": "9.0.3",
129
129
  "@types/node": "20.11.30",
130
- "@wdio/sauce-service": "8.35.1",
130
+ "@wdio/sauce-service": "8.39.0",
131
131
  "@wdio/selenium-standalone-service": "8.3.2",
132
132
  "@wdio/utils": "8.38.2",
133
133
  "@xmldom/xmldom": "0.8.10",
@@ -143,22 +143,22 @@
143
143
  "eslint-plugin-mocha": "10.4.3",
144
144
  "expect": "29.7.0",
145
145
  "express": "4.19.2",
146
- "graphql": "14.6.0",
146
+ "graphql": "16.9.0",
147
147
  "husky": "8.0.3",
148
148
  "inquirer-test": "2.0.1",
149
149
  "jsdoc": "4.0.3",
150
150
  "jsdoc-typeof-plugin": "1.0.0",
151
151
  "json-server": "0.10.1",
152
- "playwright": "1.44.1",
152
+ "playwright": "1.45.0",
153
153
  "prettier": "^3.3.2",
154
- "puppeteer": "22.10.0",
154
+ "puppeteer": "22.12.1",
155
155
  "qrcode-terminal": "0.12.0",
156
156
  "rosie": "2.1.1",
157
157
  "runok": "0.9.3",
158
158
  "sinon": "18.0.0",
159
159
  "sinon-chai": "3.7.0",
160
160
  "testcafe": "3.5.0",
161
- "ts-morph": "21.0.1",
161
+ "ts-morph": "23.0.0",
162
162
  "ts-node": "10.9.2",
163
163
  "tsd": "^0.31.0",
164
164
  "tsd-jsdoc": "2.5.0",
@@ -3,13 +3,13 @@ declare namespace CodeceptJS {
3
3
  * AI Helper for CodeceptJS.
4
4
  *
5
5
  * This helper class provides integration with the AI GPT-3.5 or 4 language model for generating responses to questions or prompts within the context of web pages. It allows you to interact with the GPT-3.5 model to obtain intelligent responses based on HTML fragments or general prompts.
6
- * This helper should be enabled with any web helpers like Playwright or Puppeteer or WebDrvier to ensure the HTML context is available.
6
+ * This helper should be enabled with any web helpers like Playwright or Puppeteer or WebDriver to ensure the HTML context is available.
7
7
  *
8
8
  * Use it only in development mode. It is recommended to run it only inside pause() mode.
9
9
  *
10
10
  * ## Configuration
11
11
  *
12
- * This helper should be configured in codecept.json or codecept.conf.js
12
+ * This helper should be configured in codecept.conf.{js|ts}
13
13
  *
14
14
  * * `chunkSize`: (optional, default: 80000) - The maximum number of characters to send to the AI API at once. We split HTML fragments by 8000 chars to not exceed token limit. Increase this value if you use GPT-4.
15
15
  */
@@ -1182,10 +1182,6 @@ declare namespace CodeceptJS {
1182
1182
  */
1183
1183
  // @ts-ignore
1184
1184
  // @ts-ignore
1185
- // @ts-ignore
1186
- // @ts-ignore
1187
- // @ts-ignore
1188
- // @ts-ignore
1189
1185
  class ExpectHelper {
1190
1186
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
1191
1187
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
@@ -1299,10 +1295,6 @@ declare namespace CodeceptJS {
1299
1295
  */
1300
1296
  // @ts-ignore
1301
1297
  // @ts-ignore
1302
- // @ts-ignore
1303
- // @ts-ignore
1304
- // @ts-ignore
1305
- // @ts-ignore
1306
1298
  class ExpectHelper {
1307
1299
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
1308
1300
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
@@ -1976,10 +1968,6 @@ declare namespace CodeceptJS {
1976
1968
  */
1977
1969
  // @ts-ignore
1978
1970
  // @ts-ignore
1979
- // @ts-ignore
1980
- // @ts-ignore
1981
- // @ts-ignore
1982
- // @ts-ignore
1983
1971
  type MockServerConfig = {
1984
1972
  port?: number;
1985
1973
  host?: string;
@@ -2106,10 +2094,6 @@ declare namespace CodeceptJS {
2106
2094
  */
2107
2095
  // @ts-ignore
2108
2096
  // @ts-ignore
2109
- // @ts-ignore
2110
- // @ts-ignore
2111
- // @ts-ignore
2112
- // @ts-ignore
2113
2097
  class MockServer {
2114
2098
  /**
2115
2099
  * Start the mock server
@@ -3185,10 +3169,6 @@ declare namespace CodeceptJS {
3185
3169
  */
3186
3170
  // @ts-ignore
3187
3171
  // @ts-ignore
3188
- // @ts-ignore
3189
- // @ts-ignore
3190
- // @ts-ignore
3191
- // @ts-ignore
3192
3172
  type PlaywrightConfig = {
3193
3173
  url?: string;
3194
3174
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -4782,13 +4762,6 @@ declare namespace CodeceptJS {
4782
4762
  * @param [sec = 1] - (optional) time in seconds to wait, 1 by default.
4783
4763
  */
4784
4764
  waitForEnabled(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<any>;
4785
- /**
4786
- * Waits for element to become disabled (by default waits for 1sec).
4787
- * Element can be located by CSS or XPath.
4788
- * @param locator - element located by CSS|XPath|strict locator.
4789
- * @param [sec = 1] - (optional) time in seconds to wait, 1 by default.
4790
- */
4791
- waitForDisabled(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<any>;
4792
4765
  /**
4793
4766
  * Waits for the specified value to be in value attribute.
4794
4767
  *
@@ -6567,10 +6540,6 @@ declare namespace CodeceptJS {
6567
6540
  */
6568
6541
  // @ts-ignore
6569
6542
  // @ts-ignore
6570
- // @ts-ignore
6571
- // @ts-ignore
6572
- // @ts-ignore
6573
- // @ts-ignore
6574
6543
  type PuppeteerConfig = {
6575
6544
  url: string;
6576
6545
  basicAuth?: any;
@@ -8379,10 +8348,6 @@ declare namespace CodeceptJS {
8379
8348
  */
8380
8349
  // @ts-ignore
8381
8350
  // @ts-ignore
8382
- // @ts-ignore
8383
- // @ts-ignore
8384
- // @ts-ignore
8385
- // @ts-ignore
8386
8351
  type RESTConfig = {
8387
8352
  endpoint?: string;
8388
8353
  prettyPrintJson?: boolean;
@@ -9503,10 +9468,6 @@ declare namespace CodeceptJS {
9503
9468
  */
9504
9469
  // @ts-ignore
9505
9470
  // @ts-ignore
9506
- // @ts-ignore
9507
- // @ts-ignore
9508
- // @ts-ignore
9509
- // @ts-ignore
9510
9471
  type WebDriverConfig = {
9511
9472
  url: string;
9512
9473
  browser: string;
@@ -3,13 +3,13 @@ declare namespace CodeceptJS {
3
3
  * AI Helper for CodeceptJS.
4
4
  *
5
5
  * This helper class provides integration with the AI GPT-3.5 or 4 language model for generating responses to questions or prompts within the context of web pages. It allows you to interact with the GPT-3.5 model to obtain intelligent responses based on HTML fragments or general prompts.
6
- * This helper should be enabled with any web helpers like Playwright or Puppeteer or WebDrvier to ensure the HTML context is available.
6
+ * This helper should be enabled with any web helpers like Playwright or Puppeteer or WebDriver to ensure the HTML context is available.
7
7
  *
8
8
  * Use it only in development mode. It is recommended to run it only inside pause() mode.
9
9
  *
10
10
  * ## Configuration
11
11
  *
12
- * This helper should be configured in codecept.json or codecept.conf.js
12
+ * This helper should be configured in codecept.conf.{js|ts}
13
13
  *
14
14
  * * `chunkSize`: (optional, default: 80000) - The maximum number of characters to send to the AI API at once. We split HTML fragments by 8000 chars to not exceed token limit. Increase this value if you use GPT-4.
15
15
  */
@@ -1206,10 +1206,6 @@ declare namespace CodeceptJS {
1206
1206
  */
1207
1207
  // @ts-ignore
1208
1208
  // @ts-ignore
1209
- // @ts-ignore
1210
- // @ts-ignore
1211
- // @ts-ignore
1212
- // @ts-ignore
1213
1209
  class ExpectHelper {
1214
1210
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
1215
1211
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
@@ -1323,10 +1319,6 @@ declare namespace CodeceptJS {
1323
1319
  */
1324
1320
  // @ts-ignore
1325
1321
  // @ts-ignore
1326
- // @ts-ignore
1327
- // @ts-ignore
1328
- // @ts-ignore
1329
- // @ts-ignore
1330
1322
  class ExpectHelper {
1331
1323
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
1332
1324
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
@@ -2003,10 +1995,6 @@ declare namespace CodeceptJS {
2003
1995
  */
2004
1996
  // @ts-ignore
2005
1997
  // @ts-ignore
2006
- // @ts-ignore
2007
- // @ts-ignore
2008
- // @ts-ignore
2009
- // @ts-ignore
2010
1998
  type MockServerConfig = {
2011
1999
  port?: number;
2012
2000
  host?: string;
@@ -2133,10 +2121,6 @@ declare namespace CodeceptJS {
2133
2121
  */
2134
2122
  // @ts-ignore
2135
2123
  // @ts-ignore
2136
- // @ts-ignore
2137
- // @ts-ignore
2138
- // @ts-ignore
2139
- // @ts-ignore
2140
2124
  class MockServer {
2141
2125
  /**
2142
2126
  * Start the mock server
@@ -3278,10 +3262,6 @@ declare namespace CodeceptJS {
3278
3262
  */
3279
3263
  // @ts-ignore
3280
3264
  // @ts-ignore
3281
- // @ts-ignore
3282
- // @ts-ignore
3283
- // @ts-ignore
3284
- // @ts-ignore
3285
3265
  type PlaywrightConfig = {
3286
3266
  url?: string;
3287
3267
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -4934,14 +4914,6 @@ declare namespace CodeceptJS {
4934
4914
  * @returns automatically synchronized promise through #recorder
4935
4915
  */
4936
4916
  waitForEnabled(locator: CodeceptJS.LocatorOrString, sec?: number): void;
4937
- /**
4938
- * Waits for element to become disabled (by default waits for 1sec).
4939
- * Element can be located by CSS or XPath.
4940
- * @param locator - element located by CSS|XPath|strict locator.
4941
- * @param [sec = 1] - (optional) time in seconds to wait, 1 by default.
4942
- * @returns automatically synchronized promise through #recorder
4943
- */
4944
- waitForDisabled(locator: CodeceptJS.LocatorOrString, sec?: number): void;
4945
4917
  /**
4946
4918
  * Waits for the specified value to be in value attribute.
4947
4919
  *
@@ -6811,10 +6783,6 @@ declare namespace CodeceptJS {
6811
6783
  */
6812
6784
  // @ts-ignore
6813
6785
  // @ts-ignore
6814
- // @ts-ignore
6815
- // @ts-ignore
6816
- // @ts-ignore
6817
- // @ts-ignore
6818
6786
  type PuppeteerConfig = {
6819
6787
  url: string;
6820
6788
  basicAuth?: any;
@@ -8759,10 +8727,6 @@ declare namespace CodeceptJS {
8759
8727
  */
8760
8728
  // @ts-ignore
8761
8729
  // @ts-ignore
8762
- // @ts-ignore
8763
- // @ts-ignore
8764
- // @ts-ignore
8765
- // @ts-ignore
8766
8730
  type RESTConfig = {
8767
8731
  endpoint?: string;
8768
8732
  prettyPrintJson?: boolean;
@@ -9943,10 +9907,6 @@ declare namespace CodeceptJS {
9943
9907
  */
9944
9908
  // @ts-ignore
9945
9909
  // @ts-ignore
9946
- // @ts-ignore
9947
- // @ts-ignore
9948
- // @ts-ignore
9949
- // @ts-ignore
9950
9910
  type WebDriverConfig = {
9951
9911
  url: string;
9952
9912
  browser: string;