Exemplo n.º 1
0
        private static void WriteResult(ResultCheck resultCheck
                                        , string resultFileName
                                        , string comparisonResult
                                        , string executionValue)
        {
            var context   = new ContextForAutoTest();
            var resultStr = new AutoTestResult();

            resultStr.ExpectedContent    = resultCheck.Description;
            resultStr.ConfirmationTarget = SetConfirmationTaget(resultCheck);
            resultStr.ExpectedValue      = resultCheck.ExpectedValue;
            resultStr.ExecutionValue     = executionValue;
            resultStr.ComparisonResult   = comparisonResult;
            WriteResult(resultString: resultStr, ResultFileName: resultFileName);
            WriteLog(
                logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                logMessage:
                Displays.AutoTestResultMessage(
                    context: context,
                    data: new string[]
            {
                resultStr.ComparisonResult,
                resultStr.ExpectedContent,
                resultStr.ConfirmationTarget,
                resultStr.ExpectedValue,
                resultStr.ExecutionValue
            }),
                consoleColor: SelectConsoleColor(resultStr.ComparisonResult)
                );
        }
Exemplo n.º 2
0
        public static void InputsOpe(IWebDriver driver,
                                     TestPart testPart)
        {
            var context = new ContextForAutoTest();
            IJavaScriptExecutor jsDriver = driver as IJavaScriptExecutor;

            testPart.Inputs.ForEach(testInput =>
            {
                if (testInput.InputAutoPostBack == true)
                {
                    jsDriver.ExecuteScript($"$p.disableAutPostback = false;");
                }
                else
                {
                    jsDriver.ExecuteScript($"$p.disableAutPostback = true;");
                }
                if (!testInput.InputWaitTime.IsNullOrEmpty())
                {
                    Thread.Sleep(testInput.InputWaitTime.ToInt());
                }
                if (testInput.InputTarget.StartsWith("Check"))
                {
                    jsDriver.ExecuteScript($"$p.set($p.getControl('{testInput.InputTarget}').prop('checked',{testInput.InputValue}));");
                }
                else
                {
                    var script = $@"
                        var $element;
                        var target = '{testInput.InputTarget}';
                        if (target.indexOf('#') === -1) {{
                            $element = $p.getControl('{testInput.InputTarget}');
                        }}
                        if ($element === undefined) {{
                            $element = $(target);
                        }}
                        var value = '{testInput.InputValue}';
                        if ($element.prop('tagName') === 'SELECT') {{
                            $element.find('option').each(function(index) {{
	                            if ($(this).text() === value) {{
                                    value = $(this).val();
                                }}
                            }});
                        }}
                        $p.set($element, value);";
                    jsDriver.ExecuteScript(script);
                }
                WriteLog(
                    logFileName: Parameters.ExtendedAutoTestSettings.LogFileName,
                    logMessage:
                    Displays.AutoTestEntered(
                        context: context,
                        data: new string[]
                {
                    testInput.InputTarget,
                    testInput.InputValue
                })
                    );
            });
        }
Exemplo n.º 3
0
        private static bool CheckTestPartsJson()
        {
            var context = new ContextForAutoTest();
            var result  = true;

            Parameters.ExtendedAutoTestScenarios
            .Select((autoTestScenario, i) => new { Index = i + 1, Data = autoTestScenario })
            .ForEach(autoTestScenario =>
            {
                Console.WriteLine(Displays.AutoTestCasesList(
                                      context: context,
                                      data: new string[]
                {
                    autoTestScenario.Index.ToString(),
                    autoTestScenario.Data.CaseName,
                    autoTestScenario.Data.CasesDescription
                }));
                autoTestScenario.Data.TestCases
                .ForEach(testCase =>
                {
                    var testPartsList = new List <string>();
                    Parameters.ExtendedAutoTestOperations
                    .ForEach(testParts =>
                    {
                        testPartsList.Add(testParts.TestPartsPath);
                    });
                    string partCheck = null;
                    if ((!testCase.TestPartsName.IsNullOrEmpty()) &&
                        (!testPartsList.Contains($"{testCase.TestPartsPath}\\{testCase.TestPartsName}")))
                    {
                        if (result)
                        {
                            result = false;
                        }
                        partCheck = Displays.AutoTestResultNg(context: context);
                    }
                    string partMessage = !testCase.TestPartsName.IsNullOrEmpty() ?
                                         $"\\{testCase.TestPartsName}" : "\\*";
                    Console.WriteLine(Displays.AutoTestPartsList(
                                          context: context,
                                          data: new string[]
                    {
                        testCase.TestPartsPath,
                        partMessage,
                        partCheck
                    }));
                });
            });
            if (!result)
            {
                Console.WriteLine(Displays.AutoTestFileDescribed(context: context));
            }
            return(result);
        }
Exemplo n.º 4
0
        private static (List <int>, bool) CheckPreExecution(string executeType)
        {
            var context  = new ContextForAutoTest();
            var testList = new List <int>();

            if (Parameters.ExtendedAutoTestSettings.Url.IsNullOrEmpty())
            {
                Parameters.ExtendedAutoTestSettings.Url = InputUrl();
            }
            if (CheckTestPartsJson() == false)
            {
                Console.ReadKey(intercept: true);
                return(null, false);
            }
            Console.WriteLine(Displays.AutoTestNumberSelect(context: context));
            Console.WriteLine(Displays.AutoTestTargetPartsMessage(context: context));
            Console.Write(Displays.AutoTestArrow(context: context));
            if (!executeType.Contains("select"))
            {
                Parameters.ExtendedAutoTestScenarios
                .Select((autoTestScenario, i) => new { Index = i })
                .ForEach(autoTestScenario =>
                {
                    testList.Add(autoTestScenario.Index);
                });
            }
            else
            {
                try
                {
                    testList = Console.ReadLine()
                               .Split(',')
                               .Select(selectNumber => int.Parse(selectNumber) - 1)
                               .ToList();
                    Console.Write(Displays.AutoTestNumber(context: context));
                }
                catch
                {
                    Console.WriteLine(Displays.AutoTestInputErrorHalfNumber(context: context));
                    Console.ReadKey(intercept: true);
                    return(null, false);
                }
            }
            foreach (var list in testList)
            {
                Console.Write($"{list + 1},");
            }
            Console.WriteLine(Displays.AutoTestSelected(context: context));
            Console.WriteLine(Displays.AutoTestConfirmRun(context: context));
            Console.WriteLine(Displays.AutoTestRunning(context: context));
            return(testList, true);
        }
Exemplo n.º 5
0
        private static string InputUrl()
        {
            var context = new ContextForAutoTest();

            Console.WriteLine(Displays.AutoTestNoUrl(context: context));
            Console.Write(Displays.AutoTestArrow(context: context));
            var strUrl = Console.ReadLine();

            if (strUrl.IsNullOrEmpty())
            {
                InputUrl();
            }
            return(strUrl);
        }
Exemplo n.º 6
0
        private static string ComparisonValue(
            IWebDriver driver,
            ResultCheck resultCheck)
        {
            var context = new ContextForAutoTest();

            if (resultCheck.CheckType.Equals(CheckTypes.Regex))
            {
                if (Regex.IsMatch(resultCheck.ExecutionValue, resultCheck.ExpectedValue))

                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.Existance))
            {
                resultCheck.ExecutionValue = resultCheck.ExecutionValue == null ? "ExistanceFalse" : "ExistanceTrue";
                if (resultCheck.ExecutionValue.Equals(resultCheck.ExpectedValue))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.HasClass))
            {
                if (HasClass(driver, resultCheck))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.HasNotClass))
            {
                if (!HasClass(driver, resultCheck))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.ReadOnly))
            {
                resultCheck.ExecutionValue = ReadOnly(driver, resultCheck);
                if (resultCheck.ExecutionValue.Equals(resultCheck.ExpectedValue))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.DataRequiredTrue))
            {
                if (DataRequired(driver, resultCheck))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.DataRequiredFalse))
            {
                if (!DataRequired(driver, resultCheck))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.CanReadRecordOnGrid))
            {
                if (CanReadRecordOnGrid(driver, resultCheck))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.CanNotReadRecordOnGrid))
            {
                if (!CanReadRecordOnGrid(driver, resultCheck))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.CanUpdateRecordOnEditor))
            {
                if (CanReadRecordOnEditor(driver, resultCheck) && CanUpdateRecordOnEditor(driver))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.CanReadRecordOnEditor))
            {
                if (CanReadRecordOnEditor(driver, resultCheck) && !CanUpdateRecordOnEditor(driver))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.CanNotReadRecordOnEditor))
            {
                if (!CanReadRecordOnEditor(driver, resultCheck))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.CanCrossSearchRecord))
            {
                if (CanCrossSearchRecord(driver, resultCheck))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.CanNotCrossSearchRecord))
            {
                if (!CanCrossSearchRecord(driver, resultCheck))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.SelectOptions))
            {
                if (SelectOptions(driver, resultCheck, resultCheck.ExecutionValue))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else if (resultCheck.CheckType.Equals(CheckTypes.Label))
            {
                resultCheck.ExecutionValue = GetLabelText(driver, resultCheck);
                if (resultCheck.ExecutionValue.Equals(resultCheck.ExpectedValue))
                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
            else
            {
                if (resultCheck.ExecutionValue == resultCheck.ExpectedValue)

                {
                    return(Displays.AutoTestResultOk(context: context));
                }
                else
                {
                    return(Displays.AutoTestResultNg(context: context));
                }
            }
        }
Exemplo n.º 7
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);
            }
        }