| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import { getXctestrunFilePath, getAdditionalRunContent, getXctestrunFileName } from '../../lib/utils';
- import { PLATFORM_NAME_IOS, PLATFORM_NAME_TVOS } from '../../lib/constants';
- import chai from 'chai';
- import chaiAsPromised from 'chai-as-promised';
- import { withMocks } from '@appium/test-support';
- import { fs } from '@appium/support';
- import path from 'path';
- import { fail } from 'assert';
- chai.should();
- chai.use(chaiAsPromised);
- describe('utils', function () {
- describe('#getXctestrunFilePath', withMocks({fs}, function (mocks) {
- const platformVersion = '12.0';
- const sdkVersion = '12.2';
- const udid = 'xxxxxyyyyyyzzzzzz';
- const bootstrapPath = 'path/to/data';
- const platformName = PLATFORM_NAME_IOS;
- afterEach(function () {
- mocks.verify();
- });
- it('should return sdk based path with udid', async function () {
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
- .returns(true);
- mocks.fs.expects('copyFile')
- .never();
- const deviceInfo = {isRealDevice: true, udid, platformVersion, platformName};
- await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
- .should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`));
- });
- it('should return sdk based path without udid, copy them', async function () {
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
- .returns(false);
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`))
- .returns(true);
- mocks.fs.expects('copyFile')
- .withExactArgs(
- path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphoneos${sdkVersion}-arm64.xctestrun`),
- path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`)
- )
- .returns(true);
- const deviceInfo = {isRealDevice: true, udid, platformVersion};
- await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
- .should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`));
- });
- it('should return platform based path', async function () {
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
- .returns(false);
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-x86_64.xctestrun`))
- .returns(false);
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`))
- .returns(true);
- mocks.fs.expects('copyFile')
- .never();
- const deviceInfo = {isRealDevice: false, udid, platformVersion};
- await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
- .should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`));
- });
- it('should return platform based path without udid, copy them', async function () {
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${sdkVersion}.xctestrun`))
- .returns(false);
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-x86_64.xctestrun`))
- .returns(false);
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`))
- .returns(false);
- mocks.fs.expects('exists')
- .withExactArgs(path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-x86_64.xctestrun`))
- .returns(true);
- mocks.fs.expects('copyFile')
- .withExactArgs(
- path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${platformVersion}-x86_64.xctestrun`),
- path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`)
- )
- .returns(true);
- const deviceInfo = {isRealDevice: false, udid, platformVersion};
- await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath)
- .should.eventually.equal(path.resolve(`${bootstrapPath}/${udid}_${platformVersion}.xctestrun`));
- });
- it('should raise an exception because of no files', async function () {
- const expected = path.resolve(`${bootstrapPath}/WebDriverAgentRunner_iphonesimulator${sdkVersion}-x86_64.xctestrun`);
- mocks.fs.expects('exists').exactly(4).returns(false);
- const deviceInfo = {isRealDevice: false, udid, platformVersion};
- try {
- await getXctestrunFilePath(deviceInfo, sdkVersion, bootstrapPath);
- fail();
- } catch (err) {
- err.message.should.equal(`If you are using 'useXctestrunFile' capability then you need to have a xctestrun file (expected: '${expected}')`);
- }
- });
- }));
- describe('#getAdditionalRunContent', function () {
- it('should return ios format', function () {
- const wdaPort = getAdditionalRunContent(PLATFORM_NAME_IOS, 8000);
- wdaPort.WebDriverAgentRunner
- .EnvironmentVariables.USE_PORT
- .should.equal('8000');
- });
- it('should return tvos format', function () {
- const wdaPort = getAdditionalRunContent(PLATFORM_NAME_TVOS, '9000');
- wdaPort.WebDriverAgentRunner_tvOS
- .EnvironmentVariables.USE_PORT
- .should.equal('9000');
- });
- });
- describe('#getXctestrunFileName', function () {
- const platformVersion = '12.0';
- const udid = 'xxxxxyyyyyyzzzzzz';
- it('should return ios format, real device', function () {
- const platformName = 'iOs';
- const deviceInfo = {isRealDevice: true, udid, platformVersion, platformName};
- getXctestrunFileName(deviceInfo, '10.2.0').should.equal(
- 'WebDriverAgentRunner_iphoneos10.2.0-arm64.xctestrun');
- });
- it('should return ios format, simulator', function () {
- const platformName = 'ios';
- const deviceInfo = {isRealDevice: false, udid, platformVersion, platformName};
- getXctestrunFileName(deviceInfo, '10.2.0').should.equal(
- 'WebDriverAgentRunner_iphonesimulator10.2.0-x86_64.xctestrun');
- });
- it('should return tvos format, real device', function () {
- const platformName = 'tVos';
- const deviceInfo = {isRealDevice: true, udid, platformVersion, platformName};
- getXctestrunFileName(deviceInfo, '10.2.0').should.equal(
- 'WebDriverAgentRunner_tvOS_appletvos10.2.0-arm64.xctestrun');
- });
- it('should return tvos format, simulator', function () {
- const platformName = 'tvOS';
- const deviceInfo = {isRealDevice: false, udid, platformVersion, platformName};
- getXctestrunFileName(deviceInfo, '10.2.0').should.equal(
- 'WebDriverAgentRunner_tvOS_appletvsimulator10.2.0-x86_64.xctestrun');
- });
- });
- });
|