Exemple #1
0
        private static void PlayOnDevice(IEnumerable <LocalStep> stepList, DeviceTarget deviceTarget, string packagePath, string appiumServerIp, int appiumPort, string aaptPath)
        {
            using (var devicePilot = new DevicePilot())
            {
                Dictionary <string, string> persistantVariables = new Dictionary <string, string>();

                var isOk = devicePilot.StartDevice(deviceTarget, packagePath, appiumServerIp, appiumPort, aaptPath);
                if (!isOk)
                {
                    Console.WriteLine("Error opening device !");
                    Console.ReadKey();
                    return;
                }

                foreach (LocalStep step in stepList)
                {
                    Console.WriteLine($"Play STEP: command:{step.Command} target:{step.Target} value:{step.Value}");
                    string stepValue;
                    var    ret = devicePilot.ExecuteCommand(step.Command, step.Target, step.Value, step.Condition, step.TimedOutValue, ref persistantVariables, out stepValue);
                    if (!ret.isOk)
                    {
                        Console.WriteLine($"Error! Message: {ret.message} Result Value:{ret.resultValue}");
                        devicePilot.Dispose();
                        Console.ReadKey();
                        return;
                    }
                    Console.WriteLine("OK! " + ret.message);
                    Thread.Sleep(step.TimeBetweenSteps ?? 5 * 1000);
                }
            }
            Console.WriteLine("Finished without any error !");
            Console.ReadKey();
        }
        public async Task SHOULD_trace_extracted_notification()
        {
            //Arrange
            _target = DeviceTarget.iOS("pnsHandle");

            //Act
            await Sut.SendNotificationToTargetAsync(_pushNotification, _target, MockNotificationHub.Object);

            //Assert
            MockAnalyticsService.VerifyTrace("Native push notification extracted");
            MockAnalyticsService.VerifyTraceProperty(_iosNotification.GetType().Name, _iosNotification);
        }
        public async Task SHOULD_extract_notification_for_target_platform_and_send_to_target_pnsHandle()
        {
            //Arrange
            _target = DeviceTarget.iOS("pnsHandle");

            //Act
            await Sut.SendNotificationToTargetAsync(_pushNotification, _target, MockNotificationHub.Object);

            //Assert
            MockNativeNotificationExtractor.Mock.Verify(x => x.ExtractNotification(RuntimePlatform.iOS, _pushNotification));
            MockNotificationHubClientProxy.Mock.Verify(x => x.SendDirectNotificationAsync(_iosNotification, It.Is <List <string> >(y =>
                                                                                                                                   y[0] == "pnsHandle")));
        }
        public override void SetUp()
        {
            base.SetUp();
            _iosNotification = new AppleNotification("{}");
            MockNativeNotificationExtractor.Where_ExtractNotification_returns(new NativeNotification(_iosNotification));

            _pushNotification = new PushNotificationMockBuilder()
                                .With(x => x.Name, "TestNotificationType")
                                .With(x => x.Title, "News Alert")
                                .With(x => x.Body, "The lockdown is only in your mind")
                                .With(x => x.DataProperties, new Dictionary <string, object>
            {
                { "FavouriteColour", "Red" },
                { "FavouriteBand", "The Beatles" },
                { "Id", _id },
            }).Object;

            _target = DeviceTarget.Android("pnsHandle");
        }
Exemple #5
0
        /// <summary>
        ///
        /// Play a scenario on a local device (or emulator)
        ///
        /// Prerequisite:
        ///
        /// ANDROID:
        ///
        ///     Intalled:
        ///         - NodeJS & appium
        ///         - Android: Android Studio with emulator
        ///
        /// TO DO iOS:
        ///
        ///     Intalled:
        ///         - NodeJS & appium
        ///         - iOS: XCode with simulator
        ///
        ///
        /// Start android emulator: cmd /k "emulator.exe -netdelay none -netspeed full -avd GALAXYS7API24"
        /// Start appium
        ///
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

            Configuration = builder.Build();

            var scriptPath  = Configuration.GetValue <string>("ScriptPath");
            var packagePath = Configuration.GetValue <string>("PackagePath");

            var appiumServerIp = Configuration.GetValue <string>("AppiumServerIp");
            var appiumPort     = Configuration.GetValue <int>("AppiumPort");
            var aaptPath       = Configuration.GetValue <string>("AaptPath");

            var deviceTarget = new DeviceTarget();

            Configuration.Bind("DeviceTarget", deviceTarget);

            var stepList = ScriptParser.GetStepListFromScript(scriptPath);

            PlayOnDevice(stepList, deviceTarget, packagePath, appiumServerIp, appiumPort, aaptPath);
        }
Exemple #6
0
        /// <summary>
        ///
        /// Play a scenario on a local device (or emulator)
        ///
        /// Prerequisite:
        ///
        /// ANDROID:
        ///
        ///     Intalled:
        ///         - NodeJS & appium
        ///         - Android: Android Studio with emulator
        ///
        /// TO DO iOS:
        ///
        ///     Intalled:
        ///         - NodeJS & appium
        ///         - iOS: XCode with simulator
        ///
        ///
        /// Start android emulator: cmd /k "emulator.exe -netdelay none -netspeed full -avd GALAXYS7API24"
        /// Start appium
        ///
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            var dataDir = Configuration.GetValue <string>("DataDir");

            var scriptPath  = Path.Combine(dataDir, Configuration.GetValue <string>("ScriptFile"));
            var packagePath = Path.Combine(dataDir, Configuration.GetValue <string>("PackageFile"));

            var buildToolsVersion = Configuration.GetValue <string>("ANDROID_BUILD_TOOLS_VERSION");
            var aaptPath          = Path.Combine(Configuration.GetValue <string>("ANDROID_HOME"), "build-tools", $"{buildToolsVersion}", "aapt.exe");

            CheckFileExists(scriptPath);
            CheckFileExists(packagePath);
            CheckFileExists(aaptPath);

            var appiumServerHost = Configuration.GetValue <string>("AppiumHost");
            var appiumPort       = Configuration.GetValue <int>("AppiumPort", 4723);

            var deviceTarget = new DeviceTarget();

            Configuration.Bind("DeviceTarget", deviceTarget);

            var stepList = ScriptParser.GetStepListFromScript(scriptPath);

            var report     = PlayOnDevice(stepList, deviceTarget, packagePath, appiumServerHost, appiumPort, aaptPath);
            var reportPath = Path.Combine(dataDir, Guid.NewGuid().ToString("N") + ".json");

            File.WriteAllText(reportPath, JsonConvert.SerializeObject(report, Formatting.Indented));
            Console.Write($"Run report written to {reportPath}");
        }
Exemple #7
0
        private static IEnumerable <StepResult> PlayOnDevice(IEnumerable <LocalStep> stepList, DeviceTarget deviceTarget, string packagePath, string appiumServerIp, int appiumPort, string aaptPath)
        {
            using (var devicePilot = new DevicePilot())
            {
                var isOk = devicePilot.StartDevice(deviceTarget, packagePath, appiumServerIp, appiumPort, aaptPath);
                if (!isOk)
                {
                    Console.WriteLine("Error opening device !");
                    return(Enumerable.Empty <StepResult>());
                }

                var persistantVariables = new Dictionary <string, string>();
                var report = new List <StepResult>();
                int stepId = 0;
                foreach (LocalStep step in stepList)
                {
                    Console.WriteLine($"Play STEP: command:{step.Command} target:{step.Target} value:{step.Value}");
                    string stepValue;
                    var    ret = devicePilot.ExecuteCommand(step.Command, step.Target, step.Value, step.Condition, step.TimedOutValue, ref persistantVariables, out stepValue);

                    report.Add(new StepResult()
                    {
                        Command     = step.Command,
                        Target      = step.Target,
                        Value       = stepValue,
                        Message     = ret.message,
                        ResultValue = ret.resultValue.ToString(),
                        StepId      = stepId++
                    });

                    if (!ret.isOk)
                    {
                        Console.WriteLine($"Error! Message: {ret.message} Result Value:{ret.resultValue}");
                        return(report);
                    }
                    else
                    {
                        Console.WriteLine("OK! " + ret.message);
                        Thread.Sleep(step.TimeBetweenSteps ?? 5 * 1000);
                    }
                }

                Console.WriteLine("Finished without any error !");
                return(report);
            }
        }
 public AndroidDriverBuilder DeviceTarget(DeviceTarget deviceTarget)
 {
     _deviceTarget = deviceTarget;
     return(this);
 }
 private static string GetPlatformVersion(DeviceTarget deviceTarget)
 {
     return(deviceTarget.VersionMajor + "." + deviceTarget.VersionMinor + (deviceTarget.VersionSubminor != "" ? "." + deviceTarget.VersionSubminor : ""));
 }
Exemple #10
0
 public DeviceTargetInfo(Stream stream)
     : base(stream)
 {
     DeviceTarget = (DeviceTarget)stream.ReadInt32BigE();
 }