forked from octalmage/robotjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
171 additions
and
237 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,56 @@ | ||
var test = require('tape'); | ||
var robot = require('..'); | ||
|
||
var params = | ||
{ | ||
'width': 'number', | ||
'height': 'number', | ||
'byteWidth': 'number', | ||
'bitsPerPixel': 'number', | ||
'bytesPerPixel': 'number', | ||
'image': 'object' | ||
}; | ||
|
||
test('Get a bitmap.', function(t) | ||
{ | ||
t.plan(1); | ||
t.ok(robot.screen.capture(), 'got a bitmap.'); | ||
}); | ||
|
||
test('Get a bitmap and check the parameters.', function(t) | ||
{ | ||
t.plan(6); | ||
var img = robot.screen.capture(); | ||
|
||
for (var x in params) | ||
{ | ||
t.equal(typeof img[x], params[x], 'make sure ' + x + ' is a ' + params[x] + '.'); | ||
} | ||
}); | ||
|
||
test('Get a bitmap of a specific size.', function(t) | ||
{ | ||
var size = 10; | ||
t.plan(2); | ||
var img = robot.screen.capture(0, 0, size, size); | ||
|
||
// Support for higher density screens. | ||
var multi = img.width / size; | ||
var size = size * multi; | ||
t.equals(img.height, size, 'make sure image is expected height.'); | ||
t.equals(img.width, size, 'make sure image is expected width.'); | ||
}); | ||
|
||
test('Get a bitmap and make sure the colorAt works as expected.', function(t) | ||
{ | ||
t.plan(7); | ||
var img = robot.screen.capture(); | ||
var hex = img.colorAt(0, 0); | ||
|
||
t.ok(/^[0-9A-F]{6}$/i.test(hex), "colorAt returned valid hex."); | ||
|
||
var screenSize = robot.getScreenSize(); | ||
var width = screenSize.width; | ||
var height = screenSize.height; | ||
|
||
// Support for higher density screens. | ||
var multi = img.width / width; | ||
width = width * multi; | ||
height = height * multi; | ||
|
||
t.throws(function() | ||
describe('Bitmap', () => { | ||
var params = { | ||
'width': 'number', | ||
'height': 'number', | ||
'byteWidth': 'number', | ||
'bitsPerPixel': 'number', | ||
'bytesPerPixel': 'number', | ||
'image': 'object' | ||
}; | ||
|
||
it('Get a bitmap and check the parameters.', function() { | ||
var img = robot.screen.capture(); | ||
|
||
for (var x in params) | ||
{ | ||
expect(typeof img[x]).toEqual(params[x]); | ||
} | ||
}); | ||
|
||
it('Get a bitmap of a specific size.', function() | ||
{ | ||
img.colorAt(0, height); | ||
}, /are outside the bitmap/, 'colorAt (0, screen.height) threw an error.'); | ||
var size = 10; | ||
var img = robot.screen.capture(0, 0, size, size); | ||
|
||
t.doesNotThrow(function() | ||
{ | ||
img.colorAt(0, height-1); | ||
}, /are outside the bitmap/, 'colorAt (0, screen.height-1) did not throw an error.'); | ||
|
||
t.throws(function() | ||
{ | ||
img.colorAt(width, 0); | ||
}, /are outside the bitmap/, 'colorAt (screen.width, 0) threw an error.'); | ||
|
||
t.doesNotThrow(function() | ||
{ | ||
img.colorAt(width-1, 0); | ||
}, /are outside the bitmap/, 'colorAt (screen.width-1, 0) did not throw an error.'); | ||
|
||
t.throws(function() | ||
{ | ||
img.colorAt(9999999999999, 0); | ||
}, /are outside the bitmap/, 'colorAt (9999999999999, 0) threw an error.'); | ||
// Support for higher density screens. | ||
var multi = img.width / size; | ||
var size = size * multi; | ||
expect(img.height).toEqual(size); | ||
expect(img.width).toEqual(size); | ||
}); | ||
|
||
// Regression test for https://github.com/octalmage/robotjs/commit/c41f38217fd73f59e6ca63015b51565cd1e7cfb7 | ||
t.throws(function() | ||
it('Get a bitmap and make sure the colorAt works as expected.', function() | ||
{ | ||
img.colorAt(0, 9999999999999); | ||
}, /are outside the bitmap/, 'colorAt (0, 9999999999999) threw an error.'); | ||
var img = robot.screen.capture(); | ||
var hex = img.colorAt(0, 0); | ||
|
||
// t.ok(.it(hex), "colorAt returned valid hex."); | ||
expect(hex).toMatch(/^[0-9A-F]{6}$/i); | ||
|
||
var screenSize = robot.getScreenSize(); | ||
var width = screenSize.width; | ||
var height = screenSize.height; | ||
|
||
// Support for higher density screens. | ||
var multi = img.width / width; | ||
width = width * multi; | ||
height = height * multi; | ||
expect(() => img.colorAt(0, height)).toThrowError(/are outside the bitmap/); | ||
expect(() => img.colorAt(0, height-1)).not.toThrow(); | ||
expect(() => img.colorAt(width, 0)).toThrowError(/are outside the bitmap/); | ||
expect(() => img.colorAt(9999999999999, 0)).toThrowError(/are outside the bitmap/); | ||
expect(() => img.colorAt(0, 9999999999999)).toThrowError(/are outside the bitmap/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,82 @@ | ||
/* jshint esversion: 6 */ | ||
var test = require('tape'); | ||
var robot = require('../..'); | ||
var targetpractice = require('targetpractice/index.js'); | ||
var os = require('os'); | ||
var elements; | ||
|
||
robot.setMouseDelay(100); | ||
|
||
test('Test clicking.', { timeout: 10000 }, function(t) | ||
{ | ||
t.plan(2); | ||
let target, elements; | ||
|
||
// Start the UI. | ||
var target = targetpractice.start(); | ||
describe('Integration/Mouse', () => { | ||
beforeEach(done => { | ||
target = targetpractice.start(); | ||
target.once('elements', message => { | ||
elements = message; | ||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
targetpractice.stop(); | ||
target = null; | ||
}); | ||
|
||
it('clicks', done => { | ||
// Alright we got a click event, did we click the button we wanted? | ||
target.once('click', function(e) | ||
{ | ||
expect(e.id).toEqual('button_1'); | ||
expect(e.type).toEqual('click'); | ||
done(); | ||
}); | ||
|
||
// Wait for the list of elements. | ||
target.once('elements', function(elements) | ||
{ | ||
// For this test we want a button. | ||
var button_1 = elements.button_1; | ||
|
||
// Click it! | ||
robot.moveMouse(button_1.x, button_1.y); | ||
robot.mouseClick(); | ||
}); | ||
|
||
// Alright we got a click event, did we click the button we wanted? | ||
target.once('click', function(e) | ||
{ | ||
t.equal(e.id, "button_1", 'Confirm button_1 was clicked.'); | ||
t.equal(e.type, "click", 'Confirm event was a click.'); | ||
}); | ||
|
||
// Close the UI. | ||
t.once('end', function() | ||
{ | ||
targetpractice.stop(); | ||
}); | ||
}); | ||
|
||
test('Test typing.', { timeout: 10000 }, function(t) | ||
{ | ||
t.plan(2); | ||
|
||
var target = targetpractice.start(); | ||
var stringToType = "hello world"; | ||
it('types', done => { | ||
const stringToType = 'hello world'; | ||
// Currently Target Practice waits for the "user" to finish typing before sending the event. | ||
target.once('type', element => { | ||
expect(element.id).toEqual('input_1'); | ||
expect(element.text).toEqual(stringToType); | ||
done(); | ||
}); | ||
|
||
target.on('elements', function(elements) | ||
{ | ||
var input_1 = elements.input_1; | ||
const input_1 = elements.input_1; | ||
robot.moveMouse(input_1.x, input_1.y); | ||
robot.mouseClick(); | ||
robot.typeString(stringToType); | ||
}); | ||
|
||
// Currently Target Practice waits for the "user" to finish typing before sending the event. | ||
target.once('type', function(element) | ||
{ | ||
t.equal(element.id, "input_1", 'Confirm input_1 was used.'); | ||
t.equal(element.text, stringToType, `Confirm that ${stringToType} was typed.`); | ||
}); | ||
|
||
t.once('end', function() | ||
{ | ||
targetpractice.stop(); | ||
}); | ||
}); | ||
|
||
test('Test scrolling.', { timeout: 10000 }, function(t) | ||
{ | ||
t.plan(2); | ||
it('scrolls', done => { | ||
target.once('scroll', element => { | ||
/** | ||
* TODO: This is gross! The scroll distance is different for each OS. I want | ||
* to look into this further, but at least these numbers are consistent. | ||
*/ | ||
let expectedScroll; | ||
switch(os.platform()) { | ||
case 'linux': | ||
expectedScroll = 180; | ||
break; | ||
case 'win32': | ||
expectedScroll = 8; | ||
break; | ||
default: | ||
expectedScroll = 10; | ||
} | ||
expect(element.id).toEqual('textarea_1'); | ||
expect(element.scroll_y).toEqual(expectedScroll); | ||
done(); | ||
}); | ||
|
||
var target = targetpractice.start(); | ||
|
||
target.once('elements', function(elements) | ||
{ | ||
var textarea_1 = elements.textarea_1; | ||
robot.moveMouse(textarea_1.x, textarea_1.y); | ||
robot.mouseClick(); | ||
robot.scrollMouse(0, -10); | ||
}); | ||
|
||
target.once('scroll', function(element) | ||
{ | ||
/** | ||
* TODO: This is gross! The scroll distance is different for each OS. I want | ||
* to look into this further, but at least these numbers are consistent. | ||
*/ | ||
let expectedScroll; | ||
switch(os.platform()) { | ||
case 'linux': | ||
expectedScroll = 180; | ||
break; | ||
case 'win32': | ||
expectedScroll = 8; | ||
break; | ||
default: | ||
expectedScroll = 10; | ||
} | ||
t.equal(element.id, 'textarea_1', 'Confirm textarea_1 was used.'); | ||
t.equal(element.scroll_y, expectedScroll, 'Confirm scroll to 10.'); | ||
}); | ||
|
||
t.once('end', function() | ||
{ | ||
targetpractice.stop(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.