From f88828d992aebe4be566e4e6da41e5e5c92a7879 Mon Sep 17 00:00:00 2001 From: Satek Date: Sat, 17 Nov 2018 00:58:05 +0100 Subject: [PATCH] Updated cli syntax; Added infinity run option; Minor code style updates --- README.md | 2 +- bin/qape.js | 7 ++-- qape.conf.js | 62 ------------------------------------ src/Runner.js | 4 +++ src/actions/ActionsHelper.js | 16 ++++------ src/config/template.js | 22 ++++++------- 6 files changed, 24 insertions(+), 89 deletions(-) delete mode 100644 qape.conf.js diff --git a/README.md b/README.md index 66b1437..c43ed87 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ QApe will look for configuraition file in your current directory with name `qape module.exports = { // Number of parallel chrome instances initialized' parallelInstances: 1, - // Time in ms, after which no more scenarios will be initialized + // Time in ms, after which no more scenarios will be initialized, set to 0 to run forever stopNewScenariosAfterTime: 100000, // Maximal number of actions performed in a random scenario // (if error occures, the scenario is ended) diff --git a/bin/qape.js b/bin/qape.js index 3eb2d13..c60f1d5 100644 --- a/bin/qape.js +++ b/bin/qape.js @@ -11,14 +11,13 @@ var configValues = {}; const USER_CONFIG_PATH = path.join(process.cwd(), './qape.conf.js'); function getOptionSyntax(option, type) { - let long = '--' + option.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`); - let short = '-' + option.charAt(0); + let syntax = '--' + option.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`); if (type === 'boolean') { - return `${short}, ${long}`; + return syntax; } - return `${short}, ${long} <${type}>`; + return `${syntax} <${type}>`; } function getTypeHandler(type) { diff --git a/qape.conf.js b/qape.conf.js deleted file mode 100644 index 1241962..0000000 --- a/qape.conf.js +++ /dev/null @@ -1,62 +0,0 @@ -module.exports = { - // Number of parallel chrome instances initialized' - parallelInstances: 1, - // Time in ms, after which no more scenarios will be initialized - stopNewScenariosAfterTime: 100000, - // Maximal number of actions performed in a random scenario - // (if error occures, the scenario is ended) - actionsPerScenario: 100, - // Number of execution errors of actions to abort the random scenario. - // This prevents from infinity loops, when qape is not able to perform - // any action on the page and keeps retrying. - numberOfActionFailuresToAbortRandomScenario: 20, - // Starting url for all random scenarios - url: 'http://localhost:4444', - // After an error occured, qape will try to reproduce the error again - // and will retry up to this number of actions before giving up. - numberOfAllowedActionsToReproduceErrorFromPreviousRun: 20, - // Disables random scenarios, - // only user defined scenarios will be executed - randomScenariosDisabled: false, - // When user defined scenario recieves an error, - // it will try to minify the steps to reproduce this error. - minifyUserDefinedScenarios: true, - // Disables chromium headless mode and will display browser GUI. - headlessModeDisabled: false, - // Preview mode will overwrite other config values - // to display the scenario on the local computer - // in non-headless mode. It will also run only - // user defined scenarios and will not try to minify them. - previewMode: false, - // Wait time (in ms) between actions in preview mode. - previewModePauseTime: 1500, - // Default browser settings passed to puppeteer.launch() - defaultBrowserSettings: { - ignoreHTTPSErrors: true, - defaultViewport: { - width: 1280, - height: 720 - }, - args: ['--start-maximized'] - }, - // Default navigation timeout set via page.setDefaultNavigationTimeout() - defaultNavigationTimeout: 60000, - // Page error handler, which should tell what is actually an error. - // Function is evaluated in the browser context via - // page.evaluateOnNewDocument() and has method - // "qapeError(error)" available. - pageErrorHandler: () => { - window.addEventListener('error', (event) => { - qapeError(event.error.toString()); - }); - }, - // A browser websocket endpoint to connect to (i.e. ws://5.5.5.5:3505) - browserWebSocketEndpoint: null, - // Define your reporters for the QApe run. - // You can pass a string for reporters in npm registry, - // i.e. if you pass \'super\', QApe will look for - // reporter 'qape-reporter-super'. You can also pass Class. - reporters: ['default'], - // Relative path for the report output - reportPath: './report', -} diff --git a/src/Runner.js b/src/Runner.js index 2c4a41c..4a0eec1 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -90,6 +90,10 @@ export default class Runner { } _isAllowedToStartNewScenario() { + if (this._config.stopNewScenariosAfterTime === 0) { + return true; + } + return (new Date().getTime() - this._initTime) < this._config.stopNewScenariosAfterTime; } diff --git a/src/actions/ActionsHelper.js b/src/actions/ActionsHelper.js index 2db58a5..15c8722 100644 --- a/src/actions/ActionsHelper.js +++ b/src/actions/ActionsHelper.js @@ -3,8 +3,8 @@ export default class ActionsHelper { this._config = config; } - async getElementSelector(input) { - let executionContext = await input.executionContext(); + async getElementSelector(element) { + let executionContext = await element.executionContext(); return executionContext.evaluate(input => { function getPathTo(element) { @@ -12,30 +12,28 @@ export default class ActionsHelper { return '//' + element.tagName.toLowerCase(); } - var ix = 0; - var siblings; - if (!element.parentNode) { return ''; } - siblings = element.parentNode.childNodes; + var siblings = element.parentNode.childNodes; + var index = 0; for (var i= 0; i < siblings.length; i++) { var sibling = siblings[i]; if (sibling === element) { - return getPathTo(element.parentNode) + '/' + element.tagName.toLowerCase() + '[' + (ix + 1) + ']'; + return getPathTo(element.parentNode) + '/' + element.tagName.toLowerCase() + '[' + (index + 1) + ']'; } if (sibling.nodeType === 1 && sibling.tagName === element.tagName) { - ix++; + index++; } } } return getPathTo(input); - }, input); + }, element); } async isElementVisible(element) { diff --git a/src/config/template.js b/src/config/template.js index c6fad14..21221bb 100644 --- a/src/config/template.js +++ b/src/config/template.js @@ -7,7 +7,7 @@ module.exports = { }, stopNewScenariosAfterTime: { value: 100000, - description: 'Time in ms, after which no more scenarios will be initialized', + description: 'Time in ms, after which no more scenarios will be initialized, set to 0 to run forever', type: 'number' }, actionsPerScenario: { @@ -23,7 +23,8 @@ module.exports = { url: { value: 'http://localhost:4444', description: 'Starting url for all random scenarios', - type: 'string' + type: 'string', + syntax: '-u, --url ' }, numberOfAllowedActionsToReproduceErrorFromPreviousRun: { value: 20, @@ -33,8 +34,7 @@ module.exports = { randomScenariosDisabled: { value: false, description: 'Disables random scenarios, only user defined scenarios will be executed', - type: 'boolean', - syntax: '-d, --random-scenarios-disabled' + type: 'boolean' }, minifyUserDefinedScenarios: { value: true, @@ -55,14 +55,13 @@ module.exports = { previewModePauseTime: { value: 1500, description: 'Wait time (in ms) between actions in preview mode.', - type: 'number', - syntax: '-t, --preview-mode-pause-time ' + type: 'number' }, defaultBrowserSettings: { value: { ignoreHTTPSErrors: true, defaultViewport: { - width: 1100, + width: 1280, height: 720 }, args: ['--start-maximized'] @@ -74,8 +73,7 @@ module.exports = { defaultNavigationTimeout: { value: 60000, description: 'Default navigation timeout set via page.setDefaultNavigationTimeout()', - type: 'number', - syntax: '-t, --default-navigation-timeout ' + type: 'number' }, pageErrorHandler: { value: () => { @@ -90,8 +88,7 @@ module.exports = { browserWebSocketEndpoint: { value: null, description: 'A browser websocket endpoint to connect to (i.e. ws://5.5.5.5:3505)', - type: 'string', - syntax: '-e, --browser-web-socket-endpoint ' + type: 'string' }, reporters: { value: ['default'], @@ -101,7 +98,6 @@ module.exports = { reportPath: { value: './report', description: 'Relative path for the report output', - type: 'string', - syntax: '--report-path' + type: 'string' } }