appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
117 lines • 5.71 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TESTAPP_BUNDLE_ID = exports.UICATALOG_BUNDLE_ID = void 0;
exports.getUIKitCatalogPath = getUIKitCatalogPath;
exports.getTestAppPath = getTestAppPath;
const node_path_1 = __importDefault(require("node:path"));
const support_1 = require("appium/support");
const UICATALOG_URL = 'https://github.com/appium/ios-uicatalog/releases/download/v4.0.1/UIKitCatalog-iphonesimulator.zip';
const UICATALOG_CACHE_PATH = node_path_1.default.resolve(__dirname, 'fixtures', 'UIKitCatalog-iphonesimulator.app');
exports.UICATALOG_BUNDLE_ID = 'com.example.apple-samplecode.UICatalog';
const TESTAPP_URL = 'https://github.com/appium/VodQAReactNative/releases/download/v1.2.5/VodQAReactNative-simulator-release.zip';
const TESTAPP_CACHE_PATH = node_path_1.default.resolve(__dirname, 'fixtures', 'VodQAReactNative.app');
exports.TESTAPP_BUNDLE_ID = 'org.reactjs.native.example.VodQAReactNative';
// Cache the download promises to prevent concurrent downloads
const downloadPromises = new Map();
/**
* Finds .app bundles in a directory (similar to findApps in app-utils.js)
* @param {string} searchPath Directory to search in
* @returns {Promise<string[]>} Array of relative paths to .app bundles
*/
async function findApps(searchPath) {
const globPattern = '**/*.app';
const sortedBundleItems = (await support_1.fs.glob(globPattern, {
cwd: searchPath,
})).sort((a, b) => a.split(node_path_1.default.sep).length - b.split(node_path_1.default.sep).length);
return sortedBundleItems;
}
/**
* Downloads and extracts an app from a zip URL if it doesn't already exist locally.
* This function handles concurrent requests by reusing the same download promise.
*
* @param {string} url The URL to download the zip file from
* @param {string} cachePath The path where the app should be cached
* @param {string} zipFileName The name to use for the temporary zip file
* @returns {Promise<string>} The path to the cached app directory
* @throws {Error} If the download or extraction fails
*/
async function downloadAndExtractApp(url, cachePath, zipFileName) {
// If a download is already in progress, wait for it first
// This prevents returning a partially downloaded file
if (downloadPromises.has(cachePath)) {
return downloadPromises.get(cachePath);
}
// Check if the app already exists locally (only after ensuring no download is in progress)
if (await support_1.fs.exists(cachePath)) {
return cachePath;
}
// Start the download
const downloadPromise = (async () => {
try {
// Double-check if file exists (another process might have downloaded it)
if (await support_1.fs.exists(cachePath)) {
return cachePath;
}
// Ensure the fixtures directory exists
const fixturesDir = node_path_1.default.dirname(cachePath);
await support_1.fs.mkdir(fixturesDir, { recursive: true });
// Create a temporary directory for the zip file
const tmpDir = await support_1.tempDir.openDir();
const zipPath = node_path_1.default.join(tmpDir, zipFileName);
try {
// Download the zip file
await support_1.net.downloadFile(url, zipPath);
// Extract the zip file
const extractDir = await support_1.tempDir.openDir();
try {
await support_1.zip.extractAllTo(zipPath, extractDir);
// Find the .app bundle in the extracted directory
const appPaths = await findApps(extractDir);
if (appPaths.length === 0) {
throw new Error('Could not find any .app bundle in the extracted zip file');
}
// Use the first (shallowest) .app bundle found
const extractedAppPath = node_path_1.default.join(extractDir, appPaths[0]);
await support_1.fs.mv(extractedAppPath, cachePath, { mkdirp: true });
}
finally {
await support_1.fs.rimraf(extractDir);
}
}
finally {
await support_1.fs.rimraf(tmpDir);
}
return cachePath;
}
finally {
// Clear the promise so future calls can download again if needed
downloadPromises.delete(cachePath);
}
})();
downloadPromises.set(cachePath, downloadPromise);
return downloadPromise;
}
/**
* Downloads and extracts the UIKitCatalog app from GitHub if it doesn't already exist locally.
* This function handles concurrent requests by reusing the same download promise.
*
* @returns {Promise<string>} The path to the cached app directory
* @throws {Error} If the download or extraction fails
*/
async function getUIKitCatalogPath() {
return downloadAndExtractApp(UICATALOG_URL, UICATALOG_CACHE_PATH, 'UIKitCatalog-iphonesimulator.zip');
}
/**
* Downloads and extracts the VodQAReactNative (TestApp) app from GitHub if it doesn't already exist locally.
* This function handles concurrent requests by reusing the same download promise.
*
* @returns {Promise<string>} The path to the cached app directory
* @throws {Error} If the download or extraction fails
*/
async function getTestAppPath() {
return downloadAndExtractApp(TESTAPP_URL, TESTAPP_CACHE_PATH, 'VodQAReactNative-simulator-release.zip');
}
//# sourceMappingURL=setup.js.map