In Excel, I want to isolate Cucumber Scenarios from a (Java-written) Feature File. I'm looking for an array, with each element being one scenario.
I came up with more than a few regular expressions that do what I want within Rubular and Regex101 with the (apparently) exact same text, but when I do a ".Execute" from my Excel macro, the entire file is returned.
This is a sample of the text:
@optionalFeatureLevel
Tag Feature: some featureScenario: scenario1
Given something
When something
Then something@optionalTag
Scenario: scenario2
Given something else
When something else
Then something elseScenario Outline: scenario3
Given yet another something
When yet another something
Then yet another something
Feature: some featureThis is the function I wrote, I have a "Set arrayOrResults = returnAllStringsMatchingRegEx" receiving it on the other end:
Function returnAllStringsMatchingRegEx(sourceString As String, pattern As String) As Variant
Dim regEx As New RegExp
With regEx
.Global = True
.MultiLine = True
.ignoreCase = True
.pattern = pattern
End With
If regEx.Test(sourceString) Then
Set returnAllStringsMatchingRegEx = regEx.Execute(sourceString)
Else
Set returnAllStringsMatchingRegEx = Nothing
End If
End Function
This how I call it:
Set arrayOfScenarios = returnAllStringsMatchingRegEx(fetchFileContent(oFile.Path), _
"Scenario( Outline)?:((.+)(\n|\r|\r\n|$))+")
For the input above, I would expect "arrayOfResults" to have 3 elements:
First element:
Scenario: scenario1
Given something
When something
Then something
Second element:
Scenario: scenario2
Given another something
When another something
Then another something
Third element:
Scenario Outline: scenario3 Given yet another something When yet another something Then yet another something
The actual result is a single element containing:
Scenario: scenario1
Given something
When something
Then something@optionalTag
Scenario: scenario2
Given another something
When another something
Then another somethingScenario Outline: scenario3
Given yet another something
When yet another something
Then yet another something