public virtual void TestSetup()
 {
     //Start driver service
     DriverService.Start(this.TestEnvironmentParameters);
     //Merge user provided options to existing default capabilities.
     Capabilities.MergeCapabilities(RunParameterUpdater);
     // Write Runsettings to log file
     TestLogs.WriteLogSection("Original Test Run Parameters", () => TestLogs.Write(this.TestEnvironmentParameters.ToString()));
     WebDriver.Initialize(Capabilities);
     //Write device configuration to log file
     TestLogs.WriteLogSection("DUT Configuration", () => TestLogs.Write(WebDriver.Instance.Capabilities.ToString()));
     WebTestContext.Set(Constants.TestEnvironmentKey, TestEnvironmentParameters);
     TestLogs.AddSection($"Test {TestContext.CurrentContext.Test.Name} Starts");
 }
 /// <summary>
 /// Set additional capabilities on driver
 /// </summary>
 /// <param name="additionalCapability">key value pair for additional capabilities.</param>
 internal void SetAdditionalOptions(Dictionary <string, object> additionalCapability = null)
 {
     if (additionalCapability != null && additionalCapability.Count > 0)
     {
         //Log Section
         TestLogs.WriteLogSection("Test Specific Capabilities",
                                  () => {
             foreach (KeyValuePair <string, object> capability in additionalCapability)
             {
                 LogOverrideSetCapability(capability, options.ToDictionary());
                 options.AddAdditionalCapability(capability.Key, capability.Value);
             }
         });
     }
 }
        internal void OverrideRunSettingsParams(RunParameterUpdater @params)
        {
            TestLogs.WriteLogSection("Overriding RunSettings",
                                     () => {
                foreach (KeyValuePair <string, object> runSetting in @params.Get().Where(k => k.Key.Contains("RS_")))
                {
                    System.Reflection.PropertyInfo contextProperty = this.context.GetType().GetProperty(runSetting.Key);
                    if (contextProperty != null && contextProperty.CanWrite)
                    {
                        contextProperty.SetValue(this.context, runSetting.Value);
                        isCapabilityRefreshNeeded = true;
                        TestLogs.Write($"Overriding RunSettings Key: [{runSetting.Key}], New Value = [{runSetting.Value}]");
                    }
                }
            });

            RefreshCapabilities();
        }
 public virtual void TestSetup()
 {
     //Start the service if needed
     AppiumServer.Start(TestEnvironmentParameters);
     //Set user provided options.
     MobileTestContext.Set(Constants.AppiumAdditionalOptionsKey, AdditionalCapabilities);
     Capabilities = new DriverCapabilities(TestEnvironmentParameters);
     //Merge user provided options to existing default capabilities.
     Capabilities.MergeCapabilities(MobileTestContext.Get <AdditionalDriverOptions>(Constants.AppiumAdditionalOptionsKey, false));
     // Write Runsettings to log file
     TestLogs.WriteLogSection("Original Test Run Parameters", () => TestLogs.Write(this.TestEnvironmentParameters.ToString()));
     MobileDriver.Initialize(Capabilities);
     //Write device configuration to log file
     TestLogs.WriteLogSection("DUT Configuration", () => TestLogs.Write(MobileDriver.Instance.Capabilities.ToString()));
     //Capture enviroment parameters for all futures uses.
     MobileTestContext.Set(Constants.TestEnvironmentKey, TestEnvironmentParameters);
     TestLogs.AddSection($"Test {TestContext.CurrentContext.Test.Name} Starts");
 }
        private void OverrideRunSettingsParams(AdditionalDriverOptions driverOptions)
        {
            TestLogs.WriteLogSection("Overriding RunSettings",
                                     () => {
                foreach (KeyValuePair <string, object> runSetting in driverOptions.GetCapabilities().Where(k => k.Key.Contains("RS_")))
                {
                    System.Reflection.PropertyInfo contextProperty = this.context.GetType().GetProperty(runSetting.Key);
                    if (contextProperty != null && contextProperty.CanWrite)
                    {
                        if (contextProperty.PropertyType == typeof(ApplicationType))
                        {
                            contextProperty.SetValue(this.context, (ApplicationType)Enum.Parse(typeof(ApplicationType), runSetting.Value.ToString()));
                            isCapabilityRefreshNeeded = true;
                            continue;
                        }
                        contextProperty.SetValue(this.context, runSetting.Value);
                        isCapabilityRefreshNeeded = true;
                        TestLogs.Write($"Overriding RunSettings Key: [{runSetting.Key}], New Value = [{runSetting.Value}]");
                    }
                }
            });

            RefreshCapabilities();
        }
        /// <summary>
        /// Basic checks since all capabilities have been set
        /// </summary>
        internal void PreReqChecks()
        {
            Dictionary <string, object> caps = options.ToDictionary();
            object values;

            TestLogs.WriteLogSection("Prerequisite Checks", () => {
                TestLogs.Write("Starting checks...");
                if (this.isNativeApp || this.isHybridApp)
                {
                    //Browser should be null
                    if (caps.TryGetValue(MobileCapabilityType.BrowserName, out values))
                    {
                        if (!Helper.IsNullOrEmpty(values.ToString(), false))
                        {
                            throw new InvalidCapabilityException($"Capability combination: [{MobileCapabilityType.BrowserName}] = [{values?.ToString()}] is invalid for application type [{this.context.RS_AppType}]");
                        }
                    }
                    values = null;
                    //Check App package or AppActivity is set or not
                    if (this.context.RS_DeviceGroup.Contains("ANDROID", StringComparison.OrdinalIgnoreCase))
                    {
                        if (caps.TryGetValue(AndroidMobileCapabilityType.AppPackage, out values))
                        {
                            if (values == null || values.Equals("io.android.testapp"))
                            {
                                throw new InvalidCapabilityException($"Capability combination: [{AndroidMobileCapabilityType.AppPackage}] = [{values?.ToString()}] is invalid for application type [{this.context.RS_AppType}]");
                            }
                        }
                        values = null;

                        if (caps.TryGetValue(AndroidMobileCapabilityType.AppActivity, out values))
                        {
                            if (values == null || values.Equals(".HomeScreenActivity"))
                            {
                                throw new InvalidCapabilityException($"Capability combination: [{AndroidMobileCapabilityType.AppActivity}] = [{values?.ToString()}] is invalid for application type [{this.context.RS_AppType}]");
                            }
                        }
                        values = null;
                    }
                    if (this.context.RS_DeviceGroup.Contains("IOS", StringComparison.OrdinalIgnoreCase))
                    {
                        if (caps.TryGetValue(IOSMobileCapabilityType.BundleId, out values))
                        {
                            if (values == null || values.Equals("io.android.testapp"))
                            {
                                throw new InvalidCapabilityException($"Capability combination: [{IOSMobileCapabilityType.AppName}] = [{values?.ToString()}] is invalid for application type [{this.context.RS_AppType}]");
                            }
                        }
                    }
                    values = null;
                }
                else     //Web app
                //Browser should not be null
                {
                    if (caps.TryGetValue(MobileCapabilityType.BrowserName, out values))
                    {
                        if (string.IsNullOrEmpty(values.ToString()))
                        {
                            throw new InvalidCapabilityException($"Capability combination: [{MobileCapabilityType.BrowserName}] = [{values?.ToString()}] is invalid for application type [{this.context.RS_AppType}]");
                        }
                    }
                }
                TestLogs.Write("No issues found!!");
            });
        }