lc2-driver
Advanced tools
Comparing version 1.1.5 to 1.1.6
43
index.js
@@ -19,2 +19,21 @@ const mouse = require('./src/device/mouse'); | ||
function querySelectElementOf(optionElement) { | ||
let parent = optionElement.parentElement; | ||
while (parent.tagName !== 'SELECT') { | ||
parent = parent.parentElement; | ||
} | ||
return parent; | ||
} | ||
function accessOptionElement(optionElement) { | ||
if (optionElement.tagName !== 'OPTION') { | ||
throw new Error('This element is not a <option>.'); | ||
} | ||
const selectElement = querySelectElementOf(optionElement); | ||
accessor(selectElement).setValue(optionElement.index); | ||
} | ||
let afterElementFound = () => {}; | ||
@@ -24,20 +43,20 @@ | ||
exports.action = { | ||
click({selector, offset}) { | ||
click({selector, offset, button = 'left'}) { | ||
return this.move({selector, offset}) | ||
.then(target => mouse.clickButton('left') | ||
.then(() => target)); | ||
.then(target => { | ||
if (target.tagName === 'OPTION') { | ||
accessOptionElement(target); | ||
} | ||
return mouse.clickButton(button).then(() => target) | ||
}); | ||
}, | ||
rclick({selector, offset}) { | ||
return this.move({selector, offset}) | ||
.then(target => mouse.clickButton('right') | ||
.then(() => target)); | ||
}, | ||
dblclick({selector, offset}) { | ||
dblclick({selector, offset, button = 'left'}) { | ||
return this.click({selector, offset}) | ||
.then(target => mouse.clickButton('left') | ||
.then(target => mouse.clickButton(button) | ||
.then(() => target)); | ||
}, | ||
hold({selector, offset}) { | ||
hold({selector, offset, button = 'left'}) { | ||
return this.move({selector, offset}).then(target => { | ||
mouse.holdButton('left'); | ||
mouse.holdButton(button); | ||
return target; | ||
@@ -44,0 +63,0 @@ }); |
{ | ||
"name": "lc2-driver", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -83,8 +83,12 @@ const {createUIEvent, createMouseEvent} = require('./event'); | ||
this.element.dispatchEvent(createMouseEvent('mousedown')); | ||
this.element.focus(); | ||
this.element.dispatchEvent(createUIEvent('focus')); | ||
this.element.dispatchEvent(createMouseEvent('mouseup')); | ||
this.element.dispatchEvent(createMouseEvent('click')); | ||
this.element.value = String(value); | ||
this.element.dispatchEvent(createUIEvent('input')); | ||
this.element.dispatchEvent(createUIEvent('change')); | ||
this.element.dispatchEvent(createUIEvent('input')); | ||
this.element.dispatchEvent(createUIEvent('blur')); | ||
@@ -106,3 +110,3 @@ return true; | ||
this.element.dispatchEvent(createMouseEvent('mousedown')); | ||
this.element.focus(); | ||
this.element.dispatchEvent(createUIEvent('focus')); | ||
this.element.dispatchEvent(createMouseEvent('mouseup')); | ||
@@ -116,2 +120,4 @@ | ||
this.element.dispatchEvent(createUIEvent('change')); | ||
this.element.dispatchEvent(createUIEvent('blur')); | ||
return true; | ||
@@ -156,3 +162,3 @@ } | ||
this.element.dispatchEvent(createMouseEvent('mousedown')); | ||
this.element.focus(); | ||
this.element.dispatchEvent(createUIEvent('focus')); | ||
this.element.dispatchEvent(createMouseEvent('mouseup')); | ||
@@ -167,2 +173,4 @@ this.element.dispatchEvent(createMouseEvent('click')); | ||
optionElement.dispatchEvent(createMouseEvent('click')); | ||
this.element.dispatchEvent(createUIEvent('blur')); | ||
return true; | ||
@@ -169,0 +177,0 @@ } |
@@ -43,4 +43,5 @@ 'use strict'; | ||
for(let o in this.$to) { | ||
if(typeof this.$to[o] === 'number' && typeof this.$from[o] === 'number') { | ||
step[o] = (this.$to[o]-this.$from[o])/speed; | ||
const delta = this.$to[o]-this.$from[o]; | ||
if(typeof delta === 'number' && delta) { | ||
step[o] = delta/speed; | ||
} | ||
@@ -60,4 +61,4 @@ } | ||
// Check if transition completed. | ||
if((step[o] <= 0 && this.$from[o] <= this.$to[o]) || ( | ||
step[o] >= 0 && this.$from[o] >= this.$to[o])) { | ||
if((step[o] < 0 && this.$from[o] <= this.$to[o]) || ( | ||
step[o] > 0 && this.$from[o] >= this.$to[o])) { | ||
clearInterval(interval); | ||
@@ -64,0 +65,0 @@ for(let o in step) { |
@@ -25,2 +25,8 @@ /** | ||
let alertLastMessage = ''; | ||
let confirmLastMessage = ''; | ||
let confirmReturn = true; | ||
let promptLastMessage = ''; | ||
let promptValue = ''; | ||
setInterval(() => traverseFrame(window, window => { | ||
@@ -32,24 +38,19 @@ if (window.lc2Injected) { | ||
window.lc2Injected = true; | ||
}), 50); | ||
let alertLastMessage = ''; | ||
window.alert = function (message) { | ||
alertLastMessage = message; | ||
return undefined; | ||
}; | ||
window.alert = function (message) { | ||
alertLastMessage = message; | ||
return undefined; | ||
}; | ||
let confirmLastMessage = ''; | ||
let confirmReturn = true; | ||
window.confirm = function (message) { | ||
confirmLastMessage = message; | ||
return confirmReturn; | ||
}; | ||
window.confirm = function (message) { | ||
confirmLastMessage = message; | ||
return confirmReturn; | ||
}; | ||
window.prompt = function (message) { | ||
promptLastMessage = message; | ||
return promptValue; | ||
}; | ||
}), 50); | ||
let promptLastMessage = ''; | ||
let promptValue = ''; | ||
window.prompt = function (message) { | ||
promptLastMessage = message; | ||
return promptValue; | ||
}; | ||
exports.setUploadCallback = function (fn) { | ||
@@ -56,0 +57,0 @@ uploadCallback = fn; |
function visitFrameWindow(window) { | ||
let windowList = [window]; | ||
window.document.querySelectorAll('iframe') | ||
window.document && window.document.querySelectorAll('iframe') | ||
.forEach(iframe => { | ||
@@ -5,0 +5,0 @@ const iframeWindow = iframe.contentWindow; |
@@ -68,2 +68,41 @@ const animate = require('../src/animate'); | ||
}); | ||
it('start and end with same pos', function (done) { | ||
const start_pos = { | ||
clientX: 50, | ||
clientY: -20 | ||
}; | ||
const end_pos = { | ||
clientX: 50, | ||
clientY: -20 | ||
}; | ||
animate(start_pos,end_pos) | ||
.onComplete(() => { | ||
assert.equal(start_pos.clientX, end_pos.clientX); | ||
assert.equal(start_pos.clientY, end_pos.clientY); | ||
done(); | ||
}).start(); | ||
}); | ||
it('with one property equal', function (done) { | ||
var updateCnt = 0; | ||
const start_pos = { | ||
clientX: 50, | ||
clientY: -20 | ||
}; | ||
const end_pos = { | ||
clientX: 50, | ||
clientY: -100 | ||
}; | ||
animate(start_pos,end_pos) | ||
.onUpdate(() => { | ||
updateCnt++; | ||
}) | ||
.onComplete(() => { | ||
assert.equal(updateCnt, 10); | ||
assert.equal(start_pos.clientX, end_pos.clientX); | ||
assert.equal(start_pos.clientY, end_pos.clientY); | ||
done(); | ||
}).start(); | ||
}); | ||
}); |
@@ -173,7 +173,10 @@ $(document).ready(function () { | ||
return act.input({selector: _('select#index'), value: 1}).then(() => { | ||
return act.input({selector: _('select#value'), value: 'd'}) | ||
return act.input({selector: _('select#value'), value: 'd'}); | ||
}).then(() => { | ||
return act.click({selector: _('select#click option:contains(345)')}); | ||
}); | ||
}, function ($, _) { | ||
return query.value({selector: _('select#index')}) === 'b' && | ||
query.value({selector: _('select#value')}) === 'd'; | ||
query.value({selector: _('select#value')}) === 'd' && | ||
query.value({selector: _('select#click')}) === 'c'; | ||
}); | ||
@@ -180,0 +183,0 @@ |
Sorry, the diff of this file is not supported yet
100905
1823