From 82127d24f82b0eb5cef270a7ac882bb75a75737b Mon Sep 17 00:00:00 2001 From: Yang Jin <373526511@qq.com> Date: Tue, 6 Feb 2018 16:00:22 +0800 Subject: [PATCH] move-action new action :move-action --- src/index.js | 14 ++++++++++++++ src/schema/playbook.json | 25 ++++++++++++++++++++++++- test/fixtures/html/move.html | 34 ++++++++++++++++++++++++++++++++++ test/src/actions.js | 18 ++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/html/move.html 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 @@ + + +
+ +