Best Gherkin-ruby code snippet using Gherkin.get_tags
ast_builder.rb
Source:ast_builder.rb
...40 line: token.location[:line],41 column: column42 )43 end44 def get_tags(node)45 tags = []46 tags_node = node.get_single(:Tags)47 return tags unless tags_node48 tags_node.get_tokens(:TagLine).each do |token|49 token.matched_items.each do |tag_item|50 tags.push(Cucumber::Messages::GherkinDocument::Feature::Tag.new(51 location: get_location(token, tag_item.column),52 name: tag_item.text,53 id: @id_generator.new_id54 ))55 end56 end57 tags58 end59 def get_table_rows(node)60 rows = node.get_tokens(:TableRow).map do |token|61 Cucumber::Messages::GherkinDocument::Feature::TableRow.new(62 id: @id_generator.new_id,63 location: get_location(token, 0),64 cells: get_cells(token)65 )66 end67 ensure_cell_count(rows)68 rows69 end70 def ensure_cell_count(rows)71 return if rows.empty?72 cell_count = rows[0].cells.length73 rows.each do |row|74 if row.cells.length != cell_count75 location = {line: row.location.line, column: row.location.column}76 raise AstBuilderException.new("inconsistent cell count within the table", location)77 end78 end79 end80 def get_cells(table_row_token)81 table_row_token.matched_items.map do |cell_item|82 Cucumber::Messages::GherkinDocument::Feature::TableRow::TableCell.new(83 location: get_location(table_row_token, cell_item.column),84 value: cell_item.text85 )86 end87 end88 def get_description(node)89 node.get_single(:Description)90 end91 def get_steps(node)92 node.get_items(:Step)93 end94 def transform_node(node)95 case node.rule_type96 when :Step97 step_line = node.get_token(:StepLine)98 data_table = node.get_single(:DataTable)99 doc_string = node.get_single(:DocString)100 Cucumber::Messages::GherkinDocument::Feature::Step.new(101 location: get_location(step_line, 0),102 keyword: step_line.matched_keyword,103 text: step_line.matched_text,104 data_table: data_table,105 doc_string: doc_string,106 id: @id_generator.new_id107 )108 when :DocString109 separator_token = node.get_tokens(:DocStringSeparator)[0]110 content_type = separator_token.matched_text == '' ? nil : separator_token.matched_text111 line_tokens = node.get_tokens(:Other)112 content = line_tokens.map { |t| t.matched_text }.join("\n")113 Cucumber::Messages::GherkinDocument::Feature::Step::DocString.new(114 location: get_location(separator_token, 0),115 content: content,116 delimiter: separator_token.matched_keyword,117 content_type: content_type,118 )119 when :DataTable120 rows = get_table_rows(node)121 Cucumber::Messages::GherkinDocument::Feature::Step::DataTable.new(122 location: rows[0].location,123 rows: rows,124 )125 when :Background126 background_line = node.get_token(:BackgroundLine)127 description = get_description(node)128 steps = get_steps(node)129 Cucumber::Messages::GherkinDocument::Feature::Background.new(130 location: get_location(background_line, 0),131 keyword: background_line.matched_keyword,132 name: background_line.matched_text,133 description: description,134 steps: steps135 )136 when :ScenarioDefinition137 tags = get_tags(node)138 scenario_node = node.get_single(:Scenario)139 scenario_line = scenario_node.get_token(:ScenarioLine)140 description = get_description(scenario_node)141 steps = get_steps(scenario_node)142 examples = scenario_node.get_items(:ExamplesDefinition)143 Cucumber::Messages::GherkinDocument::Feature::Scenario.new(144 id: @id_generator.new_id,145 tags: tags,146 location: get_location(scenario_line, 0),147 keyword: scenario_line.matched_keyword,148 name: scenario_line.matched_text,149 description: description,150 steps: steps,151 examples: examples152 )153 when :ExamplesDefinition154 tags = get_tags(node)155 examples_node = node.get_single(:Examples)156 examples_line = examples_node.get_token(:ExamplesLine)157 description = get_description(examples_node)158 rows = examples_node.get_single(:ExamplesTable)159 table_header = rows.nil? ? nil : rows.first160 table_body = rows.nil? ? nil : rows[1..-1]161 Cucumber::Messages::GherkinDocument::Feature::Scenario::Examples.new(162 tags: tags,163 location: get_location(examples_line, 0),164 keyword: examples_line.matched_keyword,165 name: examples_line.matched_text,166 description: description,167 table_header: table_header,168 table_body: table_body,169 )170 when :ExamplesTable171 get_table_rows(node)172 when :Description173 line_tokens = node.get_tokens(:Other)174 # Trim trailing empty lines175 last_non_empty = line_tokens.rindex { |token| !token.line.trimmed_line_text.empty? }176 description = line_tokens[0..last_non_empty].map { |token| token.matched_text }.join("\n")177 return description178 when :Feature179 header = node.get_single(:FeatureHeader)180 return unless header181 tags = get_tags(header)182 feature_line = header.get_token(:FeatureLine)183 return unless feature_line184 children = []185 background = node.get_single(:Background)186 children.push(Cucumber::Messages::GherkinDocument::Feature::FeatureChild.new(background: background)) if background187 node.get_items(:ScenarioDefinition).each do |scenario|188 children.push(Cucumber::Messages::GherkinDocument::Feature::FeatureChild.new(scenario: scenario))189 end190 node.get_items(:Rule).each do |rule|191 children.push(Cucumber::Messages::GherkinDocument::Feature::FeatureChild.new(rule: rule))192 end193 description = get_description(header)194 language = feature_line.matched_gherkin_dialect195 Cucumber::Messages::GherkinDocument::Feature.new(...
get_tags
Using AI Code Generation
1feature_file = File.open("feature_file_path")2gherkin = Gherkin::Parser::Parser.new.parse(feature_file)3feature_file = File.open("feature_file_path")4gherkin = Gherkin::Parser::Parser.new.parse(feature_file)5feature_file = File.open("feature_file_path")6gherkin = Gherkin::Parser::Parser.new.parse(feature_file)7feature_file = File.open("feature_file_path")8gherkin = Gherkin::Parser::Parser.new.parse(feature_file)9feature_file = File.open("feature_file_path")10gherkin = Gherkin::Parser::Parser.new.parse(feature_file)11feature_file = File.open("feature_file_path")12gherkin = Gherkin::Parser::Parser.new.parse(feature_file)13feature_file = File.open("feature_file_path")
get_tags
Using AI Code Generation
1feature_file = File.expand_path(feature_file)2parser = Gherkin::Parser::Parser.new(Gherkin::Formatters::JSONFormatter.new)3parser.parse(File.read(feature_file), feature_file, 0)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!