Пример #1
0
        private bool Do(Point point, bool suppressExceptionsIntoResult, TestState testState)
        {
            foreach (var step in point.TestSteps)
            {
                point.RunOk = true;

                if (!suppressExceptionsIntoResult)
                {
                    testState = ExecuteTestStep(point, step, testState);
                }
                else
                {
                    try
                    {
                        testState = ExecuteTestStep(point, step, testState);
                    }

                    catch (Exception e)
                    {
                        step.Result = e is TestCaseException?TestStepResult.Failed(e.Message) : TestStepResult.ImplementationError(e);

                        step.Result.RefToScreenshot = ErrorCollector.GetReferenceToAttachmentIfApplicable(testState);
                        step.Result.SetException(e);
                        point.RunOk = false;
                        break;
                    }
                }

                if (!step.Result.Success)
                {
                    step.Result.RefToScreenshot = ErrorCollector.GetReferenceToAttachmentIfApplicable(testState);
                    point.RunOk = false;
                    break;
                }
            }

            bool cleanupSucceeded = true;

            for (var i = point.TestSteps.Count - 1; i >= 0; i--)
            {
                var step = point.TestSteps[i];
                try
                {
                    CleanupTestStep(point, step, testState);
                }
                catch (Exception e)
                {
                    Log.Info($"Cleanup Failed for Point {point.Id} in Step {step.StepIndex}: {e.Message}");
                    cleanupSucceeded = false;
                }
            }

            return(cleanupSucceeded);
        }
        private async Task <TechnicalOutcome> Do(Point point, bool suppressExceptionsIntoResult, TestState testState, int testCaseId, CancellationToken cancelToken)
        {
            foreach (var step in point.TestSteps)
            {
                if (cancelToken.IsCancellationRequested)
                {
                    break;
                }
                point.RunOk = true;

                if (!suppressExceptionsIntoResult)
                {
                    testState = await ExecuteTestStep(point, step, testState, cancelToken);
                }
                else
                {
                    try
                    {
                        testState = await ExecuteTestStep(point, step, testState, cancelToken);
                    }

                    catch (WebDriverException we) when(we.Message.Contains("Variable Resource Not Found"))
                    {
                        LogRunAgainException(we, testCaseId);
                        return(TechnicalOutcome.RunAgain);
                    }

                    catch (WebDriverException we) when(we.Message.Contains("Only one usage of each socket address"))
                    {
                        LogRunAgainException(we, testCaseId);
                        return(TechnicalOutcome.RunAgain);
                    }

                    catch (WebDriverException we)
                        when(
                            we.Message.Contains("The HTTP request to the remote WebDriver server for URL") &&
                            we.Message.Contains("timed out"))
                        {
                            LogRunAgainException(we, testCaseId);
                            return(TechnicalOutcome.RunAgain);
                        }

                    catch (NoSuchWindowException we)
                    {
                        LogRunAgainException(we, testCaseId);
                        return(TechnicalOutcome.RunAgain);
                    }

                    catch (FailureToStartTestException we)
                    {
                        LogRunAgainException(we, testCaseId);
                        return(TechnicalOutcome.RunAgain);
                    }

                    catch (InvalidOperationException we) when(we.Message.Contains("unable to send message to renderer"))
                    {
                        LogRunAgainException(we, testCaseId);
                        return(TechnicalOutcome.RunAgain);
                    }

                    catch (Exception e)
                    {
                        step.Result = e is TestCaseException?TestStepResult.Failed(e.Message) : TestStepResult.ImplementationError(e);

                        step.Result.RefToScreenshot = ErrorCollector.GetReferenceToAttachmentIfApplicable(testState);
                        Console.WriteLine("For point in testcase " + point.Id + "; screenshot uploaded to " + step.Result.RefToScreenshot);
                        step.Result.SetException(e);
                        point.RunOk = false;
                        _logger.Error(e);

                        break;
                    }
                }


                if (!step.Result.Success)
                {
                    step.Result.RefToScreenshot = ErrorCollector.GetReferenceToAttachmentIfApplicable(testState);
                    Console.WriteLine("For point in testcase " + point.Id + "; screenshot uploaded to " + step.Result.RefToScreenshot);
                    point.RunOk = false;
                    break;
                }
            }

            for (var i = point.TestSteps.Count - 1; i >= 0; i--)
            {
                var step = point.TestSteps[i];
                try
                {
                    CleanupTestStep(point, step, testState);
                }
                catch (Exception e)
                {
                    _logger.Error($"Cleanup Failed for Point {point.Id} in Step {step.StepIndex} of TC {testCaseId}: {e.Message}");
                }
            }

            return(TechnicalOutcome.Ok);
        }