public IStepDefinitionBinding CreateStepBinding(StepDefinitionType type, string regexString, IBindingMethod bindingMethod, BindingScope bindingScope) { if (regexString == null) regexString = stepDefinitionRegexCalculator.CalculateRegexFromMethod(type, bindingMethod); return new StepDefinitionBinding(type, regexString, bindingMethod, bindingScope); }
public StepInfo(StepDefinitionType stepDefinitionType, string text, Table table, string multilineText) { StepDefinitionType = stepDefinitionType; Text = text; Table = table; MultilineText = multilineText; }
public void RunAction(string action, StepDefinitionType stepDefinitionType) { switch (stepDefinitionType) { case StepDefinitionType.Given: { _runner.Given(action); } break; case StepDefinitionType.When: { _runner.When(action); } break; case StepDefinitionType.Then: { _runner.Then(action); } break; default: throw new ArgumentOutOfRangeException(nameof(stepDefinitionType), stepDefinitionType, null); } }
public StepDefinitionBinding(StepDefinitionType stepDefinitionType, Regex regex, IBindingMethod bindingMethod, BindingScope bindingScope) : base(bindingMethod) { StepDefinitionType = stepDefinitionType; Regex = regex; BindingScope = bindingScope; }
public string CalculateRegexFromMethod(StepDefinitionType stepDefinitionType, IBindingMethod bindingMethod) { // if method name seems to contain regex, we use it as-is if (nonIdentifierRe.Match(bindingMethod.Name).Success) { return(bindingMethod.Name); } string stepText = bindingMethod.Name; stepText = RemoveStepPrefix(stepDefinitionType, stepText); var parameters = bindingMethod.Parameters.ToArray(); int processedPosition = 0; var reBuilder = new StringBuilder("(?i)"); foreach (var paramPosition in parameters.Select((p, i) => CalculateParamPosition(stepText, p, i)).Where(pp => pp.Position >= 0).OrderBy(pp => pp.Position)) { if (paramPosition.Position < processedPosition) { continue; //this is an error case -> overlapping parameters } reBuilder.Append(CalculateRegex(stepText.Substring(processedPosition, paramPosition.Position - processedPosition))); reBuilder.Append(CalculateParamRegex(parameters[paramPosition.ParamIndex])); processedPosition = paramPosition.Position + paramPosition.Lenght; } reBuilder.Append(CalculateRegex(stepText.Substring(processedPosition, stepText.Length - processedPosition))); reBuilder.Append(@"\W*"); return(reBuilder.ToString()); }
public string CalculateRegexFromMethod(StepDefinitionType stepDefinitionType, IBindingMethod bindingMethod) { // if method name seems to contain regex, we use it as-is if (nonIdentifierRe.Match(bindingMethod.Name).Success) { return bindingMethod.Name; } string stepText = bindingMethod.Name; stepText = RemoveStepPrefix(stepDefinitionType, stepText); var parameters = bindingMethod.Parameters.ToArray(); int processedPosition = 0; var reBuilder = new StringBuilder("(?i)"); foreach (var paramPosition in parameters.Select((p, i) => CalculateParamPosition(stepText, p, i)).Where(pp => pp.Position >= 0).OrderBy(pp => pp.Position)) { if (paramPosition.Position < processedPosition) continue; //this is an error case -> overlapping parameters reBuilder.Append(CalculateRegex(stepText.Substring(processedPosition, paramPosition.Position - processedPosition))); reBuilder.Append(CalculateParamRegex(parameters[paramPosition.ParamIndex])); processedPosition = paramPosition.Position + paramPosition.Length; } reBuilder.Append(CalculateRegex(stepText.Substring(processedPosition, stepText.Length - processedPosition))); reBuilder.Append(@"\W*"); return reBuilder.ToString(); }
public StepDefinition(StepDefinitionType type, string text, Table table, string multilineText) { Type = type; Text = text; Table = table; MultilineText = multilineText; }
private void GetCompletionsForBindingType(StepDefinitionType stepDefinitionType, out IEnumerable <Completion> completions, out string statusText) { statusText = null; var suggestionProvider = languageService.ProjectScope.StepSuggestionProvider; if (suggestionProvider == null) { completions = Enumerable.Empty <Completion>(); return; } if (!suggestionProvider.Populated) { string percentText = string.Format("({0}% completed)", suggestionProvider.GetPopulationPercent()); statusText = (!suggestionProvider.BindingsPopulated ? "step suggestion list is being populated... " : "step suggestion list from existing feature files is being populated... ") + percentText; } try { completions = suggestionProvider.GetNativeSuggestionItems(stepDefinitionType); } catch (Exception) { //fallback case completions = Enumerable.Empty <Completion>(); } }
public BoundStepSuggestions(StepDefinitionType stepDefinitionType, INativeSuggestionItemFactory <TNativeSuggestionItem> nativeSuggestionItemFactory) { StepBinding = null; StepDefinitionType = stepDefinitionType; NativeSuggestionItem = nativeSuggestionItemFactory.Create("[unbound steps]", "...", 0, "nb", this); suggestions = new StepSuggestionList <TNativeSuggestionItem>(nativeSuggestionItemFactory); }
public IStepDefinitionBinding CreateStepBinding(StepDefinitionType type, string regexString, IBindingMethod bindingMethod, BindingScope bindingScope) { if (regexString == null) { regexString = stepDefinitionRegexCalculator.CalculateRegexFromMethod(type, bindingMethod); } return(new StepDefinitionBinding(type, regexString, bindingMethod, bindingScope)); }
public void Step(StepDefinitionKeyword stepDefinitionKeyword, string keyword, string text, string multilineTextArg, Table tableArg) { StepDefinitionType stepDefinitionType = (stepDefinitionKeyword == StepDefinitionKeyword.And || stepDefinitionKeyword == StepDefinitionKeyword.But) ? GetCurrentBindingType() : (StepDefinitionType)stepDefinitionKeyword; ExecuteStep(new StepInstance(stepDefinitionType, stepDefinitionKeyword, keyword, text, multilineTextArg, tableArg, contextManager.GetStepContext())); }
public StepDefinition(StepDefinitionType type, StepDefinitionKeyword stepDefinitionKeyword, string text, Table table, string multilineText, string keyword) { Type = type; Text = text; Table = table; MultilineText = multilineText; Action = e => e.Step(stepDefinitionKeyword, keyword, text, multilineText, table); }
protected LateBoundStepDefinitionBindingWithSource(StepDefinitionType stepDefinitionType, IBindingMethod bindingMethod, BindingScope bindingScope, string sourceExpression, Lazy <Tuple <Regex, string> > regexProvider) : base(bindingMethod) { _regexProvider = regexProvider; StepDefinitionType = stepDefinitionType; BindingScope = bindingScope; SourceExpression = sourceExpression; }
protected StepDefinitionBaseAttribute(string regex, StepDefinitionType[] types) { if (types == null) throw new ArgumentNullException("types"); if (types.Length == 0) throw new ArgumentException("List cannot be empty", "types"); Regex = regex; Types = types; }
private void RegisterStepBindings <T>(Type type, StepDefinitionType stepDefinitionType) where T : StepDefinitionBaseAttribute { foreach (var(method, attribute) in GetTypeMethods <T>(type)) { var binding = bindingFactory.CreateStepBinding( stepDefinitionType, attribute.Regex, new RuntimeBindingMethod(method), null); bindingRegistry.RegisterStepDefinitionBinding(binding); } }
public StepInstance Step(StepDefinitionKeyword stepDefinitionKeyword, string keyword, string text, string multilineTextArg, Table tableArg) { StepDefinitionType stepDefinitionType = (stepDefinitionKeyword == StepDefinitionKeyword.And || stepDefinitionKeyword == StepDefinitionKeyword.But) ? GetCurrentBindingType() : (StepDefinitionType)stepDefinitionKeyword; return(new StepInstance(stepDefinitionType, stepDefinitionKeyword, keyword, text, multilineTextArg, tableArg, new StepContext( new FeatureInfo(new CultureInfo("en-GB"), text, "description", ProgrammingLanguage.CSharp, new string[0]), new ScenarioInfo("title", new string[0])))); }
public StepInstance(StepDefinitionType type, StepDefinitionKeyword stepDefinitionKeyword, string keyword, string text, string multilineTextArgument, Table tableArgument, StepContext stepContext) { StepDefinitionType = type; StepDefinitionKeyword = stepDefinitionKeyword; Text = text; MultilineTextArgument = multilineTextArgument; TableArgument = tableArgument; StepContext = stepContext; Keyword = keyword; }
private ExtentTest CreateScenario(StepDefinitionType stepDefinitionType) { var stepText = scenarioContext.StepContext.StepInfo.Text; return(stepDefinitionType switch { StepDefinitionType.Given => scenario.CreateNode <Given>(stepText), StepDefinitionType.Then => scenario.CreateNode <Then>(stepText), StepDefinitionType.When => scenario.CreateNode <When>(stepText), _ => throw new ArgumentOutOfRangeException(nameof(stepDefinitionType), stepDefinitionType, null), });
// aqui é um método para criar um Scenario passando o tipo de Step private static ExtentTest CreateScenario(ExtentTest extent, StepDefinitionType stepDefinitionType, ScenarioContext scenarioContext) { // o SpecFlow nos permite pegar o nome do Step usando o ScenarioStepContext.Current var scenarioStepContext = scenarioContext.StepContext.StepInfo.Text; return(stepDefinitionType switch { StepDefinitionType.Given => extent.CreateNode <Given>(scenarioStepContext), // cria o nodo para Given StepDefinitionType.Then => extent.CreateNode <Then>(scenarioStepContext), // cria o nodo para Then StepDefinitionType.When => extent.CreateNode <When>(scenarioStepContext), // cria o nodo para When _ => throw new ArgumentOutOfRangeException(nameof(stepDefinitionType), stepDefinitionType, null), });
private string RemoveStepPrefix(StepDefinitionType stepDefinitionType, string stepText) { var prefixesToRemove = GetPrefixesToRemove(stepDefinitionType); foreach (var prefixToRemove in prefixesToRemove) { if (stepText.StartsWith(prefixToRemove, StringComparison.CurrentCultureIgnoreCase)) { stepText = stepText.Substring(prefixToRemove.Length).TrimStart('_', ' '); break; // we only stip one prefix } } return stepText; }
private static void CreateScenarioFailOrError(ExtentTest extent, StepDefinitionType stepDefinitionType) { var error = ScenarioContext.Current.TestError; if (error.InnerException == null) { CreateScenario(extent, stepDefinitionType).Error(error.Message); } else { CreateScenario(extent, stepDefinitionType).Fail(error.InnerException); } }
private string RemoveStepPrefix(StepDefinitionType stepDefinitionType, string stepText) { var prefixesToRemove = GetPrefixesToRemove(stepDefinitionType); foreach (var prefixToRemove in prefixesToRemove) { if (stepText.StartsWith(prefixToRemove, StringComparison.CurrentCultureIgnoreCase)) { stepText = stepText.Substring(prefixToRemove.Length).TrimStart('_', ' '); break; // we only stip one prefix } } return(stepText); }
public BoundStepSuggestions(IStepDefinitionBinding stepBinding, INativeSuggestionItemFactory <TNativeSuggestionItem> nativeSuggestionItemFactory) { if (stepBinding == null) { throw new ArgumentNullException("stepBinding"); } StepBinding = stepBinding; StepDefinitionType = stepBinding.StepDefinitionType; string suggestionText = GetSuggestionText(stepBinding); NativeSuggestionItem = nativeSuggestionItemFactory.Create(suggestionText, GetInsertionText(StepBinding), 0, StepDefinitionType.ToString().Substring(0, 1) + "-b", this); suggestions = new StepSuggestionList <TNativeSuggestionItem>(nativeSuggestionItemFactory); }
// aqui temos um método para criar um novo de falha ou erro private static void CreateScenarioFailOrError(ExtentTest extent, StepDefinitionType stepDefinitionType) { var error = ScenarioContext.Current.TestError; // se não existir exception então pega a mensagem de erro do ScenarioContext.Current if (error.InnerException == null) { CreateScenario(extent, stepDefinitionType).Error(error.Message); } else { // senão cria uma falha passando a exception CreateScenario(extent, stepDefinitionType).Fail(error.InnerException); } }
private Tuple <Regex, string> CreateStepBindingRegex(StepDefinitionType type, string expressionSource, IBindingMethod bindingMethod) { try { var expression = _definitionMatchExpressionConverter.CreateExpression(expressionSource, type, bindingMethod); return(new Tuple <Regex, string>(expression.GetRegex(), null)); } catch (Exception ex) { if (Assembly.GetEntryAssembly()?.FullName.StartsWith("deveroom") ?? false) { return(new Tuple <Regex, string>(null, ex.Message)); } throw new CucumberExpressionException($"error: '{expressionSource}': {ex.Message}"); } }
// Here is a method to create a new one for failure or error private static void CreateScenarioFailOrError(ExtentTest extent, StepDefinitionType stepDefinitionType, String pathScreenshot) { var scenarioStepContext = ScenarioStepContext.Current.StepInfo.Text; var error = ScenarioContext.Current.TestError; // If there is no exception then get the error message from ScenarioContext.Current if (error.InnerException == null) { CreateScenario(extent, stepDefinitionType).Error(error.Message).AddScreenCaptureFromPath(pathScreenshot, scenarioStepContext); } else { // Otherwise creates a failure passing the exception CreateScenario(extent, stepDefinitionType).Fail(error.InnerException).AddScreenCaptureFromPath(pathScreenshot, scenarioStepContext); } }
private void AddStepSuggestionToMatchingItems(StepDefinitionType stepDefinitionType, IEnumerable <BoundStepSuggestions <TNativeSuggestionItem> > matchingItems, Action <BoundStepSuggestions <TNativeSuggestionItem> > addAction) { bool wasMatching = false; foreach (var item in matchingItems) { addAction(item); wasMatching = true; } if (!wasMatching) { addAction(notMatchingSteps[stepDefinitionType]); } }
private static void CreateScenarioFailOrError(ExtentTest extent, StepDefinitionType stepDefinitionType) { var error = ScenarioContext.Current.TestError; if (error.InnerException == null) { _step = CreateScenario(extent, stepDefinitionType).Error(error.Message); } else { _step = CreateScenario(extent, stepDefinitionType).Fail(error.InnerException); } _screenshotPath = TestBase.MakeScreenshotAfterStep(); _step.AddScreenCaptureFromPath(_screenshotPath); }
public void WhenIListMySkillForTrade(string skillTitle) { StepDefinitionType stepDefinitionType = _context.StepContext.StepInfo.StepDefinitionType; ExcelData data = ExcelDataReaderUtil.FetchRowUsingKey(skillTitle); var shareSkill = ObjectFactory.CreateInstance <ShareSkill>(data); _context.Set(shareSkill, skillTitle); // assumption that title is considered unique (even though it seems to have an internal ID that is not visible on page) if (stepDefinitionType == StepDefinitionType.When) { SkillSharePage.EnterShareSkill(shareSkill); } // retrieve ID shareSkill.Id = _helper.GetOrAdd(shareSkill); TestHelper.GetListOfObjectsToBeRemoved(_context).Add(shareSkill); }
public virtual void Step(StepDefinitionKeyword stepDefinitionKeyword, string keyword, string text, string multilineTextArg, Table tableArg) { StepDefinitionType stepDefinitionType = stepDefinitionKeyword == StepDefinitionKeyword.And || stepDefinitionKeyword == StepDefinitionKeyword.But ? GetCurrentBindingType() : (StepDefinitionType)stepDefinitionKeyword; _contextManager.InitializeStepContext(new StepInfo(stepDefinitionType, text, tableArg, multilineTextArg)); try { var stepInstance = new StepInstance(stepDefinitionType, stepDefinitionKeyword, keyword, text, multilineTextArg, tableArg, _contextManager.GetStepContext()); ExecuteStep(_contextManager, stepInstance); } finally { _contextManager.CleanupStepContext(); } }
private static ExtentTest CreateScenario(ExtentTest extent, StepDefinitionType stepDefinitionType) { var scenarioStepContext = ScenarioStepContext.Current.StepInfo.Text; switch (stepDefinitionType) { case StepDefinitionType.Given: return(extent.CreateNode <Given>(scenarioStepContext)); case StepDefinitionType.Then: return(extent.CreateNode <Then>(scenarioStepContext)); case StepDefinitionType.When: return(extent.CreateNode <When>(scenarioStepContext)); default: throw new ArgumentOutOfRangeException(nameof(stepDefinitionType), stepDefinitionType, null); } }
private IEnumerable<string> GetPrefixesToRemove(StepDefinitionType stepDefinitionType) { yield return stepDefinitionType.ToString(); var cultureToSearch = runtimeConfiguration.BindingCulture ?? runtimeConfiguration.FeatureLanguage; foreach (var keyword in LanguageHelper.GetKeywords(cultureToSearch, stepDefinitionType)) { if (keyword.Contains(' ')) { yield return keyword.Replace(" ", "_"); yield return keyword.Replace(" ", ""); } else { yield return keyword; } } }
// Here is a method to create a Scenario passing the type of Step private static ExtentTest CreateScenario(ExtentTest extent, StepDefinitionType stepDefinitionType) { // SpecFlow allows us to get the name of the Step using ScenarioStepContext.Current var scenarioStepContext = ScenarioStepContext.Current.StepInfo.Text; switch (stepDefinitionType) { case StepDefinitionType.Given: return extent.CreateNode<Given>(scenarioStepContext); // Rebuild the node for Given case StepDefinitionType.Then: return extent.CreateNode<Then>(scenarioStepContext); // Rebuild the node for Then case StepDefinitionType.When: return extent.CreateNode<When>(scenarioStepContext); // Rebuild the node for When default: throw new ArgumentOutOfRangeException(nameof(stepDefinitionType), stepDefinitionType, null); } }
private IEnumerable <string> GetPrefixesToRemove(StepDefinitionType stepDefinitionType) { yield return(stepDefinitionType.ToString()); var cultureToSearch = runtimeConfiguration.BindingCulture ?? runtimeConfiguration.FeatureLanguage; foreach (var keyword in LanguageHelper.GetKeywords(cultureToSearch, stepDefinitionType)) { if (keyword.Contains(' ')) { yield return(keyword.Replace(" ", "_")); yield return(keyword.Replace(" ", "")); } else { yield return(keyword); } } }
private static ExtentTest CreateScenario(ExtentTest extent, StepDefinitionType stepDefinitionType) { var stepInfo = ScenarioStepContext.Current.StepInfo; var scenarioStepContext = GetStepInfoFormattedText(stepInfo); switch (stepDefinitionType) { case StepDefinitionType.Given: return(extent.CreateNode <Given>(scenarioStepContext)); // cria o node para Given case StepDefinitionType.Then: return(extent.CreateNode <Then>(scenarioStepContext)); // cria o node para Then case StepDefinitionType.When: return(extent.CreateNode <When>(scenarioStepContext)); // cria o node para When default: throw new ArgumentOutOfRangeException(nameof(stepDefinitionType), stepDefinitionType, null); } }
internal StepDefinitionBaseAttribute(string regex, StepDefinitionType type) : this(regex, new[] { type }) { }
public StepInstance(StepDefinitionType stepDefinitionType, StepDefinitionKeyword stepDefinitionKeyword, string keywordWithTrailingSpaces, string text, StepContext stepContext) : this(stepDefinitionType, stepDefinitionKeyword, keywordWithTrailingSpaces, text, null, null, stepContext) { }
public static bool Equals(this ScenarioBlock block, StepDefinitionType stepDefinitionType) { return (int)block == (int)stepDefinitionType; }
private void GetCompletionsForBindingType(StepDefinitionType stepDefinitionType, out IEnumerable<Completion> completions, out string statusText) { statusText = null; var suggestionProvider = languageService.ProjectScope.StepSuggestionProvider; if (suggestionProvider == null) { completions = Enumerable.Empty<Completion>(); return; } if (!suggestionProvider.Populated) { string percentText = string.Format("({0}% completed)", suggestionProvider.GetPopulationPercent()); statusText = (!suggestionProvider.BindingsPopulated ? "step suggestion list is being populated... " : "step suggestion list from existing feature files is being populated... ") + percentText; } try { completions = suggestionProvider.GetNativeSuggestionItems(stepDefinitionType); } catch(Exception) { //fallback case completions = Enumerable.Empty<Completion>(); } }
public GherkinStep(StepDefinitionType stepDefinitionType, StepDefinitionKeyword stepDefinitionKeyword, string stepText, StepContext stepContext, string keyword, int blockRelativeLine) : base(stepDefinitionType, stepDefinitionKeyword, keyword, stepText, stepContext) { BlockRelativeLine = blockRelativeLine; BindingStatus = BindingStatus.UnknownBindingStatus; }
/// <summary> /// Creates a <see cref="StepInfo" /> instance, with the specified text and optional step definition type. /// </summary> /// <param name="text">The text of the step.</param> /// <param name="stepDefinitionType">The type of the step definition. Default value is StepDefinitionType.Given</param> /// <returns>A new instance of the <see cref="StepInfo"/> class.</returns> private StepInfo CreateStepInfo(string text, StepDefinitionType stepDefinitionType = StepDefinitionType.Given) { return new StepInfo(stepDefinitionType, text, null, string.Empty); }
private StepDefinitionBinding GetBingingFromAttribute(CodeAttribute2 codeAttribute, CodeFunction codeFunction, StepDefinitionType stepDefinitionType, BindingScope bindingScope) { try { if (codeAttribute.FullName.Equals(string.Format("TechTalk.SpecFlow.{0}Attribute", stepDefinitionType))) return CreateStepBinding(codeAttribute, codeFunction, stepDefinitionType, bindingScope); return null; } catch(Exception) { return null; } }
public StepDefinitionBinding(StepDefinitionType stepDefinitionType, string regexString, IBindingMethod bindingMethod, BindingScope bindingScope) : this(stepDefinitionType, RegexFactory.Create(regexString), bindingMethod, bindingScope) { }
public IEnumerable<IStepDefinitionBinding> GetConsideredStepDefinitions(StepDefinitionType stepDefinitionType, string stepText) { //TODO: later optimize to return step definitions that has a chance to match to stepText return stepDefinitions.Where(sd => sd.StepDefinitionType == stepDefinitionType); }
private StepDefinitionBinding CreateStepBinding(CodeAttribute2 attr, CodeFunction codeFunction, StepDefinitionType stepDefinitionType, BindingScope bindingScope) { try { IBindingMethod bindingMethod = bindingReflectionFactory.CreateBindingMethod(codeFunction); var regexArg = attr.Arguments.Cast<CodeAttributeArgument>().FirstOrDefault(); if (regexArg == null) return null; var regexString = VsxHelper.ParseCodeStringValue(regexArg.Value, regexArg.Language); return new StepDefinitionBinding(stepDefinitionType, regexString, bindingMethod, bindingScope); } catch(Exception) { return null; } }
public StepInfo(StepDefinitionType stepDefinitionType, string text) { this.StepDefinitionType = stepDefinitionType; this.Text = text; }