コード例 #1
0
ファイル: Model.cs プロジェクト: NunoMamede/WebPageAutomator
        // Método principal, responsável pela execução de todos os test steps do test case
        public void startTestCase(TestCase testCase)
        {
            messageRegistry.addLine("Beggining test case");

            //log.Info("Beggining test case");

            string imagePath = "";

            // Instancia objeto da classe TestStepExecutor que será responsável pelas execuções dos test steps
            TestStepExecutor executor = new TestStepExecutor();

            try {
                // Executa todos os test steps
                foreach (TestStep testStep in testCase.TestSteps)
                {
                    // Executa o test step individualmente
                    executor.executeTestStep(messageRegistry, testStep);

                    // se for o último test step tira screenshot
                    if (testStep.Order == testStep.Count)
                    {
                        imagePath = executor.takeScreenshot(messageRegistry);
                    }
                }

                messageRegistry.addLine("Ending test case. Returning results to view");

                // Cria resultado de sucesso e com a informação para o logger
                Result result = new Result(Status.Passed, "Test case concluded with success." + messageRegistry.Messages, imagePath);

                // Envia resultado para a view
                OnCallView(result);
            } catch (TestStepException e) {
                //log.Error(e.GetBaseException());

                // Cria resultado de insucesso com a informação da exceção e do logger
                Result result = new Result(Status.Failed, "Test case failed. Cause: " + e.GetBaseException().ToString() + messageRegistry.Messages, "");

                // Envia resultado para a view
                OnCallView(result);
            } catch (Exception e) {
                // Cria resultado de erro com a informação da exceção e do logger
                Result result = new Result(Status.Error, "Internal Error. Cause: " + e.GetBaseException().ToString() + messageRegistry.Messages, "");

                // Envia resultado para a view
                OnCallView(result);
            }
        }