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

Add a Task convenience function. #74

Open
perrygoy opened this issue Mar 31, 2023 · 11 comments
Open

Add a Task convenience function. #74

perrygoy opened this issue Mar 31, 2023 · 11 comments
Labels
enhancement New feature or request

Comments

@perrygoy
Copy link
Member

perrygoy commented Mar 31, 2023

Sometimes you make Tasks that just do a few Actions and don't need to be modified in any way, they just need a more descriptive beat to log. It's kind of a waste to have to have to make a whole file and class for what is essentially just a beat wrapper around a handful of otherwise too-generic Actions.

But if we had a Task function to entaskinate those Actions, that would be swell! Something we could use like this:

LogInAsBasicUser = Task(
    perform=(
        Eventually(Enter.the_text(BasicUser.USERNAME).into_the(USERNAME_FIELD)),
        Enter.the_password(BasicUser.PASSWORD).into_the(PASSWORD_FIELD),
        Click.on_the(LOGIN_BUTTON),
    ),
    beat=f"{{}} logs in as {BasicUser.username}",
)

Maybe you could even set blurt instead of beat, or neither if you want this Task to be performed without a summary!

@bandophahita
Copy link
Contributor

bandophahita commented Mar 31, 2023

From a usability standpoint it it would be nice if the beat was autogenerated with the option to override/customize it.
Something along the lines of :

LogInAsBasicUser = Task(
        Eventually(Enter.the_text(BasicUser.USERNAME).into_the(USERNAME_FIELD)),
        Enter.the_password(BasicUser.PASSWORD).into_the(PASSWORD_FIELD),
        Click.on_the(LOGIN_BUTTON),
).called("LogInAsBasicUser")

Then when it's logged :

User tries to LogInAsBasicUser.

or if the get_additive_description kicks in...

User tries to login as basic user.

Custom beat might look something like:

Task(Action()).called("MyTask").using_beat("This is my custom beat msg")

@bandophahita
Copy link
Contributor

I think it'll be important to get Task to generate a specific classname the caller provides.

@perrygoy
Copy link
Member Author

perrygoy commented Mar 31, 2023

get_additive_description wouldn't be called for just performing it, though, unless we wanted to have the user provide a description argument that wrote the Describe? Then we could autogenerate the beat/blurt from the description:

LogInAsBasicUser = Task(
    perform=(
        Eventually(Enter.the_text(BasicUser.USERNAME).into_the(USERNAME_FIELD)),
        Enter.the_password(BasicUser.PASSWORD).into_the(PASSWORD_FIELD),
        Click.on_the(LOGIN_BUTTON),
    ),
    description="Log in as a Basic User.",
    blurt=True
)

@perrygoy
Copy link
Member Author

I think it'll be important to get Task to generate a specific classname the caller provides.

Is there another way to do it than this?

>>> class Foo:
...   pass
... 
>>> f = Foo()
>>> Foo.__name__ = "Bar"
>>> f
<__main__.Foo object at 0x10060cb50>
>>> f.__class__.__name__
'Bar'

I think we use __class__.__name__ in get_additive_description, so maybe it will Just Work...?

@bandophahita
Copy link
Contributor

When I envision Task I picture it building an action while automatically handling creation of things like describe, etc.
In the simplest case, I'd love to be able to write the following and it "just works".

DoCommonTask = Task(
    Step1(),
    Step2(),
    Step3()
    )
actor.will(DoCommonTask())
User tries to DoCommonTask

@perrygoy
Copy link
Member Author

I don't think there's a way for the class built in the function/class/whatever we end up using for Task to know what it's called in the higher scope. But who knows, maybe! That would be a very slick smallest use-case.

@bandophahita
Copy link
Contributor

Is there another way to do it than this?

I'm also thinking about viewing these actions in the stack. It would be nice if the name of the objects were identifiable while debugging.

@bandophahita
Copy link
Contributor

I don't think there's a way for the class built in the function/class/whatever we end up using for Task to know what it's called in the higher scope. But who knows, maybe! That would be a very slick smallest use-case.

As far as I know there isn't. I think it's going to be needed as a variable at the time of Task creation.

It would be cool if Task had the ability to read the internal actions and formulate a summary, but I imagine we'll end up with some really terrible (and wordy) class names.

@perrygoy
Copy link
Member Author

perrygoy commented Mar 31, 2023

... maybe we can ask ChatGPT to summarize it. Haha.

I think just calling the generated Task class GroupedActions or something like that and require a description for GroupedActions.describe, we'll be able to make a nice log and a clear stacktrace. I hope.

@bandophahita
Copy link
Contributor

Maybe the end result is Task whereas the creation function is MakeTask?

@perrygoy
Copy link
Member Author

Yes, i like that. Maybe then we just have make_task.

Where should this live? Should we create a shortcuts module?

from screenpy.shortcuts import make_task

LogInAsABasicUser = make_task(
    ...
)

@bandophahita bandophahita added the enhancement New feature or request label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants