webdriveragent-e2e-specs.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { Simctl } from 'node-simctl';
  2. import { getVersion } from 'appium-xcode';
  3. import { getSimulator } from 'appium-ios-simulator';
  4. import { killAllSimulators, shutdownSimulator } from './helpers/simulator';
  5. import { SubProcess } from 'teen_process';
  6. import { PLATFORM_VERSION, DEVICE_NAME } from './desired';
  7. import { retryInterval } from 'asyncbox';
  8. import { WebDriverAgent } from '../../lib/webdriveragent';
  9. import axios from 'axios';
  10. const MOCHA_TIMEOUT_MS = 60 * 1000 * 5;
  11. const SIM_DEVICE_NAME = 'webDriverAgentTest';
  12. const SIM_STARTUP_TIMEOUT_MS = MOCHA_TIMEOUT_MS;
  13. let testUrl = 'http://localhost:8100/tree';
  14. function getStartOpts (device) {
  15. return {
  16. device,
  17. platformVersion: PLATFORM_VERSION,
  18. host: 'localhost',
  19. port: 8100,
  20. realDevice: false,
  21. showXcodeLog: true,
  22. wdaLaunchTimeout: 60 * 3 * 1000,
  23. };
  24. }
  25. describe('WebDriverAgent', function () {
  26. this.timeout(MOCHA_TIMEOUT_MS);
  27. let chai;
  28. let xcodeVersion;
  29. before(async function () {
  30. chai = await import('chai');
  31. const chaiAsPromised = await import('chai-as-promised');
  32. chai.should();
  33. chai.use(chaiAsPromised.default);
  34. // Don't do these tests on Sauce Labs
  35. if (process.env.CLOUD) {
  36. this.skip();
  37. }
  38. xcodeVersion = await getVersion(true);
  39. });
  40. describe('with fresh sim', function () {
  41. let device;
  42. let simctl;
  43. before(async function () {
  44. simctl = new Simctl();
  45. simctl.udid = await simctl.createDevice(
  46. SIM_DEVICE_NAME,
  47. DEVICE_NAME,
  48. PLATFORM_VERSION
  49. );
  50. device = await getSimulator(simctl.udid);
  51. // Prebuild WDA
  52. const wda = new WebDriverAgent(xcodeVersion, {
  53. iosSdkVersion: PLATFORM_VERSION,
  54. platformVersion: PLATFORM_VERSION,
  55. showXcodeLog: true,
  56. device,
  57. });
  58. await wda.xcodebuild.start(true);
  59. });
  60. after(async function () {
  61. this.timeout(MOCHA_TIMEOUT_MS);
  62. await shutdownSimulator(device);
  63. await simctl.deleteDevice();
  64. });
  65. describe('with running sim', function () {
  66. this.timeout(6 * 60 * 1000);
  67. beforeEach(async function () {
  68. await killAllSimulators();
  69. await device.run({startupTimeout: SIM_STARTUP_TIMEOUT_MS});
  70. });
  71. afterEach(async function () {
  72. try {
  73. await retryInterval(5, 1000, async function () {
  74. await shutdownSimulator(device);
  75. });
  76. } catch {}
  77. });
  78. it('should launch agent on a sim', async function () {
  79. const agent = new WebDriverAgent(xcodeVersion, getStartOpts(device));
  80. await agent.launch('sessionId');
  81. await axios({url: testUrl}).should.be.eventually.rejected;
  82. await agent.quit();
  83. });
  84. it('should fail if xcodebuild fails', async function () {
  85. // short timeout
  86. this.timeout(35 * 1000);
  87. const agent = new WebDriverAgent(xcodeVersion, getStartOpts(device));
  88. agent.xcodebuild.createSubProcess = async function () {
  89. let args = [
  90. '-workspace',
  91. `${this.agentPath}dfgs`,
  92. // '-scheme',
  93. // 'XCTUITestRunner',
  94. // '-destination',
  95. // `id=${this.device.udid}`,
  96. // 'test'
  97. ];
  98. return new SubProcess('xcodebuild', args, {detached: true});
  99. };
  100. await agent.launch('sessionId')
  101. .should.eventually.be.rejectedWith('xcodebuild failed');
  102. await agent.quit();
  103. });
  104. });
  105. });
  106. });