index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. /**
  4. * In this file we define all the commands which run against a particular webdriver session, but
  5. * do not belong in `./appium.ts` or `./storage.ts`.
  6. */
  7. const selenium_mock_1 = require("selenium-mock");
  8. const helpers_1 = require("./helpers");
  9. const appium_1 = require("./appium");
  10. const storage_1 = require("./storage");
  11. exports.session = {
  12. element: {},
  13. sessionStorage: storage_1.storageFactory('session'),
  14. localStorage: storage_1.storageFactory('local'),
  15. appium: appium_1.appium,
  16. };
  17. exports.session.currentContext = helpers_1.getterFactory('context', 'currentContext');
  18. exports.session.selectContext = helpers_1.setterFactory('context', 'currentContext', 'name');
  19. exports.session.listContexts = helpers_1.constFactory('GET', 'contexts', ['WEBVIEW_1']);
  20. exports.session.uploadFile = helpers_1.noopFactory('file');
  21. exports.session.getNetworkConnection = helpers_1.getterFactory('network_connection', 'networkConnection');
  22. exports.session.setNetworkConnection = helpers_1.setterFactory('network_connection', 'networkConnection', 'type');
  23. exports.session.toggleAirplaneMode =
  24. new selenium_mock_1.Command('POST', 'appium/device/toggle_airplane_mode', (session) => {
  25. session.networkConnection ^= 1;
  26. });
  27. exports.session.toggleWiFi =
  28. new selenium_mock_1.Command('POST', 'appium/device/toggle_wifi', (session) => {
  29. session.networkConnection ^= 2;
  30. });
  31. exports.session.toggleData =
  32. new selenium_mock_1.Command('POST', 'appium/device/toggle_data', (session) => {
  33. session.networkConnection ^= 4;
  34. });
  35. exports.session.toggleLocationServices =
  36. new selenium_mock_1.Command('POST', 'appium/device/toggle_location_services', (session) => {
  37. session.locationEnabled = !session.locationEnabled;
  38. });
  39. exports.session.getGeolocation =
  40. new selenium_mock_1.Command('GET', '/location', (session) => {
  41. if (!session.locationEnabled) {
  42. throw 'Location services disabled';
  43. }
  44. return session.location;
  45. });
  46. exports.session.setGeolocation =
  47. new selenium_mock_1.Command('POST', '/location', (session, params) => {
  48. if (!session.locationEnabled) {
  49. throw 'Location services disabled';
  50. }
  51. session.location = params['location'];
  52. });
  53. exports.session.getOrientation = helpers_1.getterFactory('orientation');
  54. exports.session.setOrientation = helpers_1.setterFactory('orientation');
  55. exports.session.switchToParentFrame = helpers_1.noopFactory('frame/parent');
  56. exports.session.fullscreen = helpers_1.noopFactory('window/fullscreen');
  57. exports.session.performMultiAction = helpers_1.noopFactory('touch/multi/perform');
  58. exports.session.performTouchAction = helpers_1.noopFactory('touch/perform');
  59. exports.session.element.elementIdLocationInView = helpers_1.constFactory('GET', '/element/:id/location_in_view', { x: 0, y: 0 });
  60. //# sourceMappingURL=index.js.map