-
-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathcommands.js
More file actions
305 lines (275 loc) · 8.67 KB
/
commands.js
File metadata and controls
305 lines (275 loc) · 8.67 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import { Actions } from './command/actions.js';
import { AddText } from './command/addText.js';
import { Click } from './command/click.js';
import { Element } from './command/element.js';
import { Wait } from './command/wait.js';
import { Measure } from './command/measure.js';
import { JavaScript } from './command/javaScript.js';
import { Switch } from './command/switch.js';
import { Screenshot } from './command/screenshot.js';
import { Set } from './command/set.js';
import { Cache } from './command/cache.js';
import { Meta } from './command/meta.js';
import { Watch as StopWatch } from './command/stopWatch.js';
import { Select } from './command/select.js';
import { Debug } from './command/debug.js';
import { Bidi } from './command/bidi.js';
import { AndroidCommand } from './command/android.js';
import { ChromeDevelopmentToolsProtocol } from './command/chromeDevToolsProtocol.js';
import { ChromeTrace } from './command/chromeTrace.js';
import {
SingleClick,
DoubleClick,
ClickAndHold,
ContextClick,
MouseMove
} from './command/mouse/index.js';
import { Scroll } from './command/scroll.js';
import { Navigation } from './command/navigation.js';
import { GeckoProfiler } from '../../firefox/geckoProfiler.js';
import { GeckoProfiler as GeckoProfilerCommand } from './command/geckoProfiler.js';
import { PerfStatsInterface } from './command/perfStats.js';
import { PerfettoTrace } from './command/perfetto.js';
import { SimplePerfProfiler } from './command/simpleperf.js';
/**
* Represents the set of commands available in a Browsertime script.
* @hideconstructor
*/
export class Commands {
constructor({
browser,
engineDelegate,
index,
result,
storageManager,
pageCompleteCheck,
context,
videos,
screenshotManager,
scriptsByCategory,
asyncScriptsByCategory,
postURLScripts,
options
}) {
const measure = new Measure({
browser,
index,
pageCompleteCheck,
result,
engineDelegate,
storageManager,
videos,
scriptsByCategory,
asyncScriptsByCategory,
postURLScripts,
context,
screenshotManager,
options
});
/**
* Provides functionality to collect perfetto traces.
* @type {PerfettoTrace}
*/
this.perfetto = new PerfettoTrace(browser, index, storageManager, options);
/**
* Provides functionality to collect simpleperf profiles.
* @type {SimplePerfProfiler}
*/
this.simpleperf = new SimplePerfProfiler(
browser,
index,
storageManager,
options
);
/**
* Manages GeckoProfiler functionality to collect performance profiles.
* @type {GeckoProfiler}
*/
const browserProfiler = new GeckoProfiler(browser, storageManager, options);
// Profiler
this.profiler = new GeckoProfilerCommand(
browserProfiler,
browser,
index,
options,
result
);
/**
* Manages PerfStats functionality to collect performance counters.
* @type {PerfStatsInterface}
*/
const perfStats = new PerfStatsInterface(browser, options);
this.perfStats = perfStats;
const cdp = new ChromeDevelopmentToolsProtocol(
engineDelegate,
options.browser
);
/**
* Manages Chrome trace functionality, enabling custom profiling and trace collection in Chrome.
* @type {ChromeTrace}
*/
this.trace = new ChromeTrace(engineDelegate, index, options, result);
/**
* Provides functionality to perform click actions on elements in a web page using various selectors.
* @type {Click}
*/
this.click = new Click(browser, pageCompleteCheck);
/**
* Provides functionality to control page scrolling in the browser.
* @type {Scroll}
*/
this.scroll = new Scroll(browser, options);
/**
* Provides functionality to add text to elements on a web page using various selectors.
* @type {AddText}
*/
this.addText = new AddText(browser);
/**
* Provides functionality to wait for different conditions in the browser.
* @type {Wait}
*/
this.wait = new Wait(browser, pageCompleteCheck);
/**
* Provides functionality for measuring a navigation.
* @type {Measure}
*/
this.measure = measure;
/**
* Navigates to a specified URL and handles additional setup for a page visit.
* @async
* @example await commands.navigate('https://www.example.org');
* @type {Function}
* @param {string} url - The URL to navigate to.
* @throws {Error} Throws an error if navigation or setup fails.
* @returns {Promise<void>} A promise that resolves when the navigation and setup are
*/
this.navigate = measure._navigate.bind(measure);
/**
* Provides functionality to control browser navigation such as back, forward, and refresh actions.
* @type {Navigation}
*/
this.navigation = new Navigation(browser, pageCompleteCheck);
/**
* Add a text that will be an error attached to the current page.
* @example await commands.error('My error message');
* @param {string} message - The error message.
* @type {Function}
*/
this.error = measure._error.bind(measure);
/**
* Mark this run as an failure. Add a message that explains the failure.
* @example await commands.markAsFailure('My failure message');
* @param {string} message - The message attached as a failure
* @type {Function}
*/
this.markAsFailure = measure._failure.bind(measure);
/**
* Executes JavaScript in the browser context.
* @type {JavaScript}
*/
this.js = new JavaScript(browser, pageCompleteCheck);
/**
* Switches context to different frames, windows, or tabs in the browser.
* @type {Switch}
*/
this.switch = new Switch(
browser,
pageCompleteCheck,
measure._navigate.bind(measure)
);
/**
* Sets values on HTML elements in the page.
* @type {Set}
*/
this.set = new Set(browser);
/**
* Stopwatch utility for measuring time intervals.
* @type {StopWatch}
*/
this.stopWatch = new StopWatch(measure);
/**
* Manages the browser's cache.
* @type {Cache}
*/
this.cache = new Cache(browser, options.browser, cdp);
/**
* Adds metadata to the user journey.
* @type {Meta}
*/
this.meta = new Meta();
/**
* Takes and manages screenshots.
* @type {Screenshot}
*/
this.screenshot = new Screenshot(screenshotManager, browser, index);
/**
* Use the Chrome DevTools Protocol, available in Chrome and Edge.
* @type {ChromeDevelopmentToolsProtocol}
*/
this.cdp = cdp;
/**
*
* Use WebDriver Bidi. Availible in Firefox and in the future more browsers.
* @type {Bidi}
*/
this.bidi = new Bidi(engineDelegate, options.browser);
/**
* Provides commands for interacting with an Android device.
* @type {AndroidCommand}
*/
this.android = new AndroidCommand(options);
/**
* Provides debugging capabilities within a browser automation script.
* It allows setting breakpoints to pause script execution and inspect the current state.
* @type {Debug}
*/
this.debug = new Debug(browser, options);
/**
* Interact with the page using the mouse.
* @type {Object}
*/
this.mouse = {
/**
* Move the mouse cursor to elements or specific positions on a web page.
* @type {MouseMove}
*/
moveTo: new MouseMove(browser),
/**
* Perform a context click (right-click) on elements in a web page.
* @type {ContextClick}
*/
contextClick: new ContextClick(browser),
/**
* Provides functionality to perform a single click action on elements or at specific positions in a web page.
* @type {SingleClick}
*/
singleClick: new SingleClick(browser, pageCompleteCheck),
/**
* Provides functionality to perform a double-click action on elements in a web page.
* @type {DoubleClick}
*/
doubleClick: new DoubleClick(browser, pageCompleteCheck),
/**
* Provides functionality to click and hold elements on a web page using different strategies.
* @type {ClickAndHold}
*/
clickAndHold: new ClickAndHold(browser)
};
/**
* Interact with a select element.
* @type {Select}
*/
this.select = new Select(browser);
/**
* Selenium's action sequence functionality.
* @type {Actions}
* @see https://www.selenium.dev/documentation/webdriver/actions_api/
*/
this.action = new Actions(browser);
/**
* Get Selenium's WebElements.
* @type {Element}
*/
this.element = new Element(browser);
}
}