//bug in .net core. details: https://stackoverflow.com/questions/46836472/selenium-with-net-core-performance-impact-multiple-threads-in-iwebelement
        public static void FixDriverCommandExecutionDelay(IWebDriver driver)
        {
            PropertyInfo     commandExecutorProperty = typeof(RemoteWebDriver).GetProperty("CommandExecutor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty);
            ICommandExecutor commandExecutor         = (ICommandExecutor)commandExecutorProperty.GetValue(driver);

            FieldInfo remoteServerUriField = commandExecutor.GetType().GetField("remoteServerUri", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField);

            if (remoteServerUriField == null)
            {
                FieldInfo internalExecutorField = commandExecutor.GetType().GetField("internalExecutor", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                commandExecutor      = (ICommandExecutor)internalExecutorField.GetValue(commandExecutor);
                remoteServerUriField = commandExecutor.GetType().GetField("remoteServerUri", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField);
            }

            if (remoteServerUriField != null)
            {
                string remoteServerUri = remoteServerUriField.GetValue(commandExecutor).ToString();

                string localhostUriPrefix = "http://localhost";

                if (remoteServerUri.StartsWith(localhostUriPrefix))
                {
                    remoteServerUri = remoteServerUri.Replace(localhostUriPrefix, "http://127.0.0.1");

                    remoteServerUriField.SetValue(commandExecutor, new Uri(remoteServerUri));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseDriver"/> class.
        /// </summary>
        /// <param name="remoteAddress">The base address for the Agent API (e.g. http://localhost:8585).</param>
        /// <param name="token">The development token used to communicate with the Agent, see <a href="https://app.testproject.io/#/integrations/sdk">here</a> for more info.</param>
        /// <param name="driverOptions">See <see cref="DriverOptions"/> for more details.</param>
        /// <param name="projectName">The project name to report.</param>
        /// <param name="jobName">The job name to report.</param>
        /// <param name="disableReports">Set to true to disable all reporting (no report will be created on TestProject).</param>
        /// <param name="reportType">The report type of the execution, can be local, cloud or both.</param>
        /// <param name="reportName">The name of the local generated report.</param>
        /// <param name="reportPath">The path of the local generated report.</param>
        protected BaseDriver(
            Uri remoteAddress           = null,
            string token                = null,
            DriverOptions driverOptions = null,
            string projectName          = null,
            string jobName              = null,
            bool disableReports         = false,
            ReportType reportType       = ReportType.CLOUD_AND_LOCAL,
            string reportName           = null,
            string reportPath           = null)
            : base(
                AgentClient.GetInstance(remoteAddress, token, driverOptions, new ReportSettings(projectName, jobName, reportType, reportName, reportPath), disableReports).AgentSession.Capabilities)
        {
            this.sessionId = AgentClient.GetInstance().AgentSession.SessionId;

            // Set the session ID for the base driver object to the session ID returned by the Agent.
            FieldInfo sessionIdField = typeof(RemoteWebDriver).GetField("sessionId", BindingFlags.Instance | BindingFlags.NonPublic);

            sessionIdField.SetValue(this, new SessionId(this.sessionId));

            // Create a new command executor for this driver session and set disable reporting flag
            this.commandExecutor = new CustomHttpCommandExecutor(AgentClient.GetInstance().AgentSession.RemoteAddress, disableReports);

            // If the driver returned by the Agent is in W3C mode, we need to update the command info repository
            // associated with the base RemoteWebDriver to the W3C command info repository (default is OSS).
            if (AgentClient.GetInstance().IsInW3CMode())
            {
                FieldInfo        executorField = typeof(RemoteWebDriver).GetField("executor", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance);
                ICommandExecutor executor      = (ICommandExecutor)executorField.GetValue(this);
                FieldInfo        commandInfoRepositoryField = executor.GetType().GetField("commandInfoRepository", BindingFlags.Instance | BindingFlags.NonPublic);
                commandInfoRepositoryField.SetValue(executor, new W3CWireProtocolCommandInfoRepository());
            }

            this.IsRunning = true;

            // Add shutdown hook for gracefully shutting down the driver
            this.driverShutdownThread = new DriverShutdownThread(this);

            if (StackTraceHelper.Instance.TryDetectSpecFlow())
            {
                var report = this.Report();

                if (!StackTraceHelper.Instance.IsSpecFlowPluginInstalled())
                {
                    string message = "TestProject Plugin for SpecFlow is not installed, please install the plugin and run the Test again.";
                    report.Step(description: message, passed: false);
                    Logger.Error(message);
                    this.Stop();
                    throw new SdkException(message);
                }

                report.DisableCommandReports(DriverCommandsFilter.All);
                report.DisableAutoTestReports(true);
                Logger.Info("SpecFlow detected, applying SpecFlow-specific reporting settings...");
            }

            instance = this;
        }
        protected void FixDriverCommandExecutionDelay(IWebDriver driver)
        {
            try
            {
                PropertyInfo     commandExecutorProperty = typeof(RemoteWebDriver).GetProperty("CommandExecutor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty);
                ICommandExecutor commandExecutor         = (ICommandExecutor)commandExecutorProperty.GetValue(driver);

                FieldInfo remoteServerUriField = commandExecutor.GetType().GetField("remoteServerUri", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField);

                if (remoteServerUriField == null)
                {
                    FieldInfo internalExecutorField = commandExecutor.GetType().GetField("internalExecutor", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                    commandExecutor      = (ICommandExecutor)internalExecutorField.GetValue(commandExecutor);
                    remoteServerUriField = commandExecutor.GetType().GetField("remoteServerUri", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField);
                }

                if (remoteServerUriField != null)
                {
                    string remoteServerUri = remoteServerUriField.GetValue(commandExecutor).ToString();

                    string localhostUriPrefix = "http://localhost";

                    if (remoteServerUri.StartsWith(localhostUriPrefix))
                    {
                        remoteServerUri = remoteServerUri.Replace(localhostUriPrefix, "http://127.0.0.1");

                        remoteServerUriField.SetValue(commandExecutor, new Uri(remoteServerUri));
                    }
                }
            }
            catch (TargetException ex)
            {
                if (ex.Message.Contains("Non-static method requires a target"))
                {
                    FixDriverCommandExecutionDelay(driver);
                }
                else
                {
                    throw;
                }
            }
        }
        private static void FixDriverCommandExecutionDelay(IWebDriver driver)
        {
            try
            {
                PropertyInfo     commandExecutorProperty = GetPropertyWithThrowOnError(typeof(WebDriver), "CommandExecutor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty);
                ICommandExecutor commandExecutor         = (ICommandExecutor)commandExecutorProperty.GetValue(driver);

                FieldInfo GetRemoteServerUriField(ICommandExecutor executor)
                {
                    return(executor.GetType().GetField("remoteServerUri", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField));
                }

                FieldInfo remoteServerUriField = GetRemoteServerUriField(commandExecutor);

                if (remoteServerUriField == null)
                {
                    FieldInfo internalExecutorField = commandExecutor.GetType().GetField("internalExecutor", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                    commandExecutor = (ICommandExecutor)internalExecutorField.GetValue(commandExecutor);

                    ServicesCollection.Current.RegisterInstance(commandExecutor);

                    remoteServerUriField = GetRemoteServerUriField(commandExecutor);
                }

                if (remoteServerUriField != null)
                {
                    string remoteServerUri = remoteServerUriField.GetValue(commandExecutor).ToString();

                    string localhostUriPrefix = "http://localhost";

                    if (remoteServerUri.StartsWith(localhostUriPrefix, StringComparison.Ordinal))
                    {
                        remoteServerUri = remoteServerUri.Replace(localhostUriPrefix, "http://127.0.0.1");

                        remoteServerUriField.SetValue(commandExecutor, new Uri(remoteServerUri));
                    }
                }
            }
            catch (Exception e)
            {
                // Failed to apply fix of command execution delay.
                e.PrintStackTrace();
            }
        }
예제 #5
0
        private static void FixDriverCommandExecutionDelay(RemoteWebDriver driver)
        {
            try
            {
                PropertyInfo     commandExecutorProperty = typeof(RemoteWebDriver).GetPropertyWithThrowOnError("CommandExecutor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty);
                ICommandExecutor commandExecutor         = (ICommandExecutor)commandExecutorProperty.GetValue(driver);

                FieldInfo GetRemoteServerUriField(ICommandExecutor executor)
                {
                    return(executor.GetType().GetField("remoteServerUri", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField));
                }

                FieldInfo remoteServerUriField = GetRemoteServerUriField(commandExecutor);

                if (remoteServerUriField == null)
                {
                    FieldInfo internalExecutorField = commandExecutor.GetType().GetField("internalExecutor", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                    commandExecutor      = (ICommandExecutor)internalExecutorField.GetValue(commandExecutor);
                    remoteServerUriField = GetRemoteServerUriField(commandExecutor);
                }

                if (remoteServerUriField != null)
                {
                    string remoteServerUri = remoteServerUriField.GetValue(commandExecutor).ToString();

                    string localhostUriPrefix = "http://localhost";

                    if (remoteServerUri.StartsWith(localhostUriPrefix))
                    {
                        remoteServerUri = remoteServerUri.Replace(localhostUriPrefix, "http://127.0.0.1");

                        remoteServerUriField.SetValue(commandExecutor, new Uri(remoteServerUri));
                        return;
                    }
                }
            }
            catch (Exception exception)
            {
                AtataContext.Current?.Log?.Error("Failed to apply fix of command execution delay.", exception);
            }

            AtataContext.Current?.Log?.Error("Failed to apply fix of command execution delay.");
        }
예제 #6
0
        // https://github.com/dotnet/corefx/issues/24104
        // https://github.com/atata-framework/atata/issues/101
        // https://github.com/atata-framework/atata/blob/17187282d2ddd356c0195802253513428d3087b4/src/Atata/Context/DriverAtataContextBuilder%601.cs#L65-L107
        private static void FixDriverCommandExecutionDelay(RemoteWebDriver driver)
        {
            PropertyInfo commandExecutorProperty = typeof(RemoteWebDriver).GetProperty("CommandExecutor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty);

            if (commandExecutorProperty == null)
            {
                throw new MissingMemberException(typeof(RemoteWebDriver).FullName, "CommandExecutor");
            }

            ICommandExecutor commandExecutor = (ICommandExecutor)commandExecutorProperty.GetValue(driver);

            FieldInfo GetRemoteServerUriField(ICommandExecutor executor)
            {
                return(executor.GetType().GetField("remoteServerUri", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField));
            }

            FieldInfo remoteServerUriField = GetRemoteServerUriField(commandExecutor);

            if (remoteServerUriField == null)
            {
                FieldInfo internalExecutorField = commandExecutor.GetType().GetField("internalExecutor", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                commandExecutor      = (ICommandExecutor)internalExecutorField.GetValue(commandExecutor);
                remoteServerUriField = GetRemoteServerUriField(commandExecutor);
            }

            if (remoteServerUriField != null)
            {
                string remoteServerUri = remoteServerUriField.GetValue(commandExecutor).ToString();

                string localhostUriPrefix = "http://localhost";

                if (remoteServerUri.StartsWith(localhostUriPrefix))
                {
                    remoteServerUri = remoteServerUri.Replace(localhostUriPrefix, "http://127.0.0.1");

                    remoteServerUriField.SetValue(commandExecutor, new Uri(remoteServerUri));
                    return;
                }
            }

            // https://github.com/SeleniumHQ/selenium/issues/4988
            throw new Exception("Unable to apply fix for issue 4988");
        }
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseDriver"/> class.
        /// </summary>
        /// <param name="remoteAddress">The base address for the Agent API (e.g. http://localhost:8585).</param>
        /// <param name="token">The development token used to communicate with the Agent, see <a href="https://app.testproject.io/#/integrations/sdk">here</a> for more info.</param>
        /// <param name="driverOptions">See <see cref="DriverOptions"/> for more details.</param>
        /// <param name="projectName">The project name to report.</param>
        /// <param name="jobName">The job name to report.</param>
        /// <param name="disableReports">Set to true to disable all reporting (no report will be created on TestProject).</param>
        protected BaseDriver(
            Uri remoteAddress           = null,
            string token                = null,
            DriverOptions driverOptions = null,
            string projectName          = null,
            string jobName              = null,
            bool disableReports         = false)
            : base(
                AgentClient.GetInstance(remoteAddress, token, driverOptions, new ReportSettings(projectName, jobName), disableReports).AgentSession.Capabilities)
        {
            this.sessionId = AgentClient.GetInstance().AgentSession.SessionId;

            // Set the session ID for the base driver object to the session ID returned by the Agent.
            FieldInfo sessionIdField = typeof(RemoteWebDriver).GetField("sessionId", BindingFlags.Instance | BindingFlags.NonPublic);

            sessionIdField.SetValue(this, new SessionId(this.sessionId));

            // Create a new command executor for this driver session and set disable reporting flag
            this.commandExecutor = new CustomHttpCommandExecutor(AgentClient.GetInstance().AgentSession.RemoteAddress, disableReports);

            // If the driver returned by the Agent is in W3C mode, we need to update the command info repository
            // associated with the base RemoteWebDriver to the W3C command info repository (default is OSS).
            if (AgentClient.GetInstance().IsInW3CMode())
            {
                FieldInfo        executorField = typeof(RemoteWebDriver).GetField("executor", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance);
                ICommandExecutor executor      = (ICommandExecutor)executorField.GetValue(this);
                FieldInfo        commandInfoRepositoryField = executor.GetType().GetField("commandInfoRepository", BindingFlags.Instance | BindingFlags.NonPublic);
                commandInfoRepositoryField.SetValue(executor, new W3CWireProtocolCommandInfoRepository());
            }

            this.IsRunning = true;

            // Add shutdown hook for gracefully shutting down the driver
            this.driverShutdownThread = new DriverShutdownThread(this);

            if (StackTraceHelper.Instance.TryDetectSpecFlow())
            {
                Logger.Info("SpecFlow detected, applying SpecFlow-specific reporting settings...");
                this.Report().DisableCommandReports(true);
                this.Report().DisableAutoTestReports(true);
            }
        }
예제 #8
0
 public void BlockInteractions(ICommandExecutor commandExecutor)
 {
     UnblockAllInteractions();
     GetButtonGameObjectByType(commandExecutor.GetType()).GetComponent <Selectable>().interactable = false;
 }