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

Exception handling in Serenity screenplay #3027

Open
amar1989 opened this issue Jan 26, 2023 · 3 comments
Open

Exception handling in Serenity screenplay #3027

amar1989 opened this issue Jan 26, 2023 · 3 comments

Comments

@amar1989
Copy link

I am in the process of migrating my Page object model code to screenplay pattern but bit confused about the exception handling. How to print exception in better way so that debugging will be easier. Currently exception is printed at Step definition level, meaning , line of error from the Task class is not getting printed in stacktrace but the line from step definition is printed . Since i am clubbing 2-3 interactions in single step so it is getting hard to pin point exact interaction which has issue.

Eg.
Step definition method:
Class: LoginPageStepDef
public void isAtHomePage(String actor)
{
theActorInTheSpotlight().attemptsTo(loginTask.loginWithMobileNumberAndPassword(testData.get("mobile"),testData.get("password")));
}

LoginTask class:

public Performable loginWithMobileNumberAndPassword(String mobileNumber, String password)
{
return Task.where(
"{0} attempts to enter mobile no and password",
Click.on(LoginPage.LOGIN_BUTTON),
Click.on(LOGIN_EMAIL_NUMBER),
Enter.theValue(mobileNumber).into(LoginPage.LOGIN_EMAIL_NUMBER_EDIT_TEXT)
}

Here if exception like ElementNotFound occurs for line Click.on(LoginPage.LOGIN_BUTTON), then in stack trace there is not any entry of LoginTask class , it is printing that exception occurs at LoginPageStepDef class at line no X , the line which is calling method loginWithMobileNumberAndPassword .

Can someone help in designing task so that we should get stacktrace of task class
--I have not copied code from editor due to privacy issue so might be syntax error

@wakaleo
Copy link
Member

wakaleo commented Feb 1, 2023

I'm not sure this is easily doable. Stack traces are tricky when you use the command pattern: the Click.on() parameter is not being directly called by the loginWithMobileNumberAndPassword() method, so it does not know what method it is being invoked from.

@globalworming
Copy link
Collaborator

it's easier with the actor by not passing the varargs steps but only one like

actor.attemptsTo(Click.on(LoginPage.LOGIN_BUTTON))
actor.attemptsTo(Click.on(LoginPage.LOGIN_EMAIL_NUMBER))

with the task it's similar i guess

public Performable loginWithMobileNumberAndPassword(String mobileNumber, String password) {
    return Task.where("{0} attempts to enter mobile no and password",
          clickLogin(),
          clickEmail());
}

public Performable clickLogin() {
    return Task.where("{0} attempts click on " + LoginPage.LOGIN_BUTTON.getName(), 
          Click.on(LoginPage.LOGIN_BUTTON));
}

public Performable clickEmail() {
    return Task.where("{0} attempts click on " + LoginPage.LOGIN_EMAIL_NUMBER.getName(), 
         Click.on(LoginPage.LOGIN_EMAIL_NUMBER));
}

@amar1989
Copy link
Author

is there any workaround apart from writing single interaction in step as its difficult to pin point which interaction is failing for a particular task , It would be easy to navigate to specific interaction in case of exception if task will be specified in stacktrace

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

No branches or pull requests

3 participants