Skip to content

Commit facc34f

Browse files
committed
Fix for Windows.
1 parent e98bf7a commit facc34f

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

test/integration/mouse.js

+23-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test('Test clicking.', { timeout: 10000 }, function(t)
1515
var target = targetpractice.start();
1616

1717
// Wait for the list of elements.
18-
target.on('elements', function(elements)
18+
target.once('elements', function(elements)
1919
{
2020
// For this test we want a button.
2121
var button_1 = elements.button_1;
@@ -26,14 +26,14 @@ test('Test clicking.', { timeout: 10000 }, function(t)
2626
});
2727

2828
// Alright we got a click event, did we click the button we wanted?
29-
target.on('click', function(e)
29+
target.once('click', function(e)
3030
{
3131
t.equal(e.id, "button_1", 'Confirm button_1 was clicked.');
3232
t.equal(e.type, "click", 'Confirm event was a click.');
3333
});
3434

3535
// Close the UI.
36-
t.on("end", function()
36+
t.once('end', function()
3737
{
3838
targetpractice.stop();
3939
});
@@ -55,13 +55,13 @@ test('Test typing.', { timeout: 10000 }, function(t)
5555
});
5656

5757
// Currently Target Practice waits for the "user" to finish typing before sending the event.
58-
target.on('type', function(element)
58+
target.once('type', function(element)
5959
{
6060
t.equal(element.id, "input_1", 'Confirm input_1 was used.');
6161
t.equal(element.text, stringToType, `Confirm that ${stringToType} was typed.`);
6262
});
6363

64-
t.on("end", function()
64+
t.once('end', function()
6565
{
6666
targetpractice.stop();
6767
});
@@ -73,24 +73,36 @@ test('Test scrolling.', { timeout: 10000 }, function(t)
7373

7474
var target = targetpractice.start();
7575

76-
target.on('elements', function(elements)
76+
target.once('elements', function(elements)
7777
{
7878
var textarea_1 = elements.textarea_1;
7979
robot.moveMouse(textarea_1.x, textarea_1.y);
8080
robot.mouseClick();
8181
robot.scrollMouse(0, -10);
8282
});
8383

84-
target.on('scroll', function(element)
84+
target.once('scroll', function(element)
8585
{
86-
// On Linux the textarea scrolls more aggressively.
87-
// TODO: I couldn't find a way to make scrolling more accurate on Linux.
88-
const expectedScroll = os.platform() === 'linux' ? 180 : 10;
86+
/**
87+
* TODO: This is gross! The scroll distance is different for each OS. I want
88+
* to look into this further, but at least these numbers are consistent.
89+
*/
90+
let expectedScroll;
91+
switch(os.platform()) {
92+
case 'linux':
93+
expectedScroll = 180;
94+
break;
95+
case 'win32':
96+
expectedScroll = 8;
97+
break;
98+
default:
99+
expectedScroll = 10;
100+
}
89101
t.equal(element.id, 'textarea_1', 'Confirm textarea_1 was used.');
90102
t.equal(element.scroll_y, expectedScroll, 'Confirm scroll to 10.');
91103
});
92104

93-
t.on('end', function()
105+
t.once('end', function()
94106
{
95107
targetpractice.stop();
96108
});

test/integration/screen.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ test('Test reading the Screen.', { timeout: 10000 }, function(t)
1414
var target = targetpractice.start();
1515

1616
// Wait for the list of elements.
17-
target.on('elements', function(elements)
17+
target.once('elements', function(elements)
1818
{
1919
var color_1 = elements.color_1;
2020
const color = robot.getPixelColor(color_1.x, color_1.y);
21-
t.equal(color, "c0ff33", 'Color is what we expected.');
21+
t.equal(color, 'c0ff33', 'Color is what we expected.');
2222
});
2323

2424
// Close the UI.
25-
t.on("end", function()
25+
t.once('end', function()
2626
{
2727
targetpractice.stop();
2828
});

0 commit comments

Comments
 (0)