forked from google/webdriver.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync_mouse_test.dart
122 lines (103 loc) · 4.13 KB
/
async_mouse_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
@TestOn('vm')
library;
import 'dart:async';
import 'package:test/test.dart';
import 'package:webdriver/async_core.dart';
import 'configs/async_io_config.dart' as config;
void main() {
group('Mouse', () {
late WebDriver driver;
late WebElement button;
Future<bool> hasAlert() async {
try {
await driver.switchTo.alert.dismiss();
return true;
} on NoSuchAlertException {
return false;
}
}
Future<bool> mouseOnButton() async {
await driver.mouse.click();
return await hasAlert();
}
setUp(() async {
driver = await config.createTestDriver();
await config.createTestServerAndGoToTestPage(driver);
button = await driver.findElement(const By.tagName('button'));
});
test('moveTo element/click', () async {
await driver.mouse.moveTo(element: button);
expect(await mouseOnButton(), true);
});
test('moveTo coordinates/click', () async {
final pos = await button.location;
await driver.mouse.moveTo(xOffset: pos.x + 5, yOffset: pos.y + 5);
expect(await mouseOnButton(), true);
});
test('moveTo element coordinates/click', () async {
await driver.mouse.moveTo(element: button, xOffset: 15, yOffset: 15);
// W3C uses center and JsonWire uses top left corner.
expect(await mouseOnButton(), driver.spec == WebDriverSpec.JsonWire);
});
test('moveTo element coordinates outside of element/click', () async {
await driver.mouse.moveTo(element: button, xOffset: -5, yOffset: -5);
// W3C uses center and JsonWire uses top left corner.
expect(await mouseOnButton(), driver.spec == WebDriverSpec.W3c);
});
test('moveToElementCenter moves to correct positions', () async {
await driver.mouse.moveToElementCenter(button, xOffset: -5, yOffset: -5);
expect(await mouseOnButton(), true);
await driver.mouse.moveToElementCenter(button, xOffset: 15, yOffset: 15);
expect(await mouseOnButton(), false);
});
test('moveToElementTopLeft moves to correct positions', () async {
await driver.mouse.moveToElementTopLeft(button, xOffset: -5, yOffset: -5);
expect(await mouseOnButton(), false);
await driver.mouse.moveToElementTopLeft(button, xOffset: 15, yOffset: 15);
expect(await mouseOnButton(), true);
});
test('hide moves away from the current location', () async {
await driver.mouse.moveTo(element: button);
expect(await mouseOnButton(), true);
await driver.mouse.hide();
expect(await mouseOnButton(), false);
});
test('hide moves to given location in w3c.', () async {
if (driver.spec == WebDriverSpec.W3c) {
final pos = await button.location;
await driver.mouse.moveTo(element: button);
expect(await mouseOnButton(), true);
await driver.mouse.moveTo(xOffset: 0, yOffset: 0, absolute: true);
expect(await mouseOnButton(), false);
await driver.mouse.hide(w3cXOffset: pos.x + 5, w3cYOffset: pos.y + 5);
expect(await mouseOnButton(), true);
}
});
// TODO(DrMarcII): Better up/down tests
test('down/up', () async {
await driver.mouse.moveTo(element: button);
await driver.mouse.down();
await driver.mouse.up();
expect(await hasAlert(), true);
});
// TODO(DrMarcII): Better double click test
test('doubleClick', () async {
await driver.mouse.moveTo(element: button);
await driver.mouse.doubleClick();
expect(await hasAlert(), true);
});
}, timeout: const Timeout(Duration(minutes: 2)));
}