Best Cucumber Common Library code snippet using PickleStep
PickleCompiler.php
Source:PickleCompiler.php
...7use Cucumber\Messages\GherkinDocument;8use Cucumber\Messages\Id\IdGenerator;9use Cucumber\Messages\Pickle;10use Cucumber\Messages\PickleDocString;11use Cucumber\Messages\PickleStep;12use Cucumber\Messages\PickleStepArgument;13use Cucumber\Messages\PickleTable;14use Cucumber\Messages\PickleTableCell;15use Cucumber\Messages\PickleTableRow;16use Cucumber\Messages\PickleTag;17use Cucumber\Messages\Rule;18use Cucumber\Messages\Scenario;19use Cucumber\Messages\Step;20use Cucumber\Messages\TableCell;21use Cucumber\Messages\TableRow;22use Cucumber\Messages\Tag;23use Generator;24final class PickleCompiler25{26 /** @var array<string, PickleStep\Type|null> */27 private array $pickleStepTypeFromKeyword = [];28 private Step\KeywordType $lastKeywordType = Step\KeywordType::UNKNOWN;29 public function __construct(30 private readonly IdGenerator $idGenerator,31 ) {32 $this->pickleStepTypeFromKeyword[Step\KeywordType::UNKNOWN->name] = PickleStep\Type::UNKNOWN;33 $this->pickleStepTypeFromKeyword[Step\KeywordType::CONTEXT->name] = PickleStep\Type::CONTEXT;34 $this->pickleStepTypeFromKeyword[Step\KeywordType::ACTION->name] = PickleStep\Type::ACTION;35 $this->pickleStepTypeFromKeyword[Step\KeywordType::OUTCOME->name] = PickleStep\Type::OUTCOME;36 $this->pickleStepTypeFromKeyword[Step\KeywordType::CONJUNCTION->name] = null;37 }38 /**39 * @return Generator<Pickle>40 */41 public function compile(GherkinDocument $gherkinDocument, string $uri): Generator42 {43 if (!$gherkinDocument->feature) {44 return;45 }46 $feature = $gherkinDocument->feature;47 $language = $feature->language;48 yield from $this->compileFeature($feature, $language, $uri);49 }50 /**51 * @return Generator<Pickle>52 */53 private function compileFeature(Feature $feature, string $language, string $uri): Generator54 {55 $tags = $feature->tags;56 $featureBackgroundSteps = [];57 foreach ($feature->children as $featureChild) {58 if ($featureChild->background) {59 $featureBackgroundSteps = [...$featureBackgroundSteps, ...$featureChild->background->steps];60 } elseif ($featureChild->rule) {61 yield from $this->compileRule($featureChild->rule, $tags, $featureBackgroundSteps, $language, $uri);62 } elseif ($featureChild->scenario) {63 if (!$featureChild->scenario->examples) {64 yield from $this->compileScenario($featureChild->scenario, $tags, $featureBackgroundSteps, $language, $uri);65 } else {66 yield from $this->compileScenarioOutline($featureChild->scenario, $tags, $featureBackgroundSteps, $language, $uri);67 }68 }69 }70 }71 /**72 * @param list<Tag> $parentTags73 * @param list<Step> $featureBackgroundSteps74 *75 * @return Generator<Pickle>76 */77 private function compileRule(Rule $rule, array $parentTags, array $featureBackgroundSteps, string $language, string $uri): Generator78 {79 $ruleBackgroundSteps = $featureBackgroundSteps;80 $ruleTags = [...$parentTags, ...$rule->tags];81 foreach ($rule->children as $ruleChild) {82 if ($ruleChild->background) {83 $ruleBackgroundSteps = [...$ruleBackgroundSteps, ...$ruleChild->background->steps];84 } elseif ($ruleChild->scenario && $ruleChild->scenario->examples) {85 yield from $this->compileScenarioOutline($ruleChild->scenario, $ruleTags, $ruleBackgroundSteps, $language, $uri);86 } elseif ($ruleChild->scenario) {87 yield from $this->compileScenario($ruleChild->scenario, $ruleTags, $ruleBackgroundSteps, $language, $uri);88 }89 }90 }91 /**92 * @param list<Tag> $parentTags93 * @param list<Step> $backgroundSteps94 *95 * @return Generator<Pickle>96 */97 private function compileScenario(Scenario $scenario, array $parentTags, array $backgroundSteps, string $language, string $uri): Generator98 {99 $steps = [100 ...($scenario->steps ? $this->pickleSteps($backgroundSteps) : []),101 ...array_map(fn ($s) => $this->pickleStep($s), $scenario->steps),102 ];103 $tags = [...$parentTags, ...$scenario->tags];104 $this->lastKeywordType = Step\KeywordType::UNKNOWN;105 yield new Pickle(106 id: $this->idGenerator->newId(),107 uri: $uri,108 name: $scenario->name,109 language: $language,110 steps: $steps,111 tags: $this->pickleTags($tags),112 astNodeIds: [$scenario->id],113 );114 }115 /**116 * @param list<Tag> $featureTags117 * @param list<Step> $backgroundSteps118 *119 * @return Generator<Pickle>120 */121 private function compileScenarioOutline(Scenario $scenario, array $featureTags, array $backgroundSteps, string $language, string $uri): Generator122 {123 foreach ($scenario->examples as $examples) {124 if (!$examples->tableHeader) {125 continue;126 }127 $variableCells = $examples->tableHeader->cells;128 foreach ($examples->tableBody as $valuesRow) {129 $valueCells = $valuesRow->cells;130 $steps = [131 ...($scenario->steps ? $this->pickleSteps($backgroundSteps) : []),132 ...array_map(fn ($s) => $this->pickleStep($s, $variableCells, $valuesRow), $scenario->steps),133 ];134 $tags = [...$featureTags, ...$scenario->tags, ...$examples->tags];135 $sourceIds = [$scenario->id, $valuesRow->id];136 yield new Pickle(137 id: $this->idGenerator->newId(),138 uri: $uri,139 name: $this->interpolate($scenario->name, $variableCells, $valueCells),140 language: $language,141 steps: $steps,142 tags: $this->pickleTags($tags),143 astNodeIds: $sourceIds,144 );145 }146 }147 }148 /**149 * @param list<Step> $steps150 * @return list<PickleStep>151 */152 private function pickleSteps(array $steps): array153 {154 return array_map(fn ($s) => $this->pickleStep($s), $steps);155 }156 /**157 * @param list<TableCell> $variableCells158 */159 private function pickleStep(Step $step, array $variableCells = [], ?TableRow $valuesRow = null): PickleStep160 {161 $valueCells = $valuesRow?->cells ?? [];162 $stepText = $this->interpolate($step->text, $variableCells, $valueCells);163 $astNodeIds = $valuesRow ? [$step->id, $valuesRow->id] : [$step->id];164 if ($step->dataTable) {165 $argument = new PickleStepArgument(dataTable: $this->pickleDataTable($step->dataTable, $variableCells, $valueCells));166 } elseif ($step->docString) {167 $argument = new PickleStepArgument(docString: $this->pickleDocString($step->docString, $variableCells, $valueCells));168 } else {169 $argument = null;170 }171 $this->lastKeywordType =172 $step->keywordType === Step\KeywordType::CONJUNCTION173 ? $this->lastKeywordType174 : ($step->keywordType ?? Step\KeywordType::UNKNOWN)175 ;176 return new PickleStep(177 argument: $argument,178 astNodeIds: $astNodeIds,179 id: $this->idGenerator->newId(),180 type: $this->pickleStepTypeFromKeyword[$this->lastKeywordType->name],181 text: $stepText,182 );183 }184 /**185 * @param list<TableCell> $variableCells186 * @param list<TableCell> $valueCells187 */188 private function interpolate(string $name, array $variableCells, array $valueCells): string189 {190 $variables = array_map(fn ($c) => '<'.$c->value.'>', $variableCells);...
TestStep.php
Source:TestStep.php
...9/**10 * Represents the TestStep message in Cucumber's message protocol11 * @see https://github.com/cucumber/common/tree/main/messages#readme12 *13 * A `TestStep` is derived from either a `PickleStep`14 * combined with a `StepDefinition`, or from a `Hook`. */15final class TestStep implements JsonSerializable16{17 use JsonEncodingTrait;18 /**19 * Construct the TestStep with all properties20 *21 * @param ?list<string> $stepDefinitionIds22 * @param ?list<StepMatchArgumentsList> $stepMatchArgumentsLists23 */24 public function __construct(25 /**26 * Pointer to the `Hook` (if derived from a Hook)27 */28 public readonly ?string $hookId = null,29 public readonly string $id = '',30 /**31 * Pointer to the `PickleStep` (if derived from a `PickleStep`)32 */33 public readonly ?string $pickleStepId = null,34 /**35 * Pointer to all the matching `StepDefinition`s (if derived from a `PickleStep`)36 */37 public readonly ?array $stepDefinitionIds = null,38 /**39 * A list of list of StepMatchArgument (if derived from a `PickleStep`).40 * Each element represents a matching step definition. A size of 0 means `UNDEFINED`,41 * and a size of 2+ means `AMBIGUOUS`42 */43 public readonly ?array $stepMatchArgumentsLists = null,44 ) {45 }46 /**47 * @throws SchemaViolationException48 *49 * @internal50 */51 public static function fromArray(array $arr): self52 {53 self::ensureHookId($arr);54 self::ensureId($arr);55 self::ensurePickleStepId($arr);56 self::ensureStepDefinitionIds($arr);57 self::ensureStepMatchArgumentsLists($arr);58 return new self(59 isset($arr['hookId']) ? (string) $arr['hookId'] : null,60 (string) $arr['id'],61 isset($arr['pickleStepId']) ? (string) $arr['pickleStepId'] : null,62 isset($arr['stepDefinitionIds']) ? array_values(array_map(fn (mixed $member) => (string) $member, $arr['stepDefinitionIds'])) : null,63 isset($arr['stepMatchArgumentsLists']) ? array_values(array_map(fn (array $member) => StepMatchArgumentsList::fromArray($member), $arr['stepMatchArgumentsLists'])) : null,64 );65 }66 /**67 * @psalm-assert array{hookId?: string|int|bool} $arr68 */69 private static function ensureHookId(array $arr): void70 {71 if (array_key_exists('hookId', $arr) && is_array($arr['hookId'])) {72 throw new SchemaViolationException('Property \'hookId\' was array');73 }74 }75 /**76 * @psalm-assert array{id: string|int|bool} $arr77 */78 private static function ensureId(array $arr): void79 {80 if (!array_key_exists('id', $arr)) {81 throw new SchemaViolationException('Property \'id\' is required but was not found');82 }83 if (array_key_exists('id', $arr) && is_array($arr['id'])) {84 throw new SchemaViolationException('Property \'id\' was array');85 }86 }87 /**88 * @psalm-assert array{pickleStepId?: string|int|bool} $arr89 */90 private static function ensurePickleStepId(array $arr): void91 {92 if (array_key_exists('pickleStepId', $arr) && is_array($arr['pickleStepId'])) {93 throw new SchemaViolationException('Property \'pickleStepId\' was array');94 }95 }96 /**97 * @psalm-assert array{stepDefinitionIds?: array} $arr98 */99 private static function ensureStepDefinitionIds(array $arr): void100 {101 if (array_key_exists('stepDefinitionIds', $arr) && !is_array($arr['stepDefinitionIds'])) {102 throw new SchemaViolationException('Property \'stepDefinitionIds\' was not array');103 }104 }...
PickleStep.php
Source:PickleStep.php
...6namespace Cucumber\Messages;7use JsonSerializable;8use Cucumber\Messages\DecodingException\SchemaViolationException;9/**10 * Represents the PickleStep message in Cucumber's message protocol11 * @see https://github.com/cucumber/common/tree/main/messages#readme12 *13 * An executable step */14final class PickleStep implements JsonSerializable15{16 use JsonEncodingTrait;17 /**18 * Construct the PickleStep with all properties19 *20 * @param list<string> $astNodeIds21 */22 public function __construct(23 public readonly ?PickleStepArgument $argument = null,24 /**25 * References the IDs of the source of the step. For Gherkin, this can be26 * the ID of a Step, and possibly also the ID of a TableRow27 */28 public readonly array $astNodeIds = [],29 /**30 * A unique ID for the PickleStep31 */32 public readonly string $id = '',33 /**34 * The context in which the step was specified: context (Given), action (When) or outcome (Then).35 *36 * Note that the keywords `But` and `And` inherit their meaning from prior steps and the `*` 'keyword' doesn't have specific meaning (hence Unknown)37 */38 public readonly ?PickleStep\Type $type = null,39 public readonly string $text = '',40 ) {41 }42 /**43 * @throws SchemaViolationException44 *45 * @internal46 */47 public static function fromArray(array $arr): self48 {49 self::ensureArgument($arr);50 self::ensureAstNodeIds($arr);51 self::ensureId($arr);52 self::ensureType($arr);53 self::ensureText($arr);54 return new self(55 isset($arr['argument']) ? PickleStepArgument::fromArray($arr['argument']) : null,56 array_values(array_map(fn (mixed $member) => (string) $member, $arr['astNodeIds'])),57 (string) $arr['id'],58 isset($arr['type']) ? PickleStep\Type::from((string) $arr['type']) : null,59 (string) $arr['text'],60 );61 }62 /**63 * @psalm-assert array{argument?: array} $arr64 */65 private static function ensureArgument(array $arr): void66 {67 if (array_key_exists('argument', $arr) && !is_array($arr['argument'])) {68 throw new SchemaViolationException('Property \'argument\' was not array');69 }70 }71 /**72 * @psalm-assert array{astNodeIds: array} $arr...
PickleStep
Using AI Code Generation
1use PickleStep;2{3 public $test;4 public $test1;5 public $test2;6 public $test3;7 public $test4;8 public $test5;9 public $test6;10 public $test7;11 public $test8;12 public $test9;13 public $test10;14 public $test11;15 public $test12;16 public $test13;17 public $test14;18 public $test15;19 public $test16;20 public $test17;21 public $test18;22 public $test19;23 public $test20;24 public $test21;25 public $test22;26 public $test23;27 public $test24;28 public $test25;29 public $test26;30 public $test27;31 public $test28;32 public $test29;33 public $test30;34 public $test31;35 public $test32;36 public $test33;37 public $test34;38 public $test35;39 public $test36;40 public $test37;41 public $test38;42 public $test39;43 public $test40;44 public $test41;45 public $test42;46 public $test43;47 public $test44;48 public $test45;49 public $test46;50 public $test47;51 public $test48;52 public $test49;53 public $test50;54 public $test51;55 public $test52;56 public $test53;57 public $test54;58 public $test55;59 public $test56;60 public $test57;61 public $test58;62 public $test59;63 public $test60;64 public $test61;65 public $test62;66 public $test63;67 public $test64;68 public $test65;69 public $test66;70 public $test67;71 public $test68;72 public $test69;73 public $test70;74 public $test71;75 public $test72;76 public $test73;77 public $test74;78 public $test75;79 public $test76;80 public $test77;81 public $test78;82 public $test79;83 public $test80;
PickleStep
Using AI Code Generation
1require_once 'CucumberCommonLibrary.php';2$step = new PickleStep();3$stepText = $step->getStepText();4$stepArgs = $step->getStepArgs();5echo $stepText;6print_r($stepArgs);7require_once 'CucumberCommonLibrary.php';8$step = new PickleStep();9$stepText = $step->getStepText();10$stepArgs = $step->getStepArgs();11$stepArgsStr = $step->getStepArgsString();12echo $stepText;13print_r($stepArgs);14echo $stepArgsStr;15require_once 'CucumberCommonLibrary.php';16$step = new PickleStep();17$stepText = $step->getStepText();18$stepArgs = $step->getStepArgs();19$stepArgsStr = $step->getStepArgsString();20$stepArgsStrDQ = $step->getStepArgsStringDQ();21echo $stepText;
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.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!