utils-specs.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { getXctestrunFilePath, getAdditionalRunContent, getXctestrunFileName } from '../../lib/utils';
  2. import { PLATFORM_NAME_IOS, PLATFORM_NAME_TVOS } from '../../lib/constants';
  3. import chai from 'chai';
  4. import chaiAsPromised from 'chai-as-promised';
  5. import { withMocks } from '@appium/test-support';
  6. import { fs } from '@appium/support';
  7. import path from 'path';
  8. import { fail } from 'assert';
  9. chai.should();
  10. chai.use(chaiAsPromised);
  11. describe('utils', function () {
  12. describe('#getXctestrunFilePath', withMocks({fs}, function (mocks) {
  13. const platformVersion = '12.0';
  14. const sdkVersion = '12.2';
  15. const udid = 'xxxxxyyyyyyzzzzzz';
  16. const bootstrapPath = 'path/to/data';
  17. const platformName = PLATFORM_NAME_IOS;
  18. afterEach(function () {
  19. mocks.verify();
  20. });
  21. it('should return sdk based path with udid', async function () {
  22. mocks.fs.expects('exists')
  23. .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
  24. .returns(true);
  25. mocks.fs.expects('copyFile')
  26. .never();
  27. const deviceInfo = {isRealDevice: true, udid, platformVersion, platformName};
  28. await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
  29. .should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`));
  30. });
  31. it('should return sdk based path without udid, copy them', async function () {
  32. mocks.fs.expects('exists')
  33. .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
  34. .returns(false);
  35. mocks.fs.expects('exists')
  36. .withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`))
  37. .returns(true);
  38. mocks.fs.expects('copyFile')
  39. .withExactArgs(
  40. path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`),
  41. path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)
  42. )
  43. .returns(true);
  44. const deviceInfo = {isRealDevice: true, udid, platformVersion};
  45. await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
  46. .should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`));
  47. });
  48. it('should return platform based path', async function () {
  49. mocks.fs.expects('exists')
  50. .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
  51. .returns(false);
  52. mocks.fs.expects('exists')
  53. .withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-x86_64.xctestrun`))
  54. .returns(false);
  55. mocks.fs.expects('exists')
  56. .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`))
  57. .returns(true);
  58. mocks.fs.expects('copyFile')
  59. .never();
  60. const deviceInfo = {isRealDevice: false, udid, platformVersion};
  61. await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
  62. .should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`));
  63. });
  64. it('should return platform based path without udid, copy them', async function () {
  65. mocks.fs.expects('exists')
  66. .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
  67. .returns(false);
  68. mocks.fs.expects('exists')
  69. .withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-x86_64.xctestrun`))
  70. .returns(false);
  71. mocks.fs.expects('exists')
  72. .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`))
  73. .returns(false);
  74. mocks.fs.expects('exists')
  75. .withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-x86_64.xctestrun`))
  76. .returns(true);
  77. mocks.fs.expects('copyFile')
  78. .withExactArgs(
  79. path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-x86_64.xctestrun`),
  80. path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)
  81. )
  82. .returns(true);
  83. const deviceInfo = {isRealDevice: false, udid, platformVersion};
  84. await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
  85. .should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`));
  86. });
  87. it('should raise an exception because of no files', async function () {
  88. const expected = path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-x86_64.xctestrun`);
  89. mocks.fs.expects('exists').exactly(4).returns(false);
  90. const deviceInfo = {isRealDevice: false, udid, platformVersion};
  91. try {
  92. await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath);
  93. fail();
  94. } catch (err) {
  95. err.message.should.equal(`If you are using 'useXctestrunFile' capability then you need to have a xctestrun file (expected: '${expected}')`);
  96. }
  97. });
  98. }));
  99. describe('#getAdditionalRunContent', function () {
  100. it('should return ios format', function () {
  101. const wdaPort = getAdditionalRunContent(PLATFORM_NAME_IOS, 8000);
  102. wdaPort.WebDriverAgentRunner
  103. .EnvironmentVariables.USE_PORT
  104. .should.equal('8000');
  105. });
  106. it('should return tvos format', function () {
  107. const wdaPort = getAdditionalRunContent(PLATFORM_NAME_TVOS, '9000');
  108. wdaPort.WebDriverAgentRunner_tvOS
  109. .EnvironmentVariables.USE_PORT
  110. .should.equal('9000');
  111. });
  112. });
  113. describe('#getXctestrunFileName', function () {
  114. const platformVersion = '12.0';
  115. const udid = 'xxxxxyyyyyyzzzzzz';
  116. it('should return ios format, real device', function () {
  117. const platformName = 'iOs';
  118. const deviceInfo = {isRealDevice: true, udid, platformVersion, platformName};
  119. getXctestrunFileName(deviceInfo, '10.2.0').should.equal(
  120. 'WebDriverAgentRunner_iphoneos10.2.0-arm64.xctestrun');
  121. });
  122. it('should return ios format, simulator', function () {
  123. const platformName = 'ios';
  124. const deviceInfo = {isRealDevice: false, udid, platformVersion, platformName};
  125. getXctestrunFileName(deviceInfo, '10.2.0').should.equal(
  126. 'WebDriverAgentRunner_iphonesimulator10.2.0-x86_64.xctestrun');
  127. });
  128. it('should return tvos format, real device', function () {
  129. const platformName = 'tVos';
  130. const deviceInfo = {isRealDevice: true, udid, platformVersion, platformName};
  131. getXctestrunFileName(deviceInfo, '10.2.0').should.equal(
  132. 'WebDriverAgentRunner_tvOS_appletvos10.2.0-arm64.xctestrun');
  133. });
  134. it('should return tvos format, simulator', function () {
  135. const platformName = 'tvOS';
  136. const deviceInfo = {isRealDevice: false, udid, platformVersion, platformName};
  137. getXctestrunFileName(deviceInfo, '10.2.0').should.equal(
  138. 'WebDriverAgentRunner_tvOS_appletvsimulator10.2.0-x86_64.xctestrun');
  139. });
  140. });
  141. });