コード例 #1
0
        private bool IsStopOnErrorStep(TestStep step)
        {
            var method = GetStepMethod(step.Keyword);

            return(method.GetCustomAttribute <StopOnFailAttribute>() != null);
        }
コード例 #2
0
 private void RunCustomStep(TestStep step)
 {
     SubstituteVariables(step);
     CallTestStepMethod(step);
 }
コード例 #3
0
        public void CallTestStepMethod(TestStep step)
        {
            try
            {
                var method       = GetStepMethod(step.Keyword);
                var expectedArgs = method.GetParameters();
                var suppliedArgs = new List <object>(expectedArgs.Length);

                // convert each paramter to the type from the method parameter list and insert into list.
                foreach (var arg in expectedArgs)
                {
                    // if the method takes a dictionary as an input, pass all the suppied parameters in as
                    // a dictionary.
                    if (arg.ParameterType == typeof(Dictionary <string, string>))
                    {
                        var expectedNames = expectedArgs.Select(a => a.Name).ToList();
                        var d             = new Dictionary <string, string>();
                        foreach (var input in step.Inputs.Where(i => !expectedNames.Contains(i.Key)))
                        {
                            d[input.Key] = input.Value;
                        }
                        suppliedArgs.Add(d);
                    }
                    else
                    {
                        // locate all parameters whose name matches an argument in the method paramter list.
                        // could either be using the step name followed by parameters, or inline parameters in step name

                        var inLineParamNames = Regex.Matches(method.GetCustomAttribute <StepAttribute>().Text, inlineParameterRegex);

                        var matchingParams = step.Inputs.Where(n => n.Key == arg.Name);

                        if (matchingParams.Count() > 0)
                        {
                            suppliedArgs.Insert(arg.Position, Convert.ChangeType(matchingParams.First().Value, arg.ParameterType));
                        }
                        else if (inLineParamNames.Count > 0)
                        {
                            // get the values from the step keyword passed via test file
                            var inLineValueMatches = Regex.Matches(step.Keyword, inlineParameterRegex);
                            for (var n = 0; n < inLineParamNames.Count; n++)
                            {
                                // only want the second group
                                if (inLineParamNames[n].Groups[1].Value == arg.Name)
                                {
                                    // inline parameters haven't gone through the substitution for variables, so do it now
                                    var value = ConvertVariableTokensToValues(inLineValueMatches[n].Groups[1].Value);
                                    suppliedArgs.Insert(arg.Position, Convert.ChangeType(value, arg.ParameterType));
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (arg.HasDefaultValue)
                            {
                                suppliedArgs.Insert(arg.Position, Type.Missing);
                            }
                            else
                            {
                                suppliedArgs.Insert(arg.Position, null);
                            }
                        }
                    }
                }

                var actionInstance = Activator.CreateInstance(method.DeclaringType, new Object[] { });
                method.Invoke(actionInstance, suppliedArgs.ToArray());
            }
            catch (Exception e)
            {
                Log.Fail($"A test step exception occurred: {e.Message}, {e.StackTrace}");
            }
        }