Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move action #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
7,497 changes: 7,497 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"lint:staged": "lint-staged",
"lint:js": "eslint bin src||true",
"pretest": "babel src --source-maps --out-dir dist --ignore 'test/**/*.js'&&babel test/src --source-maps --out-dir test/dist",
"test": "mocha test/dist -t 15000",
"test": "mocha test/dist -t 150000",
"build": "babel src --source-maps --out-dir dist --ignore 'test/**/*.js'"
},
"author": "[email protected]",
Expand All @@ -33,11 +33,14 @@
"chromejs": "^0.4.0",
"fs-extra": "^3.0.1",
"get-port": "^3.1.0",
"jQuery": "^1.7.4",
"jimp": "^0.2.28",
"jsdom": "^11.6.2",
"jsonlint": "^1.6.2",
"lodash": "^4.17.4",
"mkdirp": "^0.5.1",
"shelljs": "^0.7.5",
"xmlhttprequest": "^1.8.0",
"yargs": "10.0.3"
},
"bin": {
Expand Down
28 changes: 26 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ class VBot extends EventEmitter {
throw e
})
}
// move log
if (action.type === 'move') {
await this.move(action).catch((e) => {
log = {index: i, action: action, details: e}
throw e
})
}

// over log
if (action.type === 'over') {
await this.over(action).catch((e) => {
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 @@ -255,14 +271,14 @@ class VBot extends EventEmitter {
this.chromejs.client.Runtime.consoleAPICalled((msg) => {
for (var i = 0; i < msg.args.length; i++) {
let arg = msg.args[i]
let stackTrace = msg.stackTrace.callFrames[0]
let stackTrace;
stackTrace = msg.stackTrace.callFrames[0]
const log = {
type: msg.type,
msg: arg.type === 'object' ? 'object' : arg.value,
url: stackTrace.url,
line: stackTrace.lineNumber
}

this.emit('console', log)
}
})
Expand Down Expand Up @@ -461,6 +477,14 @@ 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
34 changes: 33 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", "over"],
"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 All @@ -49,6 +72,15 @@
"waitTimeout": {"type": "integer", "minimum": 1}
}
},
"over": {
"required": ["selector"],
"properties": {
"type": {},
"selector": { "type": "string" },
"scrollTo": {"type": "boolean"},
"waitTimeout": {"type": "integer", "minimum": 1}
}
},
"typing": {
"required": ["value"],
"properties": {
Expand Down
Binary file modified test/fixtures/compare_imgs/.DS_Store
Binary file not shown.
37 changes: 37 additions & 0 deletions test/fixtures/html/move.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!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: 200px;
margin-left: 150px;
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>
27 changes: 24 additions & 3 deletions test/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const assert = require('assert')
const VBot = require('../../dist')
const _ = require('lodash')


process.on('unhandledRejection', (e) => {
console.log(e)
})
Expand All @@ -11,10 +12,10 @@ describe('actions', async () => {
const fixturePath = `file:///${__dirname}/../fixtures/html`
const testPath = `${__dirname}`
let playbook = {
size: {width: 375, height: 677}
size: {width: 1000, height: 1000}
}
let opts = {
showWindow: process.env.WIN,
showWindow: true||process.env.WIN,
verbose: false,
imgdir: `${testPath}/../tmp/screenshots`,
playbook: playbook
Expand Down Expand Up @@ -129,13 +130,33 @@ 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: [200, 300], 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, {
url: `${fixturePath}/scroll.html`,
scenario: this.test.title,
actions: [
{type: 'scroll', selector: '.box', position: [0, 1000], delay: 1000},
{type: 'scroll', selector: '.box', position: [0, 400], delay: 1000},
]
})
vbot.start(playbook)
Expand Down
8 changes: 5 additions & 3 deletions test/src/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ describe('screenshot', async () => {
vbot = new VBot({
verbose: false,
playbookFile: `${testPath}/fixtures/project.json`,
host: `http://localhost:${serverPort}`,
//host: `http://localhost:${serverPort}`,
host: `file:///${testPath}/fixtures/index.html`,
imgdir: `${testPath}/tmp/screenshots`,
// showWindow: true
showWindow: false
})
// await vbot.start()
});
Expand All @@ -37,7 +38,8 @@ describe('screenshot', async () => {
let playbook
beforeEach(function () {
playbook = {
"url": `http://localhost:${serverPort}/`,
//"url": `http://localhost:${serverPort}/`,
url: `file:///${testPath}/fixtures/index.html`,
scenario: 'view1',
size: {width: 375,height: 677},
"actions": [
Expand Down