Exemplo n.º 1
0
        /// <summary>
        /// 通过使用测试数据来创建脚本
        /// </summary>
        /// <param name="testData"></param>
        /// <returns></returns>
        private TestScript CreateScriptWithData(TestData testData)
        {
            TestScript result = new TestScript();

            if (testData != null)
            {
                string   currentFormName = "";
                FormData currentFormData = null;
                foreach (var command in GetCommandList())
                {
                    var clonedCommand = command.Clone();
                    if (!String.IsNullOrEmpty(clonedCommand.TargetVarName))
                    {
                        clonedCommand.Target = "";// 原有值必须清空
                    }
                    if (!String.IsNullOrEmpty(clonedCommand.ValueVarName))
                    {
                        clonedCommand.Value = "";// 原有值必须清空
                    }
                    clonedCommand.Value = "";
                    if (!String.IsNullOrEmpty(clonedCommand.FormMark))
                    {
                        if (clonedCommand.IsStartFormMark())
                        {
                            currentFormName = clonedCommand.GetFormName();
                            currentFormData = testData.FindFormData(currentFormName);
                        }
                        else if (clonedCommand.IsEndFormMark())
                        {
                            currentFormName = "";
                        }
                    }

                    if (!String.IsNullOrEmpty(currentFormName) && clonedCommand.IsFormFieldMark())
                    {
                        var fieldName = clonedCommand.ValueVarName;
                        if (currentFormData != null)
                        {
                            clonedCommand.Value = currentFormData.FindFieldValue(fieldName);
                        }
                    }

                    if (clonedCommand.IsAssertMark())
                    {
                        var assertName        = clonedCommand.AssertName;
                        var expectedValueName = clonedCommand.GetAssertVarName();
                        var currentAssertData = testData.FindAssertData(assertName);
                        if (currentAssertData != null)
                        {
                            clonedCommand.SetAssertVarValue(currentAssertData.ExpectedValue);
                        }
                    }

                    result.AddCommand(clonedCommand);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建测试用例
        /// </summary>
        /// <param name="name"></param>
        /// <param name="testSiteStartUri"></param>
        /// <param name="browserType"></param>
        /// <param name="commands"></param>
        /// <param name="testData"></param>
        /// <returns></returns>
        public static TestCase Create(string name, Uri testSiteStartUri, WebBrowserType browserType, IEnumerable <TestCommand> commands, TestData testData)
        {
            TestCase result = new TestCase(name, testSiteStartUri, browserType);

            if (commands != null && testData != null)
            {
                string   currentFormName = "";
                FormData currentFormData = null;
                foreach (var command in commands)
                {
                    var clonedCommand = command.Clone();
                    if (!String.IsNullOrEmpty(clonedCommand.TargetVarName))
                    {
                        clonedCommand.Target = "";// 原有值必须清空
                    }
                    if (!String.IsNullOrEmpty(clonedCommand.ValueVarName))
                    {
                        clonedCommand.Value = "";// 原有值必须清空
                    }
                    clonedCommand.Value = "";
                    if (!String.IsNullOrEmpty(clonedCommand.FormMark))
                    {
                        if (clonedCommand.IsStartFormMark())
                        {
                            currentFormName = clonedCommand.GetFormName();
                            currentFormData = testData.FindFormData(currentFormName);
                        }
                        else if (clonedCommand.IsEndFormMark())
                        {
                            currentFormName = "";
                        }
                    }

                    if (!String.IsNullOrEmpty(currentFormName) && clonedCommand.IsFormFieldMark())
                    {
                        var fieldName = clonedCommand.ValueVarName;
                        if (currentFormData != null)
                        {
                            clonedCommand.Value = currentFormData.FindFieldValue(fieldName);
                        }
                    }

                    if (clonedCommand.IsAssertMark())
                    {
                        var assertName        = clonedCommand.AssertName;
                        var expectedValueName = clonedCommand.GetAssertVarName();
                        var currentAssertData = testData.FindAssertData(assertName);
                        if (currentAssertData != null)
                        {
                            clonedCommand.SetAssertVarValue(currentAssertData.ExpectedValue);
                        }
                    }

                    result.AddCommand(clonedCommand);
                }
            }
            return(result);
        }