Esempio n. 1
0
        public void RunBuild(BuildReport buildReport)
        {
            buildReport.BuildDefinitionName = Name;
            buildReport.StartedAt = DateTime.UtcNow;

            foreach (var step in Steps)
            {
                var stepReport = new StepReport();

                try
                {
                    step.Execute(stepReport);

                    if(string.IsNullOrWhiteSpace(step.Summary) == false)
                        stepReport.Summary = this.CreateReport(step.Summary, stepReport.Report);
                }
                catch (Exception exception)
                {
                    stepReport.Error = exception;
                }

                stepReport.FinishedAt = DateTime.UtcNow;
                buildReport.AddStepReport(stepReport);
            }

            buildReport.FinishedAt = DateTime.UtcNow;
        }
Esempio n. 2
0
        public StepReport RunStep(TaskStep step)
        {
            var stepReport = new StepReport()
            {
                Name = step.DisplayName
            };

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            try
            {
                step.Run();

                stepReport.Succeed = true;
            }
            catch (Exception e)
            {
                stepReport.Error   = e;
                stepReport.Succeed = false;

                Console.WriteLine(e);
            }
            finally
            {
                stepReport.Time = stopWatch.Elapsed;
                stopWatch.Stop();
            }

            return(stepReport);
        }
Esempio n. 3
0
        /// <summary>
        /// Converts the specified <see cref="StepReport"/> to the corresponding JUnit <see cref="testsuiteTestcase"/>.
        /// </summary>
        /// <param name="stepReport">The <see cref="StepReport"/> instance contains the data of a GUI test step.</param>
        /// <param name="index">The index, starts from 0, to identify the order of the testcases.</param>
        /// <returns>The converted JUnit <see cref="testsuiteTestcase"/> instance.</returns>
        public static testsuiteTestcase ConvertTestcase(StepReport stepReport, int index)
        {
            // the step might be a checkpoint
            CheckpointReport checkpointReport = CheckpointReport.FromStepReport(stepReport);

            if (checkpointReport != null)
            {
                return(ConvertTestcase(checkpointReport, index));
            }

            // a step with smart identification?
            if (stepReport.SmartIdentification != null)
            {
                return(ConvertTestcaseWithSmartIdentificationInfo(stepReport, index));
            }

            // a general step
            testsuiteTestcase tc = new testsuiteTestcase();

            tc.name      = string.Format("#{0,5:00000}: {1}", index + 1, stepReport.Name);
            tc.classname = stepReport.TestObjectPath;
            tc.time      = stepReport.DurationSeconds;

            if (stepReport.Status == ReportStatus.Failed)
            {
                testsuiteTestcaseFailure failure = new testsuiteTestcaseFailure();
                failure.message = stepReport.ErrorText;
                failure.type    = string.Empty;
                tc.Item         = failure;
            }

            return(tc);
        }
Esempio n. 4
0
        /// <summary>
        /// Sends a <see cref="StepReport"/> to the Agent.
        /// </summary>
        /// <param name="stepReport">The payload object containing the step details to be reported.</param>
        public void ReportStep(StepReport stepReport)
        {
            RestRequest sendStepReportRequest = new RestRequest(Endpoints.REPORT_STEP, Method.POST);

            sendStepReportRequest.RequestFormat = DataFormat.Json;

            string json = CustomJsonSerializer.ToJson(stepReport, this.serializerSettings);

            sendStepReportRequest.AddJsonBody(json);

            this.reportsQueue.Submit(sendStepReportRequest, stepReport);
        }
Esempio n. 5
0
        private static testsuiteTestcase ConvertTestcaseWithSmartIdentificationInfo(StepReport stepReport, int index)
        {
            SmartIdentificationInfoExtType sid = stepReport.SmartIdentification;

            if (sid == null)
            {
                throw new ArgumentNullException("stepReport.SmartIdentification");
            }

            if (stepReport.Status == ReportStatus.Warning)
            {
                // a step with smart identification info and warning status can be ignored
                // since the next step is the official smart identification info report node
                _lastSkippedSIDStep = stepReport;
                return(null);
            }

            // a step with smart identification info
            int basicMatches = 0;

            if (sid.SIDBasicProperties != null)
            {
                basicMatches = sid.SIDBasicProperties.BasicMatch;
            }

            List <string> optList = new List <string>();

            if (sid.SIDOptionalProperties != null)
            {
                foreach (SIDOptionalPropertyExtType property in sid.SIDOptionalProperties)
                {
                    if (property.Matches > 0)
                    {
                        optList.Add(string.Format("{0}=\"{1}\"", property.Name, property.Value));
                    }
                }
            }
            string sidDesc = string.Format(Properties.Resources.GUITest_SID_Description, basicMatches, string.Join(", ", optList));
            string sidName = stepReport.Node.Data.Name;

            testsuiteTestcase tc = new testsuiteTestcase();

            tc.name      = string.Format("#{0,5:00000}: {1} ({2})", index + 1, sidName, sidDesc);
            tc.classname = stepReport.TestObjectPath;
            tc.time      = stepReport.DurationSeconds + (_lastSkippedSIDStep != null ? _lastSkippedSIDStep.DurationSeconds : 0);

            // clear last skipped SID step
            _lastSkippedSIDStep = null;

            return(tc);
        }
Esempio n. 6
0
        /// <summary>
        /// Reports steps and tests to the Agent.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="eventArgs">Arguments passed to the event.</param>
        private void RuntimePluginTestExecutionLifecycleEvents_AfterStep(object sender, RuntimePluginAfterStepEventArgs eventArgs)
        {
            if (AgentClient.IsInitialized())
            {
                ScenarioContext context = eventArgs.ObjectContainer.Resolve <ScenarioContext>();

                string scenarioTitle;

                if (context.ScenarioInfo.Arguments.Count > 0)
                {
                    // If a scenario has arguments, it means it is an example from a Scenario Outline
                    // Similar to what SpecFlow itself does, we append the value from the first argument
                    // to the name of the current scenario to uniquely identify it
                    scenarioTitle = $"{context.ScenarioInfo.Title} [{context.ScenarioInfo.Arguments[0]}]";
                }
                else
                {
                    // If a scenario does not have arguments, we consider it to be a 'regular' scenario
                    // In this case, we use the Scenario title as the name of the test
                    scenarioTitle = context.ScenarioInfo.Title;
                }

                // Create a preliminary test report in the AgentClient (will not be reported until AgentClient is stopped).
                AgentClient.GetInstance().SpecFlowTestReport = new TestReport(scenarioTitle, true, context.ScenarioInfo.Description);

                string stepText = $"{context.StepContext.StepInfo.StepDefinitionType} {context.StepContext.StepInfo.Text}";

                StepReport stepReport;

                if (context.TestError == null)
                {
                    stepReport = new StepReport(stepText, context.StepContext.StepInfo.MultilineText, true, null);
                }
                else
                {
                    stepReport = new StepReport(stepText, context.TestError.Message, false, null);
                }

                AgentClient.GetInstance().ReportStep(stepReport);
            }
            else
            {
                string message = $"No active Agent development session found. Please ensure that you have an instance of a TestProject OpenSDK driver running.\n" +
                                 $"More information on how to do that can be found in the README at https://github.com/testproject-io/csharp-opensdk";

                Logger.Error(message);
                throw new NoActiveDriverFoundException(message);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a step report and sends it to the <see cref="AgentClient"/>.
        /// </summary>
        /// <param name="description">The description of the step.</param>
        /// /// <param name="message">A message that goes with the step.</param>
        /// <param name="passed">True if the step should be marked as passed, false otherwise.</param>
        /// <param name="screenshot">True if a screenshot should be attached to the step, false otherwise.</param>
        public void Step(string description, string message = null, bool passed = true, bool screenshot = false)
        {
            // Check whether it is necessary to report a test, too, and if so, do that.
            this.reportingCommandExecutor.ReportTest(false);

            if (!this.reportingCommandExecutor.ReportsDisabled)
            {
                string screenshotAsString = screenshot ? this.reportingCommandExecutor.GetScreenshot() : null;

                StepReport stepReport = new StepReport(description, message, passed, screenshotAsString);

                AgentClient.GetInstance().ReportStep(stepReport);
            }
            else
            {
                Logger.Trace($"Step '{description}' {(passed ? "passed" : "failed")}");
            }
        }
        /// <summary>
        /// Report a failed step and test to TestProject when SpecFlow scenario execution produces an error.
        /// </summary>
        /// <param name="ex">The exception that was thrown during SpecFlow scenario execution.</param>
        public new void TraceError(Exception ex)
        {
            if (AgentClient.IsInitialized())
            {
                StepReport stepReport = new StepReport(TestProjectStepContext.CurrentStep, ex.Message, false, null);
                AgentClient.GetInstance().ReportStep(stepReport);

                // Create a preliminary test report in the AgentClient (will not be reported until AgentClient is stopped).
                AgentClient.GetInstance().SpecFlowTestReport = new TestReport(TestProjectStepContext.CurrentScenario, false, null);
            }
            else
            {
                string errorMessage = "No active Agent development session found.";

                Logger.Error(errorMessage);
                throw new AgentConnectException(errorMessage);
            }

            base.TraceError(ex);
        }
        /// <summary>
        /// Report a passed step to TestProject when the SpecFlow step finishes executing.
        /// </summary>
        /// <param name="match">The step definition binding that was executed.</param>
        /// <param name="arguments">The step definitions arguments that were used.</param>
        /// <param name="duration">The duration of the step execution.</param>
        public new void TraceStepDone(BindingMatch match, object[] arguments, TimeSpan duration)
        {
            if (AgentClient.IsInitialized())
            {
                // Create a preliminary test report in the AgentClient (will not be reported until AgentClient is stopped).
                AgentClient.GetInstance().SpecFlowTestReport = new TestReport(TestProjectStepContext.CurrentScenario, true, null);

                string message = $"Step execution time: {duration}";

                StepReport stepReport = new StepReport(TestProjectStepContext.CurrentStep, message, true, null);
                AgentClient.GetInstance().ReportStep(stepReport);
            }
            else
            {
                string errorMessage = "No active Agent development session found.";

                Logger.Error(errorMessage);
                throw new AgentConnectException(errorMessage);
            }

            base.TraceStepDone(match, arguments, duration);
        }
Esempio n. 10
0
        /// <summary>
        /// Send an executed WebDriver command to the Agent.
        /// </summary>
        /// <param name="command">The WebDriver command that was executed.</param>
        /// <param name="result">The result of the command execution.</param>
        /// <param name="passed">True if command execution was successful, false otherwise.</param>
        private void SendCommandToAgent(Command command, object result, bool passed)
        {
            if (this.ReportsDisabled || this.CommandReportsDisabled.Equals(DriverCommandsFilter.All))
            {
                Logger.Trace($"Command '{command.Name}' {(passed ? "passed" : "failed")}");
                return;
            }

            if (this.CommandReportsDisabled.Equals(DriverCommandsFilter.Passing) && !passed)
            {
                // Report failed driver commands in a user friendly way if explicitly requested by the user
                StepReport stepReport = new StepReport(
                    description: $"Failed to execute driver command '{command.Name}'",
                    message: result.ToJson(),
                    passed: false,
                    screenshot: this.GetScreenshot());

                AgentClient.GetInstance().ReportStep(stepReport);
                return;
            }

            if (this.CommandReportsDisabled.Equals(DriverCommandsFilter.None))
            {
                if (!this.RedactionDisabled)
                {
                    command = RedactHelper.RedactCommand(this.commandExecutor, command);
                }

                DriverCommandReport driverCommandReport = new DriverCommandReport(command.Name, command.Parameters, result, passed);

                if (!passed)
                {
                    driverCommandReport.Screenshot = this.GetScreenshot();
                }

                AgentClient.GetInstance().ReportDriverCommand(driverCommandReport);
            }
        }
Esempio n. 11
0
 internal void Execute(StepReport stepReport)
 {
     stepReport.Report = this.Execute();
 }