webdriveragent-e2e-specs.js 3.2 KB

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