Skip to content

Commit

Permalink
Updated cli syntax; Added infinity run option; Minor code style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipoliko committed Nov 16, 2018
1 parent 69807e1 commit f88828d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions bin/qape.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
62 changes: 0 additions & 62 deletions qape.conf.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 7 additions & 9 deletions src/actions/ActionsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,37 @@ 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) {
if (element === document.body) {
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) {
Expand Down
22 changes: 9 additions & 13 deletions src/config/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 <string>'
},
numberOfAllowedActionsToReproduceErrorFromPreviousRun: {
value: 20,
Expand All @@ -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,
Expand All @@ -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 <number>'
type: 'number'
},
defaultBrowserSettings: {
value: {
ignoreHTTPSErrors: true,
defaultViewport: {
width: 1100,
width: 1280,
height: 720
},
args: ['--start-maximized']
Expand All @@ -74,8 +73,7 @@ module.exports = {
defaultNavigationTimeout: {
value: 60000,
description: 'Default navigation timeout set via page.setDefaultNavigationTimeout()',
type: 'number',
syntax: '-t, --default-navigation-timeout <number>'
type: 'number'
},
pageErrorHandler: {
value: () => {
Expand All @@ -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 <string>'
type: 'string'
},
reporters: {
value: ['default'],
Expand All @@ -101,7 +98,6 @@ module.exports = {
reportPath: {
value: './report',
description: 'Relative path for the report output',
type: 'string',
syntax: '--report-path'
type: 'string'
}
}

0 comments on commit f88828d

Please sign in to comment.