codeceptjs 4.0.0-beta.3 → 4.0.0-beta.4

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.
@@ -72,7 +72,6 @@ const webRoot = 'body'
72
72
  * @prop {object} [timeouts] [WebDriver timeouts](http://webdriver.io/docs/timeouts.html) defined as hash.
73
73
  * @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
74
74
  * @prop {string} [logLevel=silent] - level of logging verbosity. Default: silent. Options: trace | debug | info | warn | error | silent. More info: https://webdriver.io/docs/configuration/#loglevel
75
- * @prop {boolean} [devtoolsProtocol=false] - enable devtools protocol. Default: false. More info: https://webdriver.io/docs/automationProtocols/#devtools-protocol.
76
75
  */
77
76
  const config = {}
78
77
 
@@ -180,7 +179,6 @@ const config = {}
180
179
  * WebDriver : {
181
180
  * url: "http://localhost",
182
181
  * browser: "chrome",
183
- * devtoolsProtocol: true,
184
182
  * desiredCapabilities: {
185
183
  * chromeOptions: {
186
184
  * args: [ "--headless", "--disable-gpu", "--no-sandbox" ]
@@ -614,11 +612,6 @@ class WebDriver extends Helper {
614
612
  delete this.options.capabilities.hostname
615
613
  delete this.options.capabilities.port
616
614
  delete this.options.capabilities.path
617
- if (this.options.devtoolsProtocol) {
618
- if (!['chrome', 'chromium'].includes(this.options.browser.toLowerCase()))
619
- throw Error('The devtools protocol is only working with Chrome or Chromium')
620
- this.options.automationProtocol = 'devtools'
621
- }
622
615
  this.browser = await webdriverio.remote(this.options)
623
616
  }
624
617
  } catch (err) {
@@ -649,11 +642,6 @@ class WebDriver extends Helper {
649
642
  this.browser.capabilities.platformName = this.browser.capabilities.platformName.toLowerCase()
650
643
  }
651
644
 
652
- if (this.options.automationProtocol) {
653
- this.puppeteerBrowser = await this.browser.getPuppeteer()
654
- this.page = (await this.puppeteerBrowser.pages())[0]
655
- }
656
-
657
645
  return this.browser
658
646
  }
659
647
 
@@ -1143,10 +1131,6 @@ class WebDriver extends Helper {
1143
1131
  assertElementExists(res, field, 'Field')
1144
1132
  const elem = usingFirstElement(res)
1145
1133
  highlightActiveElement.call(this, elem)
1146
- if (this.options.automationProtocol) {
1147
- const curentValue = await elem.getValue()
1148
- return elem.setValue(curentValue + value.toString())
1149
- }
1150
1134
  return elem.addValue(value.toString())
1151
1135
  }
1152
1136
 
@@ -1159,9 +1143,6 @@ class WebDriver extends Helper {
1159
1143
  assertElementExists(res, field, 'Field')
1160
1144
  const elem = usingFirstElement(res)
1161
1145
  highlightActiveElement.call(this, elem)
1162
- if (this.options.automationProtocol) {
1163
- return elem.setValue('')
1164
- }
1165
1146
  return elem.clearValue(getElementId(elem))
1166
1147
  }
1167
1148
 
@@ -1231,7 +1212,7 @@ class WebDriver extends Helper {
1231
1212
  const el = usingFirstElement(res)
1232
1213
 
1233
1214
  // Remote Upload (when running Selenium Server)
1234
- if (this.options.remoteFileUpload && !this.options.automationProtocol) {
1215
+ if (this.options.remoteFileUpload) {
1235
1216
  try {
1236
1217
  this.debugSection('File', 'Uploading file to remote server')
1237
1218
  file = await this.browser.uploadFile(file)
@@ -1793,7 +1774,7 @@ class WebDriver extends Helper {
1793
1774
  if (this.browser.isMobile && !this.browser.isW3C) return this.browser.touchScroll(offsetX, offsetY, elementId)
1794
1775
  const location = await elem.getLocation()
1795
1776
  assertElementExists(location, locator, 'Failed to receive', 'location')
1796
- /* eslint-disable prefer-arrow-callback */
1777
+
1797
1778
  return this.browser.execute(
1798
1779
  function (x, y) {
1799
1780
  return window.scrollTo(x, y)
@@ -1801,12 +1782,10 @@ class WebDriver extends Helper {
1801
1782
  location.x + offsetX,
1802
1783
  location.y + offsetY,
1803
1784
  )
1804
- /* eslint-enable */
1805
1785
  }
1806
1786
 
1807
1787
  if (this.browser.isMobile && !this.browser.isW3C) return this.browser.touchScroll(locator, offsetX, offsetY)
1808
1788
 
1809
- /* eslint-disable prefer-arrow-callback, comma-dangle */
1810
1789
  return this.browser.execute(
1811
1790
  function (x, y) {
1812
1791
  return window.scrollTo(x, y)
@@ -1814,7 +1793,6 @@ class WebDriver extends Helper {
1814
1793
  offsetX,
1815
1794
  offsetY,
1816
1795
  )
1817
- /* eslint-enable */
1818
1796
  }
1819
1797
 
1820
1798
  /**
@@ -1873,7 +1851,6 @@ class WebDriver extends Helper {
1873
1851
  return this.browser.saveScreenshot(outputFile)
1874
1852
  }
1875
1853
 
1876
- /* eslint-disable prefer-arrow-callback, comma-dangle, prefer-const */
1877
1854
  const originalWindowSize = await this.browser.getWindowSize()
1878
1855
 
1879
1856
  let { width, height } = await this.browser
@@ -1886,7 +1863,6 @@ class WebDriver extends Helper {
1886
1863
  .then((res) => res)
1887
1864
 
1888
1865
  if (height < 100) height = 500 // errors for very small height
1889
- /* eslint-enable */
1890
1866
 
1891
1867
  await this.browser.setWindowSize(width, height)
1892
1868
  this.debug(`Screenshot has been saved to ${outputFile}, size: ${width}x${height}`)
@@ -2593,9 +2569,6 @@ class WebDriver extends Helper {
2593
2569
  async switchTo(locator) {
2594
2570
  this.browser.isInsideFrame = true
2595
2571
  if (Number.isInteger(locator)) {
2596
- if (this.options.automationProtocol) {
2597
- return this.browser.switchToFrame(locator + 1)
2598
- }
2599
2572
  return this.browser.switchToFrame(locator)
2600
2573
  }
2601
2574
  if (!locator) {
@@ -2695,11 +2668,10 @@ class WebDriver extends Helper {
2695
2668
  */
2696
2669
  scrollPageToTop() {
2697
2670
  const client = this.browser
2698
- /* eslint-disable prefer-arrow-callback */
2671
+
2699
2672
  return client.execute(function () {
2700
2673
  window.scrollTo(0, 0)
2701
2674
  })
2702
- /* eslint-enable */
2703
2675
  }
2704
2676
 
2705
2677
  /**
@@ -2707,7 +2679,7 @@ class WebDriver extends Helper {
2707
2679
  */
2708
2680
  scrollPageToBottom() {
2709
2681
  const client = this.browser
2710
- /* eslint-disable prefer-arrow-callback, comma-dangle */
2682
+
2711
2683
  return client.execute(function () {
2712
2684
  const body = document.body
2713
2685
  const html = document.documentElement
@@ -2716,60 +2688,20 @@ class WebDriver extends Helper {
2716
2688
  Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight),
2717
2689
  )
2718
2690
  })
2719
- /* eslint-enable */
2720
2691
  }
2721
2692
 
2722
2693
  /**
2723
2694
  * {{> grabPageScrollPosition }}
2724
2695
  */
2725
2696
  async grabPageScrollPosition() {
2726
- /* eslint-disable comma-dangle */
2727
2697
  function getScrollPosition() {
2728
2698
  return {
2729
2699
  x: window.pageXOffset,
2730
2700
  y: window.pageYOffset,
2731
2701
  }
2732
2702
  }
2733
- /* eslint-enable comma-dangle */
2734
- return this.executeScript(getScrollPosition)
2735
- }
2736
-
2737
- /**
2738
- * This method is **deprecated**.
2739
- *
2740
- *
2741
- * {{> setGeoLocation }}
2742
- */
2743
- async setGeoLocation(latitude, longitude) {
2744
- if (!this.options.automationProtocol) {
2745
- console.log(`setGeoLocation deprecated:
2746
- * This command is deprecated due to using deprecated JSON Wire Protocol command. More info: https://webdriver.io/docs/api/jsonwp/#setgeolocation
2747
- * Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration`)
2748
- return
2749
- }
2750
- this.geoLocation = { latitude, longitude }
2751
2703
 
2752
- await this.browser.call(async () => {
2753
- const pages = await this.puppeteerBrowser.pages()
2754
- await pages[0].setGeolocation({ latitude, longitude })
2755
- })
2756
- }
2757
-
2758
- /**
2759
- * This method is **deprecated**.
2760
- *
2761
- * {{> grabGeoLocation }}
2762
- *
2763
- */
2764
- async grabGeoLocation() {
2765
- if (!this.options.automationProtocol) {
2766
- console.log(`grabGeoLocation deprecated:
2767
- * This command is deprecated due to using deprecated JSON Wire Protocol command. More info: https://webdriver.io/docs/api/jsonwp/#getgeolocation
2768
- * Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration`)
2769
- return
2770
- }
2771
- if (!this.geoLocation) return 'No GeoLocation is set!'
2772
- return this.geoLocation
2704
+ return this.executeScript(getScrollPosition)
2773
2705
  }
2774
2706
 
2775
2707
  /**
@@ -2793,7 +2725,7 @@ class WebDriver extends Helper {
2793
2725
  * @param {*} caps
2794
2726
  * @param {*} fn
2795
2727
  */
2796
- /* eslint-disable */
2728
+
2797
2729
  runOnIOS(caps, fn) {}
2798
2730
 
2799
2731
  /**
@@ -2802,135 +2734,13 @@ class WebDriver extends Helper {
2802
2734
  * @param {*} fn
2803
2735
  */
2804
2736
  runOnAndroid(caps, fn) {}
2805
- /* eslint-enable */
2806
2737
 
2807
2738
  /**
2808
2739
  * Placeholder for ~ locator only test case write once run on both Appium and WebDriver.
2809
2740
  */
2810
- runInWeb(fn) {
2741
+ async runInWeb(fn) {
2811
2742
  return fn()
2812
2743
  }
2813
-
2814
- /**
2815
- *
2816
- * _Note:_ Only works when devtoolsProtocol is enabled.
2817
- *
2818
- * {{> flushNetworkTraffics }}
2819
- */
2820
- flushNetworkTraffics() {
2821
- if (!this.options.automationProtocol) {
2822
- console.log(
2823
- '* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
2824
- )
2825
- return
2826
- }
2827
- this.requests = []
2828
- }
2829
-
2830
- /**
2831
- *
2832
- * _Note:_ Only works when devtoolsProtocol is enabled.
2833
- *
2834
- * {{> stopRecordingTraffic }}
2835
- */
2836
- stopRecordingTraffic() {
2837
- if (!this.options.automationProtocol) {
2838
- console.log(
2839
- '* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
2840
- )
2841
- return
2842
- }
2843
- this.page.removeAllListeners('request')
2844
- this.recording = false
2845
- }
2846
-
2847
- /**
2848
- *
2849
- * _Note:_ Only works when devtoolsProtocol is enabled.
2850
- *
2851
- * {{> startRecordingTraffic }}
2852
- *
2853
- */
2854
- async startRecordingTraffic() {
2855
- if (!this.options.automationProtocol) {
2856
- console.log(
2857
- '* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
2858
- )
2859
- return
2860
- }
2861
- this.flushNetworkTraffics()
2862
- this.recording = true
2863
- this.recordedAtLeastOnce = true
2864
-
2865
- await this.page.setRequestInterception(true)
2866
-
2867
- this.page.on('request', (request) => {
2868
- const information = {
2869
- url: request.url(),
2870
- method: request.method(),
2871
- requestHeaders: request.headers(),
2872
- requestPostData: request.postData(),
2873
- response: request.response(),
2874
- }
2875
-
2876
- this.debugSection('REQUEST: ', JSON.stringify(information))
2877
-
2878
- if (typeof information.requestPostData === 'object') {
2879
- information.requestPostData = JSON.parse(information.requestPostData)
2880
- }
2881
- request.continue()
2882
- this.requests.push(information)
2883
- })
2884
- }
2885
-
2886
- /**
2887
- *
2888
- * _Note:_ Only works when devtoolsProtocol is enabled.
2889
- *
2890
- * {{> grabRecordedNetworkTraffics }}
2891
- */
2892
- async grabRecordedNetworkTraffics() {
2893
- if (!this.options.automationProtocol) {
2894
- console.log(
2895
- '* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
2896
- )
2897
- return
2898
- }
2899
- return grabRecordedNetworkTraffics.call(this)
2900
- }
2901
-
2902
- /**
2903
- *
2904
- * _Note:_ Only works when devtoolsProtocol is enabled.
2905
- *
2906
- * {{> seeTraffic }}
2907
- */
2908
- async seeTraffic({ name, url, parameters, requestPostData, timeout = 10 }) {
2909
- if (!this.options.automationProtocol) {
2910
- console.log(
2911
- '* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
2912
- )
2913
- return
2914
- }
2915
- await seeTraffic.call(this, ...arguments)
2916
- }
2917
-
2918
- /**
2919
- *
2920
- * _Note:_ Only works when devtoolsProtocol is enabled.
2921
- *
2922
- * {{> dontSeeTraffic }}
2923
- *
2924
- */
2925
- dontSeeTraffic({ name, url }) {
2926
- if (!this.options.automationProtocol) {
2927
- console.log(
2928
- '* Switch to devtools protocol to use this command by setting devtoolsProtocol: true in the configuration',
2929
- )
2930
- return
2931
- }
2932
- dontSeeTraffic.call(this, ...arguments)
2933
- }
2934
2744
  }
2935
2745
 
2936
2746
  async function proceedSee(assertType, text, context, strict = false) {
@@ -3213,7 +3023,6 @@ function getElementId(el) {
3213
3023
  // List of known key values to unicode code points
3214
3024
  // https://www.w3.org/TR/webdriver/#keyboard-actions
3215
3025
  const keyUnicodeMap = {
3216
- /* eslint-disable quote-props */
3217
3026
  Unidentified: '\uE000',
3218
3027
  Cancel: '\uE001',
3219
3028
  Clear: '\uE005',
@@ -3328,7 +3137,6 @@ const keyUnicodeMap = {
3328
3137
  Semicolon: '\uE018', // ';' alias
3329
3138
  Slash: '/', // '/' alias
3330
3139
  ZenkakuHankaku: '\uE040',
3331
- /* eslint-enable quote-props */
3332
3140
  }
3333
3141
 
3334
3142
  function convertKeyToRawKey(key) {
@@ -2,7 +2,7 @@ module.exports.createValueEngine = () => {
2
2
  return {
3
3
  // Creates a selector that matches given target when queried at the root.
4
4
  // Can return undefined if unable to create one.
5
- // eslint-disable-next-line no-unused-vars
5
+
6
6
  create(root, target) {
7
7
  return null;
8
8
  },
@@ -29,7 +29,7 @@ module.exports.createDisabledEngine = () => {
29
29
  return {
30
30
  // Creates a selector that matches given target when queried at the root.
31
31
  // Can return undefined if unable to create one.
32
- // eslint-disable-next-line no-unused-vars
32
+
33
33
  create(root, target) {
34
34
  return null;
35
35
  },
@@ -34,7 +34,7 @@ const extractQueryObjects = (queryString) => {
34
34
  queryParameters.forEach((queryParameter) => {
35
35
  const keyValue = queryParameter.split('=');
36
36
  const queryObject = {};
37
- // eslint-disable-next-line prefer-destructuring
37
+
38
38
  queryObject.name = keyValue[0];
39
39
  queryObject.value = decodeURIComponent(keyValue[1]);
40
40
  queryObjects.push(queryObject);
@@ -48,7 +48,7 @@ function getFuncBody(func) {
48
48
  const arrowIndex = fnStr.indexOf('=>');
49
49
  if (arrowIndex >= 0) {
50
50
  fnStr = fnStr.slice(arrowIndex + 2);
51
- // eslint-disable-next-line no-new-func
51
+
52
52
  // eslint-disable-next-line no-eval
53
53
  return eval(`() => ${fnStr}`);
54
54
  }
package/lib/locator.js CHANGED
@@ -389,7 +389,7 @@ class Locator {
389
389
  }
390
390
 
391
391
  /**
392
- * @param {CodeceptJS.LocatorOrString} locator
392
+ * @param {CodeceptJS.LocatorOrString} [locator]
393
393
  * @returns {Locator}
394
394
  */
395
395
  Locator.build = (locator) => {
package/lib/output.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const colors = require('chalk');
2
2
  const figures = require('figures');
3
+ const { maskSensitiveData } = require('invisi-data')
3
4
 
4
5
  const styles = {
5
6
  error: colors.bgRed.white.bold,
@@ -57,8 +58,9 @@ module.exports = {
57
58
  * @param {string} msg
58
59
  */
59
60
  debug(msg) {
61
+ const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
60
62
  if (outputLevel >= 2) {
61
- print(' '.repeat(this.stepShift), styles.debug(`${figures.pointerSmall} ${msg}`));
63
+ print(' '.repeat(this.stepShift), styles.debug(`${figures.pointerSmall} ${_msg}`));
62
64
  }
63
65
  },
64
66
 
@@ -67,8 +69,9 @@ module.exports = {
67
69
  * @param {string} msg
68
70
  */
69
71
  log(msg) {
72
+ const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
70
73
  if (outputLevel >= 3) {
71
- print(' '.repeat(this.stepShift), styles.log(truncate(` ${msg}`, this.spaceShift)));
74
+ print(' '.repeat(this.stepShift), styles.log(truncate(` ${_msg}`, this.spaceShift)));
72
75
  }
73
76
  },
74
77
 
@@ -117,10 +120,11 @@ module.exports = {
117
120
  stepLine = colors.green(truncate(stepLine, this.spaceShift));
118
121
  }
119
122
  if (step.comment) {
120
- stepLine += colors.grey(step.comment.split('\n').join('\n' + ' '.repeat(4))); // eslint-disable-line
123
+ stepLine += colors.grey(step.comment.split('\n').join('\n' + ' '.repeat(4)));
121
124
  }
122
125
 
123
- print(' '.repeat(this.stepShift), truncate(stepLine, this.spaceShift));
126
+ const _stepLine = isMaskedData() ? maskSensitiveData(stepLine) : stepLine
127
+ print(' '.repeat(this.stepShift), truncate(_stepLine, this.spaceShift));
124
128
  },
125
129
 
126
130
  /** @namespace */
@@ -167,10 +171,10 @@ module.exports = {
167
171
  scenario: {
168
172
  /**
169
173
  * @param {Mocha.Test} test
170
- */
171
- /* eslint-disable */
174
+ */
175
+
172
176
  started(test) {},
173
- /* eslint-enable */
177
+
174
178
  /**
175
179
  * @param {Mocha.Test} test
176
180
  */
@@ -254,3 +258,7 @@ function truncate(msg, gap = 0) {
254
258
  }
255
259
  return msg;
256
260
  }
261
+
262
+ function isMaskedData() {
263
+ return global.maskSensitiveData === true || false
264
+ }
package/lib/pause.js CHANGED
@@ -91,7 +91,7 @@ async function parseInput(cmd) {
91
91
  return nextStep();
92
92
  }
93
93
  for (const k of Object.keys(registeredVariables)) {
94
- eval(`var ${k} = registeredVariables['${k}'];`); // eslint-disable-line no-eval
94
+ eval(`var ${k} = registeredVariables['${k}'];`);
95
95
  }
96
96
 
97
97
  let executeCommand = Promise.resolve();
@@ -106,9 +106,9 @@ async function parseInput(cmd) {
106
106
  let isAiCommand = false;
107
107
  let $res;
108
108
  try {
109
- // eslint-disable-next-line
109
+
110
110
  const locate = global.locate; // enable locate in this context
111
- // eslint-disable-next-line
111
+
112
112
  const I = container.support('I');
113
113
  if (cmd.trim().startsWith('=>')) {
114
114
  isCustomCommand = true;
@@ -143,7 +143,7 @@ async function parseInput(cmd) {
143
143
  executeCommand = executeCommand.then(async () => {
144
144
  const cmd = getCmd();
145
145
  if (!cmd) return;
146
- return eval(cmd); // eslint-disable-line no-eval
146
+ return eval(cmd);
147
147
  }).catch((err) => {
148
148
  debug(err);
149
149
  if (isAiCommand) return;
@@ -156,7 +156,7 @@ async function parseInput(cmd) {
156
156
  const val = await executeCommand;
157
157
 
158
158
  if (isCustomCommand) {
159
- if (val !== undefined) console.log('Result', '$res=', val); // eslint-disable-line
159
+ if (val !== undefined) console.log('Result', '$res=', val);
160
160
  $res = val;
161
161
  }
162
162
 
@@ -143,9 +143,6 @@ module.exports = function (config) {
143
143
 
144
144
  const helper = helpers[helperName]
145
145
 
146
- if (helperName === 'WebDriver' && !helper.config.devtoolsProtocol)
147
- throw Error('Coverage is currently supporting the WebDriver running with Devtools protocol.')
148
-
149
146
  const v8Helper = v8CoverageHelpers[helperName]
150
147
 
151
148
  const coverageOptions = {
package/lib/secret.js CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable max-classes-per-file */
2
1
  const { deepClone } = require('./utils');
3
2
 
4
3
  const maskedString = '*****';
package/lib/step.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // TODO: place MetaStep in other file, disable rule
2
- /* eslint-disable max-classes-per-file */
2
+
3
3
  const store = require('./store');
4
4
  const Secret = require('./secret');
5
5
  const event = require('./event');
package/lib/workers.js CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable max-classes-per-file */
2
1
  const path = require('path');
3
2
  const mkdirp = require('mkdirp');
4
3
  const { Worker } = require('worker_threads');