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: Be able to run a task using screenplay based in data from a csv #1259

Closed
LucasGrc opened this issue May 24, 2018 · 2 comments
Closed
Labels

Comments

@LucasGrc
Copy link

LucasGrc commented May 24, 2018

Is there a way to run a certain task using the screenplay pattern base on the data from a csv file?
For example login then create as many users as there are in the csv file and then logout.

Thanks in advance for your help.

@wakaleo
Copy link
Member

wakaleo commented Jul 12, 2018

Sure, within a task you could load the data, then loop through each row and call another task to create the users.

@LucasGrc
Copy link
Author

LucasGrc commented Jul 13, 2018

Thanks for your answer, I was able to to do it but not sure if is the best way, let me show you:

This is my test:

    public void should_be_able_to_create_as_many_daily_notes_as_needed() throws Throwable {
        givenThat(anna).wasAbleTo(OpenTheApplication.onTheLoginPage());
        and(anna).wasAbleTo(Login.intoTheApp());
        and(anna).wasAbleTo(CreateAPatient.withTheName("Jane", "Smith"));
        and(anna).wasAbleTo(CreateNote.forTheNewlyPatientCreated());

        withTestDataFrom("testdata/dailyNotes.csv").
                run(dailyNotesDataDriven).
                createDailyNote(anna);
    }

This is the model class that extends from ScenarioSteps that executes the task, as this was my first try I have only one column in the csv file to iterate to "ptEvaluationTimeMinutes"

public class DailyNotesDataDriven extends ScenarioSteps {
    private String ptEvaluationTimeMinutes;

    public void setPtEvaluationTimeMinutes(String ptEvaluationTimeMinutes) {
        this.ptEvaluationTimeMinutes = ptEvaluationTimeMinutes;
    }

    public DailyNotesDataDriven(Pages pages) {
        super(pages);
    }

    public void createDailyNote(Actor actor) {
        when(actor).attemptsTo(CreateDailyNote.fillForm(this.ptEvaluationTimeMinutes));
    }

Using withTestDataFrom I was able to get the csv file be loaded in the serenity report.

I know this may be considered as support but I just need an advice on how to do this in a better way and get the data from the csv file loaded in the serenity report, thanks in advance for your help and time.

@wakaleo wakaleo closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants