private static async Task ConfigureForIOSTests(TestConfiguration config, CancellationToken cancellationToken) { // Install Helpers for testing on iOS Devices / Simulators // await Pip.UpgradePip(cancellationToken).ConfigureAwait(false); // await Gem.InstallXcPretty(cancellationToken).ConfigureAwait(false); // await Brew.InstallAppleSimUtils(cancellationToken).ConfigureAwait(false); // await Brew.InstallFFMPEG(cancellationToken).ConfigureAwait(false); // await Brew.InstallIdbCompanion(cancellationToken).ConfigureAwait(false); // await Pip.InstallIdbClient(cancellationToken).ConfigureAwait(false); await Task.CompletedTask; if (cancellationToken.IsCancellationRequested) { return; } var device = AppleSimulator.GetSimulator(); if (device is null) { throw new NullReferenceException("Unable to locate the Device"); } config.DeviceName = device.Name; config.UDID = device.Udid; config.OSVersion = device.OSVersion; AppleSimulator.ShutdownAllSimulators(); }
private static bool IsIOSSupportedInternal() { try { return(IsRunningOnMac && AppleSimulator.GetAvailableSimulators().Any()); } catch { } return(false); }
private static bool IsIOSSupportedInternal() { try { var hasSimulators = AppleSimulator.GetAvailableSimulators().Any(); if (IsRunningOnMac && !hasSimulators) { Logger.WriteError("You appear to be running on macOS, but there are no available Simulators installed."); } return(IsRunningOnMac && hasSimulators); } catch { } return(false); }
private async Task GenerateTestConfig(string headBin, string uiTestBin, string platform, CancellationToken cancellationToken) { var binDir = new DirectoryInfo(headBin); var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true, AllowTrailingCommas = true, IgnoreNullValues = true, PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip }; var appPath = platform switch { "Android" => binDir.GetFiles().First(x => x.Name.EndsWith("-Signed.apk")).FullName, "iOS" => binDir.GetDirectories().First(x => x.Name.EndsWith(".app")).FullName, null => throw new ArgumentNullException("No platform was specified"), _ => throw new PlatformNotSupportedException($"The {platform} is not supported") }; var config = new TestConfiguration(); var testConfig = Path.Combine(uiTestBin, ConfigFileName); if (!string.IsNullOrEmpty(ConfigurationPath)) { if (!File.Exists(ConfigurationPath)) { throw new FileNotFoundException($"Could not locate the specified uitest configuration at: '{ConfigurationPath}'"); } config = JsonSerializer.Deserialize <TestConfiguration>(File.ReadAllText(ConfigurationPath), options); } else if (File.Exists(testConfig)) { config = JsonSerializer.Deserialize <TestConfiguration>(File.ReadAllText(testConfig), options); } if (config.Capabilities is null) { config.Capabilities = new Dictionary <string, string>(); } if (config.Settings is null) { config.Settings = new Dictionary <string, string>(); } config.Platform = platform; config.AppPath = appPath; if (string.IsNullOrEmpty(config.ScreenshotsPath)) { config.ScreenshotsPath = Path.Combine(BaseWorkingDirectory, "screenshots"); } switch (platform) { case "Android": // Ensure WebDrivers are installed await SdkManager.InstallWebDriver(cancellationToken).ConfigureAwait(false); // Ensure latest CmdLine tools are installed await SdkManager.InstallLatestCommandLineTools(cancellationToken).ConfigureAwait(false); // Check for connected device if (!await Adb.DeviceIsConnected(cancellationToken)) { // Ensure SDK Installed await SdkManager.EnsureSdkIsInstalled(sdkVersion, cancellationToken).ConfigureAwait(false); // Ensure Emulator Exists if (!(await Emulator.ListEmulators(cancellationToken)).Any(x => x == AvdManager.DefaultUITestEmulatorName)) { await AvdManager.InstallEmulator(sdkVersion, cancellationToken); } // Start Emulator await Emulator.StartEmulator(AvdManager.DefaultUITestEmulatorName, cancellationToken).ConfigureAwait(false); } var emulator = (await Adb.ListDevices(cancellationToken).ConfigureAwait(false)).First(); config.DeviceName = emulator.Name; config.UDID = emulator.Id; config.OSVersion = $"{emulator.SdkVersion}"; break; case "iOS": AppleSimulator.ShutdownAllSimulators(); var device = AppleSimulator.GetSimulator(); if (device is null) { throw new NullReferenceException("Unable to locate the Device"); } config.DeviceName = device.Name; config.UDID = device.Udid; config.OSVersion = device.OSVersion; break; } var jsonOutput = JsonSerializer.Serialize(config, options); File.WriteAllText(testConfig, jsonOutput); if (DisplayGeneratedConfig) { Logger.WriteLine(jsonOutput, LogLevel.Normal); } }