Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 24 additions & 1 deletion src/schema/playbook.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
Expand All @@ -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": {
Expand Down
34 changes: 34 additions & 0 deletions test/fixtures/html/move.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en" onclick = 'getMousePos();'>
<head>
<meta charset="UTF-8">
<title>move tests</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style type="text/css">
#changecolor {
margin-top: 100px;
margin-left: 30px;
height: 400px;
width: 300px;
background-color: black;
}
#changecolor:hover {
background-color: blue;
}
.blank {}
</style>
</head>
<body>
<div id="changecolor"></div>
<script>
function getMousePos(event) {
var e = event || window.event;
console.log(e.clientX,e.clientY);
return {'x':e.clientX,'y':e.clientY}
}
$('#changecolor').mouseover(function () {
$('#changecolor').addClass("blank");
})
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions test/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down