@applitools/spec-driver-selenium 1.4.1 → 1.4.3

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.
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.build = exports.performAction = exports.getElementText = exports.getElementAttribute = exports.getElementRegion = exports.getOrientation = exports.setOrientation = exports.getSystemBars = exports.waitUntilDisplayed = exports.scrollIntoView = exports.type = exports.hover = exports.click = exports.takeScreenshot = exports.visit = exports.getUrl = exports.getTitle = exports.getCapabilities = exports.getDriverInfo = exports.getCookies = exports.setWindowSize = exports.getWindowSize = exports.waitForSelector = exports.findElements = exports.findElement = exports.childContext = exports.parentContext = exports.mainContext = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.untransformSelector = exports.transformSelector = exports.transformDriver = exports.isSelector = exports.isElement = exports.isDriver = void 0;
26
+ exports.build = exports.switchWorld = exports.getWorlds = exports.getCurrentWorld = exports.performAction = exports.getElementText = exports.getElementAttribute = exports.getElementRegion = exports.getOrientation = exports.setOrientation = exports.getSystemBars = exports.waitUntilDisplayed = exports.scrollIntoView = exports.type = exports.hover = exports.click = exports.takeScreenshot = exports.visit = exports.getUrl = exports.getTitle = exports.getCapabilities = exports.getDriverInfo = exports.getCookies = exports.setWindowSize = exports.getWindowSize = exports.waitForSelector = exports.findElements = exports.findElement = exports.childContext = exports.parentContext = exports.mainContext = exports.executeScript = exports.isEqualElements = exports.isStaleElementError = exports.untransformSelector = exports.transformSelector = exports.transformDriver = exports.isSelector = exports.isElement = exports.isDriver = void 0;
27
+ const command_1 = require("selenium-webdriver/lib/command");
27
28
  const Selenium = __importStar(require("selenium-webdriver"));
28
29
  const utils = __importStar(require("@applitools/utils"));
29
30
  // #region HELPERS
@@ -39,6 +40,11 @@ function transformShadowRoot(driver, shadowRoot) {
39
40
  function isByHashSelector(selector) {
40
41
  return byHash.includes(Object.keys(selector)[0]);
41
42
  }
43
+ async function executeCustomCommand(driver, command) {
44
+ return process.env.APPLITOOLS_SELENIUM_MAJOR_VERSION === '3'
45
+ ? driver.schedule(command)
46
+ : driver.execute(command);
47
+ }
42
48
  // #endregion
43
49
  // #region UTILITY
44
50
  function isDriver(driver) {
@@ -67,7 +73,10 @@ function transformDriver(driver) {
67
73
  driver.getExecutor().defineCommand('setWindowPosition', 'POST', '/session/:sessionId/window/current/position');
68
74
  driver.getExecutor().defineCommand('performTouch', 'POST', '/session/:sessionId/touch/perform');
69
75
  driver.getExecutor().defineCommand('executeCdp', 'POST', '/session/:sessionId/chromium/send_command_and_get_result');
70
- driver.getExecutor().defineCommand('setOrientation', 'POST', '/session/:sessionId/orientation/');
76
+ driver.getExecutor().defineCommand('setOrientation', 'POST', '/session/:sessionId/orientation');
77
+ driver.getExecutor().defineCommand('getCurrentContext', 'GET', '/session/:sessionId/context');
78
+ driver.getExecutor().defineCommand('getContexts', 'GET', '/session/:sessionId/contexts');
79
+ driver.getExecutor().defineCommand('switchToContext', 'POST', '/session/:sessionId/context');
71
80
  if (process.env.APPLITOOLS_SELENIUM_MAJOR_VERSION === '3') {
72
81
  driver.getExecutor().defineCommand('switchToParentFrame', 'POST', '/session/:sessionId/frame/parent');
73
82
  }
@@ -135,8 +144,7 @@ async function mainContext(driver) {
135
144
  exports.mainContext = mainContext;
136
145
  async function parentContext(driver) {
137
146
  if (process.env.APPLITOOLS_SELENIUM_MAJOR_VERSION === '3') {
138
- const { Command } = require('selenium-webdriver/lib/command');
139
- await driver.schedule(new Command('switchToParentFrame'));
147
+ await executeCustomCommand(driver, new command_1.Command('switchToParentFrame'));
140
148
  return driver;
141
149
  }
142
150
  await driver.switchTo().parentFrame();
@@ -183,11 +191,9 @@ async function getWindowSize(driver) {
183
191
  return { width: rect.width, height: rect.height };
184
192
  }
185
193
  catch {
186
- const { Command } = require('selenium-webdriver/lib/command');
187
- const getWindowSizeCommand = new Command('getWindowSize');
188
194
  const size = driver.manage().window().getSize
189
195
  ? await driver.manage().window().getSize()
190
- : await driver.execute(getWindowSizeCommand);
196
+ : await executeCustomCommand(driver, new command_1.Command('getWindowSize'));
191
197
  return { width: size.width, height: size.height };
192
198
  }
193
199
  }
@@ -197,17 +203,14 @@ async function setWindowSize(driver, size) {
197
203
  await driver.manage().window().setRect({ x: 0, y: 0, width: size.width, height: size.height });
198
204
  }
199
205
  catch {
200
- const { Command } = require('selenium-webdriver/lib/command');
201
- const setWindowPositionCommand = new Command('setWindowPosition').setParameters({ x: 0, y: 0 });
202
206
  if (driver.manage().window().setPosition)
203
207
  await driver.manage().window().setPosition(0, 0);
204
208
  else
205
- await driver.execute(setWindowPositionCommand);
206
- const setWindowSizeCommand = new Command('setWindowSize').setParameters({ ...size });
209
+ await executeCustomCommand(driver, new command_1.Command('setWindowPosition').setParameters({ x: 0, y: 0 }));
207
210
  if (driver.manage().window().setSize)
208
211
  await driver.manage().window().setSize(size.width, size.height);
209
212
  else
210
- await driver.execute(setWindowSizeCommand);
213
+ await executeCustomCommand(driver, new command_1.Command('setWindowSize').setParameters({ ...size }));
211
214
  }
212
215
  }
213
216
  exports.setWindowSize = setWindowSize;
@@ -220,13 +223,7 @@ async function getCookies(driver, context) {
220
223
  cookies = response.cookies;
221
224
  }
222
225
  else {
223
- const { Command } = require('selenium-webdriver/lib/command');
224
- const executeCdpCommand = new Command('executeCdp')
225
- .setParameter('cmd', 'Network.getAllCookies')
226
- .setParameter('params', {});
227
- const response = process.env.APPLITOOLS_SELENIUM_MAJOR_VERSION === '3'
228
- ? await driver.schedule(executeCdpCommand)
229
- : await driver.execute(executeCdpCommand);
226
+ const response = await executeCustomCommand(driver, new command_1.Command('executeCdp').setParameter('cmd', 'Network.getAllCookies').setParameter('params', {}));
230
227
  cookies = response.cookies;
231
228
  }
232
229
  return cookies.map((cookie) => {
@@ -249,11 +246,7 @@ async function getDriverInfo(driver) {
249
246
  exports.getDriverInfo = getDriverInfo;
250
247
  async function getCapabilities(driver) {
251
248
  try {
252
- const { Command } = require('selenium-webdriver/lib/command');
253
- const getSessionDetailsCommand = new Command('getSessionDetails');
254
- return process.env.APPLITOOLS_SELENIUM_MAJOR_VERSION === '3'
255
- ? await driver.schedule(getSessionDetailsCommand)
256
- : await driver.execute(getSessionDetailsCommand);
249
+ return executeCustomCommand(driver, new command_1.Command('getSessionDetails'));
257
250
  }
258
251
  catch {
259
252
  const capabilities = await driver.getCapabilities();
@@ -316,27 +309,15 @@ exports.waitUntilDisplayed = waitUntilDisplayed;
316
309
  // #endregion
317
310
  // #region MOBILE COMMANDS
318
311
  async function getSystemBars(driver) {
319
- const { Command } = require('selenium-webdriver/lib/command');
320
- const getSystemBarsCommand = new Command('getSystemBars');
321
- return process.env.APPLITOOLS_SELENIUM_MAJOR_VERSION === '3'
322
- ? await driver.schedule(getSystemBarsCommand)
323
- : await driver.execute(getSystemBarsCommand);
312
+ return executeCustomCommand(driver, new command_1.Command('getSystemBars'));
324
313
  }
325
314
  exports.getSystemBars = getSystemBars;
326
315
  async function setOrientation(driver, orientation) {
327
- const { Command } = require('selenium-webdriver/lib/command');
328
- const setOrientationCommand = new Command('setOrientation').setParameters({ orientation });
329
- process.env.APPLITOOLS_SELENIUM_MAJOR_VERSION === '3'
330
- ? await driver.schedule(setOrientationCommand)
331
- : await driver.execute(setOrientationCommand);
316
+ await executeCustomCommand(driver, new command_1.Command('setOrientation').setParameters({ orientation }));
332
317
  }
333
318
  exports.setOrientation = setOrientation;
334
319
  async function getOrientation(driver) {
335
- const { Command } = require('selenium-webdriver/lib/command');
336
- const getOrientationCommand = new Command('getOrientation');
337
- const orientation = process.env.APPLITOOLS_SELENIUM_MAJOR_VERSION === '3'
338
- ? await driver.schedule(getOrientationCommand)
339
- : await driver.execute(getOrientationCommand);
320
+ const orientation = await executeCustomCommand(driver, new command_1.Command('getOrientation'));
340
321
  return orientation.toLowerCase();
341
322
  }
342
323
  exports.getOrientation = getOrientation;
@@ -360,18 +341,23 @@ async function getElementText(_driver, element) {
360
341
  }
361
342
  exports.getElementText = getElementText;
362
343
  async function performAction(driver, steps) {
363
- const { Command } = require('selenium-webdriver/lib/command');
364
- const performTouchCommand = new Command('performTouch').setParameters({
344
+ await executeCustomCommand(driver, new command_1.Command('performTouch').setParameters({
365
345
  actions: steps.map(({ action, ...options }) => ({ action, options })),
366
- });
367
- if (process.env.APPLITOOLS_SELENIUM_MAJOR_VERSION === '3') {
368
- await driver.schedule(performTouchCommand);
369
- }
370
- else {
371
- await driver.execute(performTouchCommand);
372
- }
346
+ }));
373
347
  }
374
348
  exports.performAction = performAction;
349
+ async function getCurrentWorld(driver) {
350
+ return executeCustomCommand(driver, new command_1.Command('getCurrentContext'));
351
+ }
352
+ exports.getCurrentWorld = getCurrentWorld;
353
+ async function getWorlds(driver) {
354
+ return executeCustomCommand(driver, new command_1.Command('getContexts'));
355
+ }
356
+ exports.getWorlds = getWorlds;
357
+ async function switchWorld(driver, name) {
358
+ return executeCustomCommand(driver, new command_1.Command('switchToContext').setParameters({ name }));
359
+ }
360
+ exports.switchWorld = switchWorld;
375
361
  // #endregion
376
362
  // #region TESTING
377
363
  const browserOptionsNames = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/spec-driver-selenium",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "keywords": [
5
5
  "selenium",
6
6
  "selenium-webdriver",
@@ -83,7 +83,7 @@
83
83
  "husky": "^4.3.7",
84
84
  "mocha": "^9.2.2",
85
85
  "prettier": "^2.6.2",
86
- "selenium-webdriver": "^4.2.0",
86
+ "selenium-webdriver": "4.4.0",
87
87
  "ts-node": "^10.8.0",
88
88
  "ttypescript": "^1.5.13",
89
89
  "typescript": "^4.7.2"
package/types/index.d.ts CHANGED
@@ -48,6 +48,9 @@ export function getElementRegion(_driver: Driver, element: Element): Promise<imp
48
48
  export function getElementAttribute(_driver: Driver, element: Element, attr: string): Promise<string>;
49
49
  export function getElementText(_driver: Driver, element: Element): Promise<string>;
50
50
  export function performAction(driver: Driver, steps: Array<any>): Promise<void>;
51
+ export function getCurrentWorld(driver: Driver): Promise<string>;
52
+ export function getWorlds(driver: Driver): Promise<Array<string>>;
53
+ export function switchWorld(driver: Driver, name: string): Promise<void>;
51
54
  export function build(__0: any): Promise<[import('selenium-webdriver').WebDriver & { __applitoolsBrand?: never; } & { __serverUrl?: string; }, () => Promise<void>]>;
52
55
  export type Driver = import('selenium-webdriver').WebDriver & { __applitoolsBrand?: never; };
53
56
  export type Element = import('selenium-webdriver').WebElement & { __applitoolsBrand?: never; };