Ejemplo n.º 1
0
        void VerifyAllArguments(string screenshotsPath)
        {
            if (osVersion == null)
            {
                throw new ArgumentNullException(nameof(osVersion));
            }

            var regex = new Regex("([a-z][A-Z]*)+[-]([0-9]*)[-][0-9]");

            if (!regex.IsMatch(osVersion))
            {
                const string Message = "osVersion must be OS name followed by OS version, seperated by \"-\". ";
                var          example = "Example: \"iOS-9-2\". osVersion was: \"" + osVersion + "\".";
                throw new ArgumentException(Message + example, nameof(osVersion));
            }

            if (screenshotsPath == null)
            {
                throw new ArgumentNullException(nameof(screenshotsPath));
            }

            if (!Directory.Exists(screenshotsPath))
            {
                Directory.CreateDirectory(screenshotsPath);
            }

            if (appBundlePath == null)
            {
                throw new ArgumentNullException(nameof(appBundlePath));
            }

            if (!Directory.Exists(appBundlePath))
            {
                throw new ArgumentException($"Could not find App bundle at: \"{appBundlePath}\".",
                                            nameof(appBundlePath));
            }

            const string SimulatorNameErrorMessage = "Specify the names of the devices you wish to screenshot. Available device names are:{0}{0}{1}{0}";
            var          availableSimulatorNames   = DeviceSetParser.GetAvailableSimulatorNames(osVersion);

            if (deviceNames == null)
            {
                throw new ArgumentNullException(string.Format(SimulatorNameErrorMessage, Environment.NewLine, string.Join(Environment.NewLine, availableSimulatorNames)), nameof(deviceNames));
            }

            if (deviceNames.Length == 0 || deviceNames.Any(d => !availableSimulatorNames.Contains(d)))
            {
                throw new ArgumentException(string.Format(SimulatorNameErrorMessage, Environment.NewLine, string.Join(Environment.NewLine, availableSimulatorNames)), nameof(deviceNames));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Takes the screenshots using the currently configured options.
        ///
        /// The app will be automated using the implemented SetAppStateForScreenshotX methods
        /// for all available simulators given the selected device type.
        ///
        /// The SetAppStateForScreenshotX methods will be run in sequence
        /// and screenshots taken after each one if configured.
        /// </summary>
        public void TakeScreenshots()
        {
            ClearScreenshotsDirectory();
            var simulators = DeviceSetParser.GetAvailableSimulators(osVersion, deviceNames);

            foreach (var device in simulators)
            {
                App = ConfigureApp
                      .Debug().EnableLocalScreenshots()
                      .iOS
                      .AppBundle(appBundlePath)
                      .DeviceIdentifier(device.UUID)
                      .StartApp(Xamarin.UITest.Configuration.AppDataMode.DoNotClear);

                TakeScreenShot(device.Name);
            }
        }