示例#1
0
        protected override Response Execute(string driverCommandToExecute, Dictionary <string, object> parameters)
        {
            bool logResponse = false;

            if (!driverCommandToExecute.Contains("newSession") && !driverCommandToExecute.Contains("setTimeouts") && !driverCommandToExecute.Contains("screenshot"))
            {
                if (parameters != null)
                {
                    TestLogs.Write($"Server Request => [{driverCommandToExecute}] with parameters:");
                    foreach (KeyValuePair <string, object> parameter in parameters)
                    {
                        TestLogs.Write($"[{parameter.Key}" + " : " + $"{parameter.Value.ToString()}]");
                    }
                }
                else
                {
                    TestLogs.Write($"Server Request => [{driverCommandToExecute}].");
                }
                logResponse = true;
            }
            Response result = base.Execute(driverCommandToExecute, parameters);

            if (logResponse)
            {
                TestLogs.Write($"Server Response:\n[{result.ToJson()}]");
            }
            return(result);
        }
 private void LogOverrideSetCapability(KeyValuePair <string, object> capability, ICapabilities caps)
 {
     if (caps.HasCapability(capability.Key))
     {
         TestLogs.Write($"Overriding Capability, Key:[{capability.Key}], OldValue:[{caps.GetCapability(capability.Key)}], NewValue:[{capability.Value}]");
         return;
     }
     TestLogs.Write($"New Capability, Key:[{capability.Key}], Value:[{capability.Value}]");
 }
 private void LogOverrideSetCapability(KeyValuePair <string, object> capability, Dictionary <string, object> existingCapabilities)
 {
     if (existingCapabilities.ContainsKey(capability.Key))
     {
         TestLogs.Write($"Overriding Capability, Key:[{capability.Key}], OldValue:[{existingCapabilities[capability.Key]}], NewValue:[{capability.Value}]");
         return;
     }
     TestLogs.Write($"New Capability, Key:[{capability.Key}], Value:[{capability.Value}]");
 }
 /// <summary>
 /// Exception Wrapper creating driver
 /// </summary>
 /// <param name="method">method to execute inside the wrapper</param>
 /// <returns></returns>
 private static AppiumDriver <AppiumWebElement> GetDriver(Func <AppiumDriver <AppiumWebElement> > method)
 {
     try {
         return(method());
     } catch (Exception e) {
         TestLogs.Write(e.ToString());
         throw new WebDriverException($"Cannot Create Driver Instance. Exception:\n{e}");
     }
 }
 private void RefreshCapabilities()
 {
     if (!isCapabilityRefreshNeeded)
     {
         return;
     }
     TestLogs.Write("Runsetting parameter change detected,Refreshing set capabilities now !!!");
     this.options = null;
     SetupBaseCapabilities();
 }
 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");
 }
        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!!");
            });
        }