-
-
Notifications
You must be signed in to change notification settings - Fork 424
/
Copy pathxctest-e2e-specs.js
120 lines (106 loc) · 3.93 KB
/
xctest-e2e-specs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import path from 'path';
import {MOCHA_TIMEOUT, initSession, deleteSession, hasDefaultPrebuiltWDA} from '../helpers/session';
import {GENERIC_CAPS, amendCapabilities} from '../desired';
import xcode from 'appium-xcode';
const APP_UNDER_TEST_PATH = path.resolve(__dirname, '..', '..', 'assets', 'XCTesterApp.app');
const TEST_BUNDLE_PATH = path.resolve(
__dirname,
'..',
'..',
'assets',
'XCTesterAppUITests-Runner.app',
);
const XCTEST_BUNDLE_PATH = path.join(TEST_BUNDLE_PATH, 'PlugIns', 'XCTesterAppUITests.xctest');
if (process.env.LAUNCH_WITH_IDB) {
describe('XCTest', function () {
this.timeout(MOCHA_TIMEOUT);
let driver;
let chai;
before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.should();
chai.use(chaiAsPromised.default);
// idb_companion doesn't work with xcode 13 or lower due to concurrency lib issue.
if (
/** @type {import('appium-xcode').XcodeVersion} */ (await xcode.getVersion(true)).major < 14
) {
this.skip();
}
const caps = amendCapabilities(GENERIC_CAPS, {
'appium:app': APP_UNDER_TEST_PATH,
'appium:launchWithIDB': true,
'appium:usePrebuiltWDA': hasDefaultPrebuiltWDA(),
});
driver = await initSession(caps);
});
after(async function () {
await deleteSession();
});
it('should install an XC test bundle and then run it', async function () {
// Install the test runner app
await driver.installApp(TEST_BUNDLE_PATH);
// Install the xctest bundle
await driver.execute('mobile: installXCTestBundle', {xctestApp: XCTEST_BUNDLE_PATH});
// Get list of xctest bundles
const xcTestBundleList = await driver.execute('mobile: listXCTestBundles');
const bundleTest = 'io.appium.XCTesterAppUITests';
xcTestBundleList.should.includes(bundleTest);
// Get list of xctests within bundle
const xcTestsInBundle = await driver.execute('mobile: listXCTestsInTestBundle', {
bundle: bundleTest,
});
xcTestsInBundle.should.eql([
'XCTesterAppUITests.XCTesterAppUITests/testExample',
'XCTesterAppUITests.XCTesterAppUITests/testLaunchPerformance',
]);
// Now run the tests
const bundleApp = 'io.appium.XCTesterApp';
const res = await driver.execute('mobile: runXCTest', {
testRunnerBundleId: 'io.appium.XCTesterAppUITests.xctrunner',
appUnderTestBundleId: bundleApp,
xctestBundleId: bundleTest,
testType: 'ui',
});
res.code.should.equal(0);
res.passed.should.be.true;
res.results[0].testName.should.eql(
'XCTesterAppUITests - XCTesterAppUITests.XCTesterAppUITests/testExample',
);
res.results[0].passed.should.be.true;
res.results[1].testName.should.eql(
'XCTesterAppUITests - XCTesterAppUITests.XCTesterAppUITests/testLaunchPerformance',
);
res.results[1].passed.should.be.true;
});
it('should fail gracefully if bad params passed in runXCTest', async function () {
try {
await driver.execute('mobile: runXCTest', {
testRunnerBundleId: 'bad',
appUnderTestBundleId: 'bad',
xctestBundleId: 'bad',
testType: 'ui',
});
} catch (e) {
e.message.should.match(/Couldn't find test with id: bad/);
return;
}
throw new Error(`An exception should have been thrown`);
});
it('should fail if timeout', async function () {
try {
await driver.execute('mobile: runXCTest', {
testRunnerBundleId: 'bad',
appUnderTestBundleId: 'bad',
xctestBundleId: 'bad',
testType: 'ui',
timeout: 1,
});
} catch (e) {
e.message.should.match(/Timed out after '1ms' waiting for XCTest to complete/);
return;
}
throw new Error(`An exception should have been thrown`);
});
});
}