codeceptjs 3.6.5-beta.3 → 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) {
@@ -159,6 +159,7 @@ module.exports = function (config) {
159
159
  // Ignore steps from BeforeSuite function
160
160
  if (scenarioFailed && config.disableScreenshotOnFail) return
161
161
  if (step.metaStep && step.metaStep.name === 'BeforeSuite') return
162
+ if (!step.test) return // Ignore steps from AfterSuite
162
163
 
163
164
  const fileName = `${pad.substring(0, pad.length - stepNum.toString().length) + stepNum.toString()}.png`
164
165
  if (step.status === 'failed') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "3.6.5-beta.3",
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,9 +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
1185
  class ExpectHelper {
1189
1186
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
1190
1187
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
@@ -1298,9 +1295,6 @@ declare namespace CodeceptJS {
1298
1295
  */
1299
1296
  // @ts-ignore
1300
1297
  // @ts-ignore
1301
- // @ts-ignore
1302
- // @ts-ignore
1303
- // @ts-ignore
1304
1298
  class ExpectHelper {
1305
1299
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
1306
1300
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): Promise<any>;
@@ -1974,9 +1968,6 @@ declare namespace CodeceptJS {
1974
1968
  */
1975
1969
  // @ts-ignore
1976
1970
  // @ts-ignore
1977
- // @ts-ignore
1978
- // @ts-ignore
1979
- // @ts-ignore
1980
1971
  type MockServerConfig = {
1981
1972
  port?: number;
1982
1973
  host?: string;
@@ -2103,9 +2094,6 @@ declare namespace CodeceptJS {
2103
2094
  */
2104
2095
  // @ts-ignore
2105
2096
  // @ts-ignore
2106
- // @ts-ignore
2107
- // @ts-ignore
2108
- // @ts-ignore
2109
2097
  class MockServer {
2110
2098
  /**
2111
2099
  * Start the mock server
@@ -3181,9 +3169,6 @@ declare namespace CodeceptJS {
3181
3169
  */
3182
3170
  // @ts-ignore
3183
3171
  // @ts-ignore
3184
- // @ts-ignore
3185
- // @ts-ignore
3186
- // @ts-ignore
3187
3172
  type PlaywrightConfig = {
3188
3173
  url?: string;
3189
3174
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -4777,13 +4762,6 @@ declare namespace CodeceptJS {
4777
4762
  * @param [sec = 1] - (optional) time in seconds to wait, 1 by default.
4778
4763
  */
4779
4764
  waitForEnabled(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<any>;
4780
- /**
4781
- * Waits for element to become disabled (by default waits for 1sec).
4782
- * Element can be located by CSS or XPath.
4783
- * @param locator - element located by CSS|XPath|strict locator.
4784
- * @param [sec = 1] - (optional) time in seconds to wait, 1 by default.
4785
- */
4786
- waitForDisabled(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<any>;
4787
4765
  /**
4788
4766
  * Waits for the specified value to be in value attribute.
4789
4767
  *
@@ -6562,9 +6540,6 @@ declare namespace CodeceptJS {
6562
6540
  */
6563
6541
  // @ts-ignore
6564
6542
  // @ts-ignore
6565
- // @ts-ignore
6566
- // @ts-ignore
6567
- // @ts-ignore
6568
6543
  type PuppeteerConfig = {
6569
6544
  url: string;
6570
6545
  basicAuth?: any;
@@ -8373,9 +8348,6 @@ declare namespace CodeceptJS {
8373
8348
  */
8374
8349
  // @ts-ignore
8375
8350
  // @ts-ignore
8376
- // @ts-ignore
8377
- // @ts-ignore
8378
- // @ts-ignore
8379
8351
  type RESTConfig = {
8380
8352
  endpoint?: string;
8381
8353
  prettyPrintJson?: boolean;
@@ -9496,9 +9468,6 @@ declare namespace CodeceptJS {
9496
9468
  */
9497
9469
  // @ts-ignore
9498
9470
  // @ts-ignore
9499
- // @ts-ignore
9500
- // @ts-ignore
9501
- // @ts-ignore
9502
9471
  type WebDriverConfig = {
9503
9472
  url: string;
9504
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,9 +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
1209
  class ExpectHelper {
1213
1210
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
1214
1211
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
@@ -1322,9 +1319,6 @@ declare namespace CodeceptJS {
1322
1319
  */
1323
1320
  // @ts-ignore
1324
1321
  // @ts-ignore
1325
- // @ts-ignore
1326
- // @ts-ignore
1327
- // @ts-ignore
1328
1322
  class ExpectHelper {
1329
1323
  expectEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
1330
1324
  expectNotEqual(actualValue: any, expectedValue: any, customErrorMsg?: any): void;
@@ -2001,9 +1995,6 @@ declare namespace CodeceptJS {
2001
1995
  */
2002
1996
  // @ts-ignore
2003
1997
  // @ts-ignore
2004
- // @ts-ignore
2005
- // @ts-ignore
2006
- // @ts-ignore
2007
1998
  type MockServerConfig = {
2008
1999
  port?: number;
2009
2000
  host?: string;
@@ -2130,9 +2121,6 @@ declare namespace CodeceptJS {
2130
2121
  */
2131
2122
  // @ts-ignore
2132
2123
  // @ts-ignore
2133
- // @ts-ignore
2134
- // @ts-ignore
2135
- // @ts-ignore
2136
2124
  class MockServer {
2137
2125
  /**
2138
2126
  * Start the mock server
@@ -3274,9 +3262,6 @@ declare namespace CodeceptJS {
3274
3262
  */
3275
3263
  // @ts-ignore
3276
3264
  // @ts-ignore
3277
- // @ts-ignore
3278
- // @ts-ignore
3279
- // @ts-ignore
3280
3265
  type PlaywrightConfig = {
3281
3266
  url?: string;
3282
3267
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -4929,14 +4914,6 @@ declare namespace CodeceptJS {
4929
4914
  * @returns automatically synchronized promise through #recorder
4930
4915
  */
4931
4916
  waitForEnabled(locator: CodeceptJS.LocatorOrString, sec?: number): void;
4932
- /**
4933
- * Waits for element to become disabled (by default waits for 1sec).
4934
- * Element can be located by CSS or XPath.
4935
- * @param locator - element located by CSS|XPath|strict locator.
4936
- * @param [sec = 1] - (optional) time in seconds to wait, 1 by default.
4937
- * @returns automatically synchronized promise through #recorder
4938
- */
4939
- waitForDisabled(locator: CodeceptJS.LocatorOrString, sec?: number): void;
4940
4917
  /**
4941
4918
  * Waits for the specified value to be in value attribute.
4942
4919
  *
@@ -6806,9 +6783,6 @@ declare namespace CodeceptJS {
6806
6783
  */
6807
6784
  // @ts-ignore
6808
6785
  // @ts-ignore
6809
- // @ts-ignore
6810
- // @ts-ignore
6811
- // @ts-ignore
6812
6786
  type PuppeteerConfig = {
6813
6787
  url: string;
6814
6788
  basicAuth?: any;
@@ -8753,9 +8727,6 @@ declare namespace CodeceptJS {
8753
8727
  */
8754
8728
  // @ts-ignore
8755
8729
  // @ts-ignore
8756
- // @ts-ignore
8757
- // @ts-ignore
8758
- // @ts-ignore
8759
8730
  type RESTConfig = {
8760
8731
  endpoint?: string;
8761
8732
  prettyPrintJson?: boolean;
@@ -9936,9 +9907,6 @@ declare namespace CodeceptJS {
9936
9907
  */
9937
9908
  // @ts-ignore
9938
9909
  // @ts-ignore
9939
- // @ts-ignore
9940
- // @ts-ignore
9941
- // @ts-ignore
9942
9910
  type WebDriverConfig = {
9943
9911
  url: string;
9944
9912
  browser: string;