@@ -4,63 +4,90 @@ import useBrowser from '@cloudscape-design/browser-test-tools/use-browser';
4
4
5
5
// Workaround until scrollbars are generally shown in tests (AWSUI-59983)
6
6
7
+ interface Options {
8
+ isMobile ?: boolean ;
9
+ width ?: number ;
10
+ height ?: number ;
11
+ }
12
+
7
13
interface TestFunction {
8
14
( browser : WebdriverIO . Browser ) : Promise < void > | void ;
9
15
}
10
16
11
- const options = {
12
- capabilities : {
13
- 'goog:chromeOptions' : {
14
- args : [
15
- // Same array as in
16
- // https://github.com/cloudscape-design/browser-test-tools/blob/4aaed9e410b13e05a7d5dbace17231776d250b97/src/browsers/capabilities.ts
17
- // but without --hide-scrollbar.
18
- '--disable-background-timer-throttling' ,
19
- '--disable-breakpad' ,
20
- '--disable-client-side-phishing-detection' ,
21
- '--disable-cloud-import' ,
22
- '--disable-default-apps' ,
23
- '--disable-dev-shm-usage' ,
24
- '--disable-extensions' ,
25
- '--disable-gesture-typing' ,
26
- '--disable-hang-monitor' ,
27
- '--disable-infobars' ,
28
- '--disable-notifications' ,
29
- '--disable-offer-store-unmasked-wallet-cards' ,
30
- '--disable-offer-upload-credit-cards' ,
31
- '--disable-popup-blocking' ,
32
- '--disable-print-preview' ,
33
- '--disable-prompt-on-repost' ,
34
- '--disable-setuid-sandbox' ,
35
- '--disable-speech-api' ,
36
- '--disable-sync' ,
37
- '--disable-tab-for-desktop-share' ,
38
- '--disable-translate' ,
39
- '--disable-voice-input' ,
40
- '--disable-wake-on-wifi' ,
41
- '--disk-cache-size=33554432' ,
42
- '--enable-async-dns' ,
43
- '--enable-simple-cache-backend' ,
44
- '--enable-tcp-fast-open' ,
45
- '--enable-webgl' ,
46
- '--ignore-gpu-blacklist' ,
47
- '--media-cache-size=33554432' ,
48
- '--metrics-recording-only' ,
49
- '--mute-audio' ,
50
- '--no-default-browser-check' ,
51
- '--no-first-run' ,
52
- '--no-pings' ,
53
- '--no-zygote' ,
54
- '--password-store=basic' ,
55
- '--prerender-from-omnibox=disabled' ,
56
- '--no-sandbox' ,
57
- '--disable-gpu' ,
58
- '--headless=new' ,
59
- ] ,
60
- } ,
61
- } ,
62
- } ;
17
+ const flags = [
18
+ // Same array as in
19
+ // https://github.com/cloudscape-design/browser-test-tools/blob/4aaed9e410b13e05a7d5dbace17231776d250b97/src/browsers/capabilities.ts
20
+ // but without --hide-scrollbar.
21
+ '--disable-background-timer-throttling' ,
22
+ '--disable-breakpad' ,
23
+ '--disable-client-side-phishing-detection' ,
24
+ '--disable-cloud-import' ,
25
+ '--disable-default-apps' ,
26
+ '--disable-dev-shm-usage' ,
27
+ '--disable-extensions' ,
28
+ '--disable-gesture-typing' ,
29
+ '--disable-hang-monitor' ,
30
+ '--disable-infobars' ,
31
+ '--disable-notifications' ,
32
+ '--disable-offer-store-unmasked-wallet-cards' ,
33
+ '--disable-offer-upload-credit-cards' ,
34
+ '--disable-popup-blocking' ,
35
+ '--disable-print-preview' ,
36
+ '--disable-prompt-on-repost' ,
37
+ '--disable-setuid-sandbox' ,
38
+ '--disable-speech-api' ,
39
+ '--disable-sync' ,
40
+ '--disable-tab-for-desktop-share' ,
41
+ '--disable-translate' ,
42
+ '--disable-voice-input' ,
43
+ '--disable-wake-on-wifi' ,
44
+ '--disk-cache-size=33554432' ,
45
+ '--enable-async-dns' ,
46
+ '--enable-simple-cache-backend' ,
47
+ '--enable-tcp-fast-open' ,
48
+ '--enable-webgl' ,
49
+ '--ignore-gpu-blacklist' ,
50
+ '--media-cache-size=33554432' ,
51
+ '--metrics-recording-only' ,
52
+ '--mute-audio' ,
53
+ '--no-default-browser-check' ,
54
+ '--no-first-run' ,
55
+ '--no-pings' ,
56
+ '--no-zygote' ,
57
+ '--password-store=basic' ,
58
+ '--prerender-from-omnibox=disabled' ,
59
+ '--no-sandbox' ,
60
+ '--disable-gpu' ,
61
+ '--headless=new' ,
62
+ ] ;
63
63
64
- export default function ( testFn : TestFunction ) : ( ) => Promise < void > {
64
+ function useBrowserWithScrollbars ( optionsOverride : Options , testFn : TestFunction ) : ( ) => Promise < void > ;
65
+ function useBrowserWithScrollbars ( testFn : TestFunction ) : ( ) => Promise < void > ;
66
+ function useBrowserWithScrollbars ( ...args : [ Options , TestFunction ] | [ TestFunction ] ) {
67
+ // How to do type-safe function overloads: https://stackoverflow.com/questions/55852612/typescript-overloads-optional-arguments-and-type-inference
68
+ const optionsOverride = args . length === 1 ? { } : args [ 0 ] ;
69
+ const { width, height } = optionsOverride ;
70
+ const testFn = args . length === 1 ? args [ 0 ] : args [ 1 ] ;
71
+ const options = {
72
+ capabilities : {
73
+ 'goog:chromeOptions' : {
74
+ args : flags ,
75
+ mobileEmulation : optionsOverride . isMobile
76
+ ? {
77
+ deviceMetrics : {
78
+ mobile : true ,
79
+ touch : true ,
80
+ width,
81
+ height,
82
+ } ,
83
+ }
84
+ : undefined ,
85
+ } ,
86
+ } ,
87
+ width,
88
+ height,
89
+ } ;
65
90
return useBrowser ( options , testFn ) ;
66
91
}
92
+
93
+ export default useBrowserWithScrollbars ;
0 commit comments