-
Notifications
You must be signed in to change notification settings - Fork 8
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
Replace recursion with loop in FindElement#run #83
Replace recursion with loop in FindElement#run #83
Conversation
This makes sure the code always runs at least once without modifying the #max_tries code
@@ -46,7 +40,8 @@ class LuckyFlow::FindElement | |||
LuckyFlow.settings | |||
end | |||
|
|||
private def matching_elements : Array(Selenium::Element) | |||
private def find_matching_elements : Array(Selenium::Element) | |||
self.tries += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my refactor I forgot to increment this number and ended up in an infinite loop. Rather than fixing it and letting someone else do it in the future, I thought it made more sense to have it here.
end | ||
|
||
private def has_retries_left? | ||
tries < max_tries | ||
end | ||
|
||
private def retry_after_delay | ||
sleep retry_delay_in_ms | ||
run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the moral of this story that recursion is bad? Hmmm... 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha yeah I guess so!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for improving this. The stack trace looks a lot nicer!
end | ||
|
||
private def has_retries_left? | ||
tries < max_tries | ||
end | ||
|
||
private def retry_after_delay | ||
sleep retry_delay_in_ms | ||
run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha yeah I guess so!
Fixes #78
This drastically simplifies the stack trace when a spec attempts to find an element and fails.
Before
After