@cloudscape-design/browser-test-tools 3.0.82 → 3.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,9 +2,10 @@ export interface ScrollPosition {
|
|
|
2
2
|
top: number;
|
|
3
3
|
left: number;
|
|
4
4
|
}
|
|
5
|
-
export declare function scrollToBottom
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export declare function scrollAction(action: 'scrollToOffset' | 'scrollToRight' | 'scrollToBottom', selector: string, offset?: {
|
|
6
|
+
top: number;
|
|
7
|
+
left: number;
|
|
8
|
+
}): void;
|
|
8
9
|
export declare function getElementScrollPosition(selector: string): ScrollPosition;
|
|
9
10
|
export declare function windowScrollTo(top: number, left: number): void;
|
|
10
11
|
export declare function getWindowScrollPosition(): ScrollPosition;
|
|
@@ -1,39 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.scrollToRight = scrollToRight;
|
|
5
|
-
exports.elementScrollTo = elementScrollTo;
|
|
3
|
+
exports.scrollAction = scrollAction;
|
|
6
4
|
exports.getElementScrollPosition = getElementScrollPosition;
|
|
7
5
|
exports.windowScrollTo = windowScrollTo;
|
|
8
6
|
exports.getWindowScrollPosition = getWindowScrollPosition;
|
|
9
|
-
function
|
|
10
|
-
|
|
7
|
+
function scrollAction(action, selector, offset) {
|
|
8
|
+
const element = document.querySelector(selector);
|
|
11
9
|
if (!element) {
|
|
12
10
|
throw new Error('Element ' + selector + ' has not been found at the page');
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (!element) {
|
|
19
|
-
throw new Error('Element ' + selector + ' has not been found at the page');
|
|
12
|
+
const overflowDirection = action === 'scrollToOffset' ? 'overflow' : action === 'scrollToBottom' ? 'overflowY' : 'overflowX';
|
|
13
|
+
const overflowStyles = getComputedStyle(element)[overflowDirection].split(' ');
|
|
14
|
+
if (!overflowStyles.includes('auto') && !overflowStyles.includes('scroll') && element !== document.documentElement) {
|
|
15
|
+
throw new Error(`Element ${selector} is not scrollable`);
|
|
20
16
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
if (overflowStyles.length === 2 && offset) {
|
|
18
|
+
const hasErrorScrollX = !['auto', 'scroll'].includes(overflowStyles[0]) && offset.left > 0;
|
|
19
|
+
const hasErrorScrollY = !['auto', 'scroll'].includes(overflowStyles[1]) && offset.top > 0;
|
|
20
|
+
if (hasErrorScrollX || hasErrorScrollY) {
|
|
21
|
+
throw new Error(`Element ${selector} is not scrollable in ${hasErrorScrollX ? 'left' : 'top'} direction`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
switch (action) {
|
|
25
|
+
case 'scrollToOffset':
|
|
26
|
+
if (!offset) {
|
|
27
|
+
throw new Error('Cannot scroll to offset without an offset');
|
|
28
|
+
}
|
|
29
|
+
element.scrollTop = offset.top;
|
|
30
|
+
element.scrollLeft = offset.left;
|
|
31
|
+
break;
|
|
32
|
+
case 'scrollToBottom':
|
|
33
|
+
element.scrollTop = element.scrollHeight;
|
|
34
|
+
break;
|
|
35
|
+
case 'scrollToRight':
|
|
36
|
+
element.scrollLeft = element.scrollWidth;
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Unsupported scroll action ${action}`);
|
|
27
40
|
}
|
|
28
|
-
element.scrollTop = top;
|
|
29
|
-
element.scrollLeft = left;
|
|
30
41
|
}
|
|
31
42
|
function getElementScrollPosition(selector) {
|
|
32
|
-
|
|
43
|
+
const element = document.querySelector(selector);
|
|
33
44
|
if (!element) {
|
|
34
|
-
// We cannnot use our custom error types as they are not available inside the browser context
|
|
35
45
|
throw new Error('Element ' + selector + ' has not been found at the page');
|
|
36
46
|
}
|
|
47
|
+
const overflowStyles = getComputedStyle(element).overflow.split(' ');
|
|
48
|
+
if (!overflowStyles.includes('auto') && !overflowStyles.includes('scroll')) {
|
|
49
|
+
throw new Error('Element ' + selector + ' is not scrollable');
|
|
50
|
+
}
|
|
37
51
|
return { top: element.scrollTop, left: element.scrollLeft };
|
|
38
52
|
}
|
|
39
53
|
function windowScrollTo(top, left) {
|
package/internal/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudscape-design/browser-test-tools",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.84",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/cloudscape-design/browser-test-tools.git"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/wait-on": "^5.3.4",
|
|
39
39
|
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
|
40
40
|
"@typescript-eslint/parser": "^5.41.0",
|
|
41
|
-
"@vitest/coverage-istanbul": "^3.0.
|
|
41
|
+
"@vitest/coverage-istanbul": "^3.0.7",
|
|
42
42
|
"eslint": "^8.26.0",
|
|
43
43
|
"eslint-config-prettier": "^8.5.0",
|
|
44
44
|
"eslint-plugin-header": "^3.1.1",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"npm-run-all": "^4.1.5",
|
|
51
51
|
"prettier": "^2.7.1",
|
|
52
52
|
"typescript": "^5.7.3",
|
|
53
|
-
"vitest": "^3.0.
|
|
53
|
+
"vitest": "^3.0.7"
|
|
54
54
|
},
|
|
55
55
|
"exports": {
|
|
56
56
|
"./chrome-launcher": "./chrome-launcher.js",
|
package/page-objects/base.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export default class BasePageObject {
|
|
|
25
25
|
getElementScroll(selector: string): Promise<ScrollPosition>;
|
|
26
26
|
elementScrollTo(selector: string, { top, left }: Partial<ScrollPosition>): Promise<void>;
|
|
27
27
|
waitForVisible(selector: string, shouldDisplay?: boolean, timeout?: number): Promise<void>;
|
|
28
|
+
waitForExist(selector: string, shouldExist?: boolean, timeout?: number): Promise<true>;
|
|
28
29
|
waitForAssertion(expression: () => Promise<void>): Promise<void>;
|
|
29
30
|
waitForJsTimers(timeout?: number): Promise<void>;
|
|
30
31
|
isFocused(selector: string): Promise<boolean>;
|
package/page-objects/base.js
CHANGED
|
@@ -135,7 +135,7 @@ class BasePageObject {
|
|
|
135
135
|
return this.browser.execute(browser_scripts_1.getElementScrollPosition, selector);
|
|
136
136
|
}
|
|
137
137
|
async elementScrollTo(selector, { top = 0, left = 0 }) {
|
|
138
|
-
await this.browser.execute(browser_scripts_1.
|
|
138
|
+
await this.browser.execute(browser_scripts_1.scrollAction, 'scrollToOffset', selector, { top, left });
|
|
139
139
|
}
|
|
140
140
|
async waitForVisible(selector, shouldDisplay = true, timeout) {
|
|
141
141
|
await this.browser.waitUntil(async () => {
|
|
@@ -148,6 +148,15 @@ class BasePageObject {
|
|
|
148
148
|
: `Element "${selector}" is still visible after waiting`,
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
|
+
waitForExist(selector, shouldExist = true, timeout) {
|
|
152
|
+
return this.browser.$(selector).waitForExist({
|
|
153
|
+
reverse: !shouldExist,
|
|
154
|
+
timeout,
|
|
155
|
+
timeoutMsg: shouldExist
|
|
156
|
+
? `Element "${selector}" is not existing upon waiting`
|
|
157
|
+
: `Element "${selector}" is still existing after waiting`,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
151
160
|
async waitForAssertion(expression) {
|
|
152
161
|
const retryOptions = { minTimeout: 100, retries: 5 };
|
|
153
162
|
await (0, p_retry_1.default)(expression, retryOptions);
|
|
@@ -18,10 +18,10 @@ class ScreenshotPageObject extends base_1.default {
|
|
|
18
18
|
return this.keys('Tab');
|
|
19
19
|
}
|
|
20
20
|
async scrollToBottom(selector) {
|
|
21
|
-
await this.browser.execute(browser_scripts_1.scrollToBottom, selector);
|
|
21
|
+
await this.browser.execute(browser_scripts_1.scrollAction, 'scrollToBottom', selector);
|
|
22
22
|
}
|
|
23
23
|
async scrollToRight(selector) {
|
|
24
|
-
await this.browser.execute(browser_scripts_1.scrollToRight, selector);
|
|
24
|
+
await this.browser.execute(browser_scripts_1.scrollAction, 'scrollToRight', selector);
|
|
25
25
|
}
|
|
26
26
|
async fullPageScreenshot() {
|
|
27
27
|
// preserve scroll position in order to avoid side effects after screenshot taking
|