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.
Merge pull request octalmage#371 from octalmage/targetpractice
Add integration tests.
- Loading branch information
Showing
12 changed files
with
2,945 additions
and
301 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 was deleted.
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* jshint esversion: 6 */ | ||
var robot = require('../..'); | ||
var targetpractice = require('targetpractice/index.js'); | ||
var os = require('os'); | ||
|
||
robot.setMouseDelay(100); | ||
|
||
var target, elements; | ||
|
||
describe('Integration/Keyboard', () => { | ||
beforeEach(done => { | ||
target = targetpractice.start(); | ||
target.once('elements', message => { | ||
elements = message; | ||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
targetpractice.stop(); | ||
target = null; | ||
}); | ||
|
||
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(); | ||
}); | ||
|
||
const input_1 = elements.input_1; | ||
robot.moveMouse(input_1.x, input_1.y); | ||
robot.mouseClick(); | ||
robot.typeString(stringToType); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* jshint esversion: 6 */ | ||
var robot = require('../..'); | ||
var targetpractice = require('targetpractice/index.js'); | ||
var os = require('os'); | ||
|
||
robot.setMouseDelay(100); | ||
|
||
var target, elements; | ||
|
||
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(); | ||
}); | ||
|
||
// 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(); | ||
}); | ||
|
||
it('scrolls vertically', 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. | ||
*/ | ||
var 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 textarea_1 = elements.textarea_1; | ||
robot.moveMouse(textarea_1.x, textarea_1.y); | ||
robot.mouseClick(); | ||
robot.scrollMouse(0, -10); | ||
}); | ||
|
||
it('scrolls horizontally', 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. | ||
*/ | ||
var expectedScroll; | ||
switch(os.platform()) { | ||
case 'linux': | ||
expectedScroll = 530; | ||
break; | ||
case 'win32': | ||
expectedScroll = 8; | ||
break; | ||
default: | ||
expectedScroll = 10; | ||
} | ||
expect(element.id).toEqual('textarea_1'); | ||
expect(element.scroll_x).toEqual(expectedScroll); | ||
done(); | ||
}); | ||
|
||
var textarea_1 = elements.textarea_1; | ||
robot.moveMouse(textarea_1.x, textarea_1.y); | ||
robot.mouseClick(); | ||
robot.scrollMouse(-10, 0); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* jshint esversion: 6 */ | ||
var robot = require('../..'); | ||
var targetpractice = require('targetpractice/index.js'); | ||
var elements, target; | ||
|
||
describe('Integration/Screen', () => { | ||
beforeEach(done => { | ||
target = targetpractice.start(); | ||
target.once('elements', message => { | ||
elements = message; | ||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
targetpractice.stop(); | ||
target = null; | ||
}); | ||
|
||
it('reads a pixel color', () => { | ||
var color_1 = elements.color_1; | ||
const color = robot.getPixelColor(color_1.x, color_1.y); | ||
expect(color).toEqual('c0ff33'); | ||
}); | ||
}); |
Oops, something went wrong.