diff --git a/src/index.js b/src/index.js index 034c1d8..51af6b9 100644 --- a/src/index.js +++ b/src/index.js @@ -160,6 +160,13 @@ class VBot extends EventEmitter { throw e }) } + if (action.type === 'move') { + await this.move(action).catch((e) => { + console.log('catch a move error'); + log = {index: i, action: action, details: e} + throw e + }) + } if (['enter', 'typing'].indexOf(action.type) !== -1) { await this.type(action) if (action.enter) { @@ -460,6 +467,13 @@ class VBot extends EventEmitter { } await this.chromejs.click(action.selector) } + async move(action) { + if (!action.selector) { + throw new Error('move action failed') + } + await this.chromejs.move(action.selector, action.start_position[0], action.start_position[1], action.end_position[0], action.end_position[1]) + } + async selectDropdown(action) { await this.chromejs.select(action.selector, action.selectIndex) diff --git a/src/schema/playbook.json b/src/schema/playbook.json index 6b63697..5cf7ab6 100644 --- a/src/schema/playbook.json +++ b/src/schema/playbook.json @@ -22,7 +22,7 @@ "delay": {"type": "integer", "minimum": 1, "description": "delay in ms before executing this action"}, "type": { "type": "string", - "enum": ["exist", "click", "typing", "select", "scroll", "assertInnerText", "reload"], + "enum": ["exist", "click", "typing", "select", "scroll", "assertInnerText", "reload", "move"], "description": "action type" }, "screenshot": {"type": "boolean", "description": "whether to take screenshot and do comparison with previous version after the action has been executed."}, @@ -40,6 +40,29 @@ "waitTimeout": {"type": "integer", "minimum": 1} } }, + "move": { + "required": ["selector","start_position","end_position"], + "properties": { + "type": {}, + "selector": { "type": "string" }, + "start_position": { + "type": "array", + "items": [ + {"type": "number"}, + {"type": "number"} + ] + }, + "end_position": { + "type": "array", + "items": [ + {"type": "number"}, + {"type": "number"} + ] + }, + "scrollTo": {"type": "boolean"}, + "waitTimeout": {"type": "integer", "minimum": 1} + } + }, "click": { "required": ["selector"], "properties": { diff --git a/test/fixtures/html/move.html b/test/fixtures/html/move.html new file mode 100644 index 0000000..7f5c296 --- /dev/null +++ b/test/fixtures/html/move.html @@ -0,0 +1,34 @@ + + + + + move tests + + + + +
+ + + diff --git a/test/src/actions.js b/test/src/actions.js index 901bb6b..c7a765a 100644 --- a/test/src/actions.js +++ b/test/src/actions.js @@ -129,6 +129,24 @@ describe('actions', async () => { }) }); }); + describe('move', function () { + it('should move using position', function (done) { + _.assign(playbook, { + url: `${fixturePath}/move.html`, + scenario: this.test.title, + actions: [ + {type: 'move', selector: '#changecolor', start_position: [160, 220], end_position: [50, 100], delay: 1000}, + ] + }) + vbot.start(playbook) + vbot.on('end', () => { + vbot.chromejs.eval(`document.querySelector('#changecolor').className`).then((data) => { + assert.equal(data.result.value,'blank') + done() + }) + }) + }); + }); describe('scroll', function () { it('should scroll using position', function (done) { _.assign(playbook, {