Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to do data-driven testing with Excel? #245

Open
TomasRibeiro96 opened this issue Nov 19, 2024 · 4 comments
Open

Question: How to do data-driven testing with Excel? #245

TomasRibeiro96 opened this issue Nov 19, 2024 · 4 comments
Labels
question Further information is requested

Comments

@TomasRibeiro96
Copy link

Hello,

Thank you for this package. We are currently using it in our projects but a new need arose. We want to do data-driven testing and execute the same test with different test data. However, and here's the catch, the Test Data must come from an Excel file that other people can edit to change what's being tested. Hence, the generated "*.feature.spec.js" files must be dynamic.

The Examples functionality could be useful, however the test data needs to come from the Excel file and can't be static in the feature file. I want to avoid other people updating the feature files because that would imply that they need to have VS Code and do a commit and push. It's easier for them to just change an Excel file in Jira.
Additionally, I wanted to avoid having to run a pre-script separately to generate tests. I was looking for a solution that integrates with a simple npx bddgen && npx playwright test and avoids bigger changes do the pipeline.

Given this, do you have any suggestion about how to address this situation?

Thank you.

@TomasRibeiro96 TomasRibeiro96 added the question Further information is requested label Nov 19, 2024
@vitalets
Copy link
Owner

Hi @TomasRibeiro96
Could you provide a small sample of excel and feature file that consumes it?
Does excel contains only test data for particular step or it contains steps itself?

Similar approach exists in Specflow, it loads *.feature.xlsx files and converts them into scenarios under the hood.

@TomasRibeiro96
Copy link
Author

Hi @vitalets, here's an example of a feature file:

Given I login as "XXX"
When I create a case
And I fill the field "Name" with "${Name}"
And I fill the field "ID" with "${ID}
Then the text "${ExpectedText}" appears on the page

The Excel file would contain a table such as:
| Name | ID | ExpectedText |
| John Doe | 1 | Johnny |
| Marilyn Doe | 2 | Mary |
| James Smith | 3 | Jamie |

The intention is to execute the test from the feature file but use the test data from the Excel file. Hence, in this situation, from 1 feature file there should be 3 tests executed, each test for each row in the Excel file. Any suggestions about how to implement this?

@vitalets
Copy link
Owner

So the goal is to load examples data from external xls file.
For now, it is not possible out-of-box in playwright-bdd, and most likely in none of Cucumber implementations.

I've found this SO question with the same request. One of suggestions is to use preprocessing: treat feature file as a template and generate 3 actual feature files. I'd suggest to follow it for now, as it's straightforward and keeps excel parsing on your side. Btw, why are you against pre-script?

Another approach we can think for the future - to link external data source inside feature file. To not break gherkin syntax we can put file path to Examples name:

Scenario Outline: my scenario
  Given I login as "XXX"
  When I create a case
  And I fill the field "Name" with "<Name>"
  And I fill the field "ID" with "<ID>"
  Then the text "<ExpectedText>" appears on the page

Examples: path/to/examples.xls

@vitalets
Copy link
Owner

vitalets commented Dec 16, 2024

Another approach used in Gauge library: there is parameter prefix to get value from a csv file: https://docs.gauge.org/writing-specifications?os=macos&language=javascript&ide=vscode#special-parameter-csv

Can be considered as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants