normal_spec.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const helpers_1 = require("./helpers");
  4. const path = require("path");
  5. describe('normal tests', () => {
  6. let driverFactory = helpers_1.initMockSeleniumStandaloneServerAndGetDriverFactory();
  7. it('should set/get device activity', (done) => {
  8. let driver = driverFactory();
  9. driver.startDeviceActivity('sjelin', '.is.cool').then(() => {
  10. return driver.getCurrentDeviceActivity();
  11. }).then((activity) => {
  12. expect(activity).toBe('.is.cool');
  13. return driver.startDeviceActivity('sjelin', '.is.the.coolest');
  14. }).then(() => {
  15. return driver.getCurrentDeviceActivity();
  16. }).then((activity) => {
  17. expect(activity).toBe('.is.the.coolest');
  18. done();
  19. });
  20. });
  21. it('should set/get appium settings', (done) => {
  22. let driver = driverFactory();
  23. driver.setAppiumSettings({ ignoreUnimportantViews: true }).then(() => {
  24. return driver.getAppiumSettings();
  25. }).then((settings) => {
  26. expect(settings['ignoreUnimportantViews']).toBe(true);
  27. return driver.setAppiumSettings({ ignoreUnimportantViews: false });
  28. }).then(() => {
  29. return driver.getAppiumSettings();
  30. }).then((settings) => {
  31. expect(settings['ignoreUnimportantViews']).toBe(false);
  32. done();
  33. });
  34. });
  35. it('should set/get the context', (done) => {
  36. let driver = driverFactory();
  37. driver.selectContext('NATIVE_APP').then(() => {
  38. return driver.getCurrentContext();
  39. }).then((context) => {
  40. expect(context).toBe('NATIVE_APP');
  41. return driver.selectContext('WEBVIEW_1');
  42. }).then(() => {
  43. return driver.getCurrentContext();
  44. }).then((context) => {
  45. expect(context).toBe('WEBVIEW_1');
  46. done();
  47. });
  48. });
  49. it('should set/get screen orientation', (done) => {
  50. let driver = driverFactory();
  51. driver.setScreenOrientation('landscape').then(() => {
  52. return driver.getScreenOrientation();
  53. }).then((orientation) => {
  54. expect(orientation).toBe('LANDSCAPE');
  55. return driver.setScreenOrientation('portrait');
  56. }).then(() => {
  57. return driver.getScreenOrientation();
  58. }).then((orientation) => {
  59. expect(orientation).toBe('PORTRAIT');
  60. done();
  61. });
  62. });
  63. it('should lock/unlcok the device', (done) => {
  64. let driver = driverFactory();
  65. driver.lockDevice().then(() => {
  66. return driver.isDeviceLocked();
  67. }).then((locked) => {
  68. expect(locked).toBe(true);
  69. return driver.unlockDevice();
  70. }).then(() => {
  71. return driver.isDeviceLocked();
  72. }).then((locked) => {
  73. expect(locked).toBe(false);
  74. done();
  75. });
  76. });
  77. it('should install/uninstall an app', (done) => {
  78. let driver = driverFactory();
  79. driver.installApp(path.resolve(__dirname, 'totally_real_apk.apk')).then(() => {
  80. return driver.isAppInstalled('sjelin.is.cool');
  81. }).then((isInstalled) => {
  82. expect(isInstalled).toBe(true);
  83. return driver.removeApp('sjelin.is.cool');
  84. }).then(() => {
  85. return driver.isAppInstalled('sjelin.is.cool');
  86. }).then((isInstalled) => {
  87. expect(isInstalled).toBe(false);
  88. done();
  89. });
  90. });
  91. it('should manipulate file system', (done) => {
  92. let driver = driverFactory();
  93. Promise.all([
  94. driver.pushFileToDevice('/tmp/wd_js_ext/foo.txt', 'bar'),
  95. driver.pushFileToDevice('/tmp/wd_js_ext/folder/a.txt', 'x'),
  96. driver.pushFileToDevice('/tmp/wd_js_ext/folder/b.txt', 'y'),
  97. driver.pushFileToDevice('/tmp/wd_js_ext/folder/c.txt', 'z'),
  98. ]).then(() => {
  99. return driver.pullFileFromDevice('/tmp/wd_js_ext/foo.txt');
  100. }).then((fileContents) => {
  101. expect(fileContents).toBe('bar');
  102. return driver.pullFolderFromDevice('/tmp/wd_js_ext/folder');
  103. }).then((folderContents) => {
  104. expect(folderContents['a.txt']).toBe('x');
  105. expect(folderContents['b.txt']).toBe('y');
  106. expect(folderContents['c.txt']).toBe('z');
  107. done();
  108. });
  109. });
  110. describe('network connection', () => {
  111. it('should get/set the network connection', (done) => {
  112. let driver = driverFactory();
  113. driver.setNetworkConnection(0).then(() => {
  114. return driver.getNetworkConnection();
  115. }).then((networkConnection) => {
  116. expect(networkConnection).toBe(0);
  117. return driver.setNetworkConnection(6);
  118. }).then(() => {
  119. return driver.getNetworkConnection();
  120. }).then((networkConnection) => {
  121. expect(networkConnection).toBe(6);
  122. done();
  123. });
  124. });
  125. it('should be able to toggle various settings', (done) => {
  126. let driver = driverFactory();
  127. driver.setNetworkConnection(0).then(() => {
  128. return driver.getNetworkConnection();
  129. }).then((networkConnection) => {
  130. expect(networkConnection).toBe(0);
  131. return driver.toggleAirplaneMode();
  132. }).then(() => {
  133. return driver.getNetworkConnection();
  134. }).then((networkConnection) => {
  135. expect(networkConnection).toBe(1);
  136. return driver.toggleWiFi();
  137. }).then(() => {
  138. return driver.getNetworkConnection();
  139. }).then((networkConnection) => {
  140. expect(networkConnection).toBe(3);
  141. return driver.toggleData();
  142. }).then(() => {
  143. return driver.getNetworkConnection();
  144. }).then((networkConnection) => {
  145. expect(networkConnection).toBe(7);
  146. return driver.toggleWiFi();
  147. }).then(() => {
  148. return driver.getNetworkConnection();
  149. }).then((networkConnection) => {
  150. expect(networkConnection).toBe(5);
  151. return driver.toggleAirplaneMode();
  152. }).then(() => {
  153. return driver.getNetworkConnection();
  154. }).then((networkConnection) => {
  155. expect(networkConnection).toBe(4);
  156. return driver.toggleWiFi();
  157. }).then(() => {
  158. return driver.getNetworkConnection();
  159. }).then((networkConnection) => {
  160. expect(networkConnection).toBe(6);
  161. return driver.toggleData();
  162. }).then(() => {
  163. return driver.getNetworkConnection();
  164. }).then((networkConnection) => {
  165. expect(networkConnection).toBe(2);
  166. done();
  167. });
  168. });
  169. });
  170. describe('geolocation', () => {
  171. it('should get/set the geolocation', (done) => {
  172. let driver = driverFactory();
  173. driver.setGeolocation(1, 2, 3).then(() => {
  174. return driver.getGeolocation();
  175. }).then((geolocation) => {
  176. expect(geolocation).toEqual({ latitude: 1, longitude: 2, altitude: 3 });
  177. return driver.setGeolocation(0, 0, 0);
  178. }).then(() => {
  179. return driver.getGeolocation();
  180. }).then((geolocation) => {
  181. expect(geolocation).toEqual({ latitude: 0, longitude: 0, altitude: 0 });
  182. done();
  183. });
  184. });
  185. it('should disable geolocation', (done) => {
  186. let driver = driverFactory();
  187. // Location should initially work
  188. driver.setGeolocation(1, 2, 3).then(() => {
  189. return driver.getGeolocation();
  190. }).then((geolocation) => {
  191. expect(geolocation).toEqual({ latitude: 1, longitude: 2, altitude: 3 });
  192. // Double toggle should do nothing
  193. return driver.toggleLocationServices();
  194. }).then(() => {
  195. return driver.toggleLocationServices();
  196. }).then(() => {
  197. return driver.setGeolocation(0, 0, 0);
  198. }).then(() => {
  199. return driver.getGeolocation();
  200. }).then((geolocation) => {
  201. expect(geolocation).toEqual({ latitude: 0, longitude: 0, altitude: 0 });
  202. // Single toggle should cause the command to fail
  203. return driver.toggleLocationServices();
  204. }).then(() => {
  205. return driver.getGeolocation().catch((error) => {
  206. expect(error.toString()).toContain('Location services disabled');
  207. done();
  208. });
  209. });
  210. });
  211. });
  212. });
  213. //# sourceMappingURL=normal_spec.js.map