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 wait-url-change macro to make tests more reliable #675

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

dgr
Copy link
Contributor

@dgr dgr commented Sep 24, 2024

Closes #646
Closes #674

This macro uses wait-predicate to poll the WebDriver for a change in the URL, thus eliminating some race conditions that were causing flaky test failures.

Please complete and include the following checklist:

  • I have read CONTRIBUTING and the Etaoin Developer Guide.

  • This PR corresponds to an issue that the Etaoin maintainers have agreed to address.

  • This PR contains test(s) to protect against future regressions

  • I have updated CHANGELOG.adoc with a description of the addressed issue.

This macro uses wait-predicate to poll the WebDriver for a change in
the URL, thus eliminating some race conditions that were causing
flaky test failures.
In addition to waiting for the URL to change, wait-url-change also
waits for the new URL to match a regex (with re-find).
@dgr
Copy link
Contributor Author

dgr commented Sep 24, 2024

This passed everything except for the other race condition in another part of the test suite. I create an issue for that other race condition. I think you can merge this PR now and we can work on the other issue later.

Copy link
Collaborator

@lread lread left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment for you to consider.

:simple-textarea 3})
(wait-url-change #"login"
(e/submit *driver* :simple-input))
(is (str/ends-with? (e/get-url *driver*) "?login=1&password=2&message=3")))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why you bothered with a macro, but I think I see your motivation.

An alternative would be to have a wait- fn like those in Etaoin's public api.
And you'd just wait for your expected URL (no need to check if it changed) and fail via timeout exception.
But then you'd not have an assertion in your test, which might feel less natural for a test.

That's probably what I would have done, but if you are still happy with your macro after reading my comment, I'm okay with it, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, a few things:

  1. The wait for change is actually a good self-check. There were a few tests in the suite that I discovered had the previous testing block that performed a test left the browser URL state such that it was unchanged (e.g., two tests tests for the same browser URL back to back; the first passes and the second does't do anything because if the test suite is faster than the browser, it just tests the results of the previous test, not the current test). If you force a change in the URL, then it will catch mistakes like this in the test suite. That said, you could certainly remove the test for change and just look for the URL you're looking for. One issue that still has is that failure is slow. That is, if you don't get the result you're looking for, you'll have to fully timeout because you don't really know if you should continue waiting for more or not. I'd rather have all tests be fast if possible, whether passing or failing. So, that led to the "if the URL changed and it has at least enough of what I'm looking for to know that it's not Firefox's about:blank nonsense, then that's good enough to say that we're ready to start making test assertions" strategy.
  2. It's a macro because I want to detect a change in the URL, so it needs to wrap the body that triggers the change so that it can first grab the URL before the change, then execute the body to trigger, and then wait for things to change. If it was a function, you'd have to pass in a thunk that triggered the change, and I generally prefer macros to thunks; they're just more readable, IMO.
  3. It doesn't have an actual clojure.test assertion in it because I just wanted it to wait and detect a change, without making it too complicated beyond that. Once that change is detected, there may be multiple assertions that the test writer wants to run. There aren't examples of that in the test code right now, but I like composable pieces if possible.

So, poh-tay-toe / poh-tah-toe. That said, as written the test suite passed 100%, which was interesting to see.

Copy link
Collaborator

@lread lread Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking if my poh-tay-toe might pique your interest at all.
Your poh-tah-toe is fine with me.

@lread lread merged commit 81e241d into clj-commons:master Sep 24, 2024
49 checks passed
@dgr dgr deleted the dgr-issue-674-test-failure branch October 8, 2024 19:25
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

Successfully merging this pull request may close these issues.

Possible bug in fill-active-el Random error testing test-combined-actions
2 participants