Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | 1x 13x 13x 7x 1x 6x 4x 2x 2x 2x 2x 2x 2x 1x 1x 1x 6x 2x 2x 4x 2x 2x 2x 4x 2x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 3x 1x 2x 1x 1x 2x 2x 2x |
/**
*
* This command helps you to debug your integration tests. It stops the running browser and gives
* you time to jump into it and check the state of your application (e.g. using dev tools).
* Your terminal transforms into a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)
* interface that will allow you to try out certain commands, find elements and test actions on
* them.
*
* [](https://webdriver.io/images/repl.gif)
*
* If you run the WDIO testrunner make sure you increase the timeout property of the test framework
* you are using (e.g. Mocha or Jasmine) in order to prevent test termination due to a test timeout.
* Also avoid executing the command with multiple capabilities running at the same time.
*
* <iframe width="560" height="315" src="https://www.youtube.com/embed/xWwP-3B_YyE" frameborder="0" allowfullscreen></iframe>
*
* <example>
:debug.js
it('should demonstrate the debug command', () => {
$('#input').setValue('FOO')
browser.debug() // jumping into the browser and change value of #input to 'BAR'
const value = $('#input').getValue()
console.log(value) // outputs: "BAR"
})
* </example>
*
* @alias browser.debug
* @type utility
*
*/
import vm from 'vm'
import repl from 'repl'
import { runFnInFiberContext, hasWdioSyncSupport } from '@wdio/config'
import { STATIC_RETURNS, INTRO_MESSAGE } from './constants'
export default class WDIORepl {
static introMessage = INTRO_MESSAGE
constructor (config) {
this.config = Object.assign({
commandTimeout: 5000,
eval: ::this.eval,
prompt: '\u203A ',
useGlobal: true,
useColor: true
}, config)
this.isCommandRunning = false
}
eval (cmd, context, filename, callback) {
if (this.isCommandRunning) {
return
}
if (cmd && STATIC_RETURNS[cmd.trim()]) {
return callback(null, STATIC_RETURNS[cmd.trim()])
}
vm.createContext(context)
this.isCommandRunning = true
/* istanbul ignore if */
if (hasWdioSyncSupport) {
return runFnInFiberContext(
() => this._runCmd(cmd, context, callback))()
}
return this._runCmd(cmd, context, callback)
}
_runCmd (cmd, context, callback) {
try {
const result = vm.runInContext(cmd, context)
return this._handleResult(result, callback)
} catch (e) {
this.isCommandRunning = false
return callback(e)
}
}
_handleResult (result, callback) {
if (!result || typeof result.then !== 'function') {
this.isCommandRunning = false
return callback(null, result)
}
const timeout = setTimeout(
() => {
callback(new Error('Command execution timed out'))
this.isCommandRunning = false
timeout._called = true
},
this.config.commandTimeout
)
result.then((res) => {
/**
* don't do anything if timeout was called
*/
if (timeout._called) {
return
}
this.isCommandRunning = false
clearTimeout(timeout)
return callback(null, res)
}, (e) => {
/**
* don't do anything if timeout was called
*/
if (timeout._called) {
return
}
this.isCommandRunning = false
clearTimeout(timeout)
const errorMessage = e ? e.message : 'Command execution timed out'
const commandError = new Error(errorMessage)
delete commandError.stack
return callback(commandError)
})
}
start (context) {
if (this.replServer) {
throw new Error('a repl was already initialised')
}
if (context) {
const evalFn = this.config.eval
this.config.eval = (cmd, _, filename, callback) => evalFn(cmd, context, filename, callback)
}
this.replServer = repl.start(this.config)
return new Promise(
(resolve) => this.replServer.on('exit', resolve))
}
}
|