table_spec.js 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const helpers_1 = require("./helpers");
  4. const path = require("path");
  5. describe('table tests', () => {
  6. let driverFactory = helpers_1.initMockSeleniumStandaloneServerAndGetDriverFactory(true);
  7. let table = {
  8. getCurrentContext: { result: 'WEBVIEW_1' },
  9. selectContext: { args: ['WEBVIEW_1'], params: { name: 'WEBVIEW_1' } },
  10. listContexts: { result: ['WEBVIEW_1'] },
  11. uploadFile: { args: ['hello'], params: { file: 'hello' } },
  12. getNetworkConnection: { result: 6 },
  13. setNetworkConnection: [
  14. { args: [0], params: { 'type': 0 } },
  15. { args: [true, false, false], params: { 'type': 1 } },
  16. { args: [false, true, true], params: { 'type': 6 } }
  17. ],
  18. toggleAirplaneMode: {},
  19. toggleData: {},
  20. toggleWiFi: {},
  21. toggleLocationServices: {},
  22. getGeolocation: { result: { latitude: 0, longitude: 0, altitude: 0 } },
  23. setGeolocation: { args: [1, 2, 3], params: { location: { latitude: 1, longitude: 2, altitude: 3 } } },
  24. getScreenOrientation: { result: 'PORTRAIT' },
  25. setScreenOrientation: { args: ['landscape'], params: { orientation: 'LANDSCAPE' } },
  26. switchToParentFrame: {},
  27. fullscreen: {},
  28. getAppiumSettings: { result: { ignoreUnimportantViews: false } },
  29. setAppiumSettings: { args: [{ ignoreUnimportantViews: true }], params: { settings: { ignoreUnimportantViews: true } } },
  30. sendAppToBackground: [{ params: { seconds: 0 } }, { args: [1], params: { seconds: 1 } }],
  31. closeApp: {},
  32. getAppStrings: [{ result: ['Hello', 'World'] },
  33. { result: ['Hello', 'World'], args: ['en'], params: { language: 'en' } }],
  34. launchSession: {},
  35. resetApp: {},
  36. getCurrentDeviceActivity: {},
  37. startDeviceActivity: [{ args: ['a', 'b', 'c', 'd'], params: { appPackage: 'a', appActivity: 'b', appWaitPackage: 'c', appWaitActivity: 'd' } },
  38. { args: ['a', 'b'], params: { appPackage: 'a', appActivity: 'b' } }],
  39. hideSoftKeyboard: [{ params: { strategy: 'default' } },
  40. { args: ['pressKey', 'Done'], params: { strategy: 'pressKey', key: 'Done' } }],
  41. installApp: { args: [path.resolve(__dirname, 'totally_real_apk.apk')],
  42. params: { appPath: path.resolve(__dirname, 'totally_real_apk.apk') } },
  43. isAppInstalled: { result: false, args: ['sjelin.is.cool'], params: { bundleId: 'sjelin.is.cool' } },
  44. removeApp: { args: ['sjelin.is.cool'], params: { appId: 'sjelin.is.cool' } },
  45. isDeviceLocked: { result: false },
  46. lockDevice: [{ params: { seconds: 0 } }, { args: [1], params: { seconds: 1 } }],
  47. unlockDevice: {},
  48. // pullFileFromDevice: null, // No good way to test this
  49. pullFolderFromDevice: { result: {}, args: [''], params: { path: '' } },
  50. pushFileToDevice: { args: ['/a/b', 'cde'], params: { path: '/a/b', data: 'cde' } },
  51. getDeviceTime: { result: new Date().toString() },
  52. openDeviceNotifications: {},
  53. rotationGesture: [{ params: { x: 0, y: 0, duration: 1, rotation: 180, touchCount: 2 } },
  54. { args: [1, 2, 3, 90, 5], params: { x: 1, y: 2, duration: 3, rotation: 90, touchCount: 5 } }],
  55. shakeDevice: {},
  56. sendChromiumCommand: { args: ['DOM.enable', {}] },
  57. sendChromiumCommandAndGetResult: { args: ['DOM.enable', {}] }
  58. };
  59. function runTestcase(commandName) {
  60. let itName = 'should correctly call "' + commandName + '"';
  61. let tableEntry = table[commandName];
  62. if (tableEntry == null) {
  63. return it(itName);
  64. }
  65. let testcases = Array.isArray(tableEntry) ? tableEntry : [tableEntry];
  66. testcases.forEach((testcase, i) => {
  67. let caseName = itName + (tableEntry === testcases ? ' (#' + i + ')' : '');
  68. if (testcase.skip) {
  69. return it(caseName);
  70. }
  71. it(caseName, (done) => {
  72. let driver = driverFactory();
  73. driver[commandName].apply(driver, testcase.args || []).then((results) => {
  74. expect(results.result).toEqual(testcase.result == null ? null : testcase.result);
  75. if (testcase.session) {
  76. for (let varname in testcase.session) {
  77. expect(results.session[varname]).
  78. toEqual(testcase.session[varname]);
  79. }
  80. }
  81. if (testcase.params) {
  82. for (let paramName in testcase.params) {
  83. expect(results.params[paramName]).toEqual(testcase.params[paramName]);
  84. }
  85. }
  86. done();
  87. });
  88. });
  89. });
  90. }
  91. for (let commandName in table) {
  92. runTestcase(commandName);
  93. }
  94. });
  95. //# sourceMappingURL=table_spec.js.map