コード例 #1
0
        public static void ExecuteAutoTest(
            AutoTestOperation testOperation,
            IWebDriver driver,
            AutoTestSettings testSettings,
            AutoTestScenario autoTestScenario = null)
        {
            TestAutomationOperate.WriteLog(
                logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                logMessage: $"Parts:{testOperation.TestPartsPath}"
                );
            testOperation.TestParts
            .ForEach(testPart =>
            {
                TestAutomationOperate.WriteLog(
                    logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                    logMessage: $"Action:{testPart.Action}"
                    );

                switch (testPart.Action)
                {
                case ActionTypes.Input:
                    TestAutomationOperate.InputOpe(driver, testPart);
                    break;

                case ActionTypes.Inputs:
                    TestAutomationOperate.InputsOpe(driver, testPart);
                    break;

                case ActionTypes.Clear:
                    TestAutomationOperate.ClearOpe(driver, testPart);
                    break;

                case ActionTypes.Click:
                    TestAutomationOperate.ClickOpe(driver, testPart);
                    break;

                case ActionTypes.Enter:
                    TestAutomationOperate.EnterOpe(driver, testPart);
                    break;

                case ActionTypes.Hover:
                    TestAutomationOperate.HoverOpe(driver, testPart);
                    break;

                case ActionTypes.Create:
                    TestAutomationOperate.CreateOpe(driver, testPart);
                    break;

                case ActionTypes.Update:
                    TestAutomationOperate.UpdateOpe(driver);
                    break;

                case ActionTypes.Delete:
                    TestAutomationOperate.DeleteOpe(driver);
                    break;

                case ActionTypes.Copy:
                    TestAutomationOperate.CopyOpe(driver);
                    break;

                case ActionTypes.Select:
                    TestAutomationOperate.SelectOpe(driver, testPart);
                    break;

                case ActionTypes.AlertAccept:
                    TestAutomationOperate.AlertAccept(driver);
                    break;

                case (ActionTypes.AlertDismiss):
                    TestAutomationOperate.AlertDismiss(driver);
                    break;

                case (ActionTypes.GoToUrl):
                    TestAutomationOperate.GoToUrl(driver, testPart);
                    break;

                case ActionTypes.UploadFile:
                    TestAutomationOperate.UploadFileOpe(driver, testPart);
                    break;

                case ActionTypes.WaitingAlertSuccess:
                    TestAutomationOperate.WaitingAlertSuccess(driver);
                    break;

                case ActionTypes.WaitingAlertError:
                    TestAutomationOperate.WaitingAlertError(driver);
                    break;

                case ActionTypes.Script:
                    TestAutomationOperate.Script(driver, testPart);
                    break;

                case ActionTypes.ResultCheck:
                    break;
                }
                Thread.Sleep(testPart.WaitTime ?? 500);
                if (testSettings.ScreenShot)
                {
                    TestAutomationOperate.GetScreenShot(
                        driver: driver,
                        ActionName: testPart.Action.ToString());
                }
                if (testPart.Results?.Count > 0)
                {
                    testPart.Results.ForEach(resultCheck =>
                    {
                        TestAutomationOperate.CheckResult(
                            driver,
                            resultCheck,
                            autoTestScenario.ResultFileName);
                    });
                }
            });
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var(path, executeType) = GetArgParams(args);
            Initializer.Initialize(
                path,
                assemblyVersion: Assembly.GetExecutingAssembly().GetName().Version.ToString());

            var context = new ContextForAutoTest();

            var(testList, checkResult) = CheckPreExecution(executeType);
            if (!checkResult)
            {
                return;
            }
            try
            {
                using (IWebDriver driver = SelectBrowser(Parameters.ExtendedAutoTestSettings.BrowserType))
                {
                    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(Parameters.ExtendedAutoTestSettings.TimeoutSeconds);
                    TestAutomationOperate.LaunchBrowser(driver, Parameters.ExtendedAutoTestSettings);
                    Thread.Sleep(500);
                    Parameters.ExtendedAutoTestScenarios
                    .Where((autoTestScenario, index) => testList.Contains(index))
                    .ForEach(autoTestScenario =>
                    {
                        TestAutomationOperate.WriteResult(
                            resultString: new AutoTestResult()
                        {
                            Description = autoTestScenario.CasesDescription
                        },
                            ResultFileName: autoTestScenario.ResultFileName,
                            resultInitial: true);
                        TestAutomationOperate.WriteLog(
                            logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                            logMessage: $"Start case:{ autoTestScenario.CaseName}",
                            logInitial: true
                            );
                        autoTestScenario.TestCases
                        .SelectMany(testCase => Parameters.ExtendedAutoTestOperations
                                    .Where(testOperateion => testOperateion.TestPartsPath
                                           .StartsWith($"{testCase.TestPartsPath}\\{testCase.TestPartsName}")))
                        .ForEach(testOperation =>
                                 TestAutomationExecute.ExecuteAutoTest(
                                     testOperation: testOperation,
                                     driver: driver,
                                     testSettings: Parameters.ExtendedAutoTestSettings,
                                     autoTestScenario: autoTestScenario));
                    });
                    TestAutomationOperate.WriteLog(
                        logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                        logMessage: Displays.AutoTestFinished(context: context)
                        );
                    Console.ReadKey(intercept: true);
                }
            }
            catch (NoSuchElementException ex)
            {
                TestAutomationOperate.WriteLog(
                    logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                    logMessage: Displays.AutoTestHtmlError(context: context)
                    );
                TestAutomationOperate.WriteLog(
                    logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                    logMessage: ex.Message
                    );
                Console.ReadKey(intercept: true);
            }
            catch (Exception ex)
            {
                TestAutomationOperate.WriteLog(
                    logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                    logMessage: Displays.AutoTestOtherError(context: context)
                    );
                TestAutomationOperate.WriteLog(
                    logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                    logMessage: ex.Message
                    );
                Console.ReadKey(intercept: true);
            }
        }