Comments (3)
My plans were to experiment with increasing our timeouts
I'm confused about what uses timeouts and what doesn't, and what's the best way to wait on some dom.
This code was flakey for us:
|> visit("/users/sign_in")
|> fill_in(text_field("user[email]"), with: user.email)
|> fill_in(text_field("user[password]"), with: user.password)
|> click(button("Sign In"))
When it failed, Wallaby would raise an error from click/1
saying something like "can't find button, most likely the dom isn't ready, using find/2,3 will probably fix it."
Changing the code to this makes the test not flakey:
|> visit("/users/sign_in")
|> find(button("Sign In"), fn _ -> nil end)
|> fill_in(text_field("user[email]"), with: user.email)
|> fill_in(text_field("user[password]"), with: user.password)
|> click(button("Sign In"))
Using find/3
with an empty function feels wonky though; why isn't there a wait_for/2
function? Or why not every function that relies on some dom go through the timeout/retry process?
from wallaby.
We see the same thing in our codebase. I don't think it's easy to help you though without more details (the exact error message, OS/memory/processor specs of your machines running the tests, configuration you're using for max-cases and max_wait_time, chrome and chromedriver versions).
One suggestion from me is to enable Screenshots. For us, this has shown it's always the case that the next page hasn't loaded in time (the screenshots often show the browser was still displaying the previous page that had the button/link clicked on, hence the missing element or text). My thoughts have been this is probably not a Wallaby issue, given it's a fairly common challenge writing reliable browser tests at all. They are just slower, have more moving parts, and more prone to this kind of behaviour.
My plans were to experiment with increasing our timeouts and reducing the number of parallel tests being run, to try and get to a point of more stability, and that might be the best option for you too. When running tests locally with --max-cases=1
and a max_wait_time
of 7000
, it's much less common for us to see random failures (although it is still happening....and that seems strange with such a long timeout). Our CI runs with --max-cases 8
and a max_wait_time
of 10000
and failures are much more frequent.
I'd welcome other suggestions of how to debug and tune things. I am surprised that I have seen failures locally with the 7 second timeout and 1 test case running at a time. I am running with a 2015 MacBook Pro though, which has a 2.2 GHz Quad-Core Intel Core i7 processor and 16 GB 1600 MHz DDR3 RAM. I'll hopefully be upgrading my machine soon!
from wallaby.
Not because of flakiness, but to wait on external hardware to do something that should cause the UI to update, I just wrote this little function:
@doc """
In a Wallaby test, wait up to the specified number of milliseconds for the
specified element to be present.
Note that Wallaby has its own timeout (apparently around 3 seconds) when
checking for an element, so that much delay is built in every time this
function is called or recurses.
"""
@spec await_element_for_ms(
parent :: Wallaby.Browser.parent(),
query :: Wallaby.Query.t(),
ms :: integer()
) :: Wallaby.Browser.parent()
def await_element_for_ms(parent, _selector, ms) when is_integer(ms) and ms <= 0 do
# Continue test
parent
end
def await_element_for_ms(parent, query, ms) when is_integer(ms) do
started_at = System.monotonic_time(:millisecond)
# This appears to take about 3 seconds
present? = Wallaby.Browser.has?(parent, query)
if present? do
# Continue test
parent
else
ended_at = System.monotonic_time(:millisecond)
elapsed = ended_at - started_at
await_element_for_ms(parent, query, ms - elapsed)
end
end
Maybe that would be useful for y'all?
If the maintainers would like to put this into Wallaby, feel free to use or adapt this code.
from wallaby.
Related Issues (20)
- Wallaby does not set Selenium sessionId correctly. HOT 3
- Wallaby doesn't find html elements anymore HOT 4
- One chromedriver per core becomes problematic with sufficiently many cores HOT 4
- Support Chrome DevTools HOT 2
- Unexpected output to console when running tests HOT 3
- LiveViewTest Driver HOT 1
- Error tracking db ownership when overriding the useragent of the session HOT 1
- Uncaught TypeError: Cannot set properties of null (setting 'textContent') when field exists (or seems to)
- Multiple wallaby configs for different umbrella apps HOT 4
- chromedriver 115.0.5790.102 not working HOT 10
- Passed capabilities may be passed in the wrong format HOT 1
- Modify capabilities while keeping metadata in user agent HOT 2
- Wallaby test issue HOT 1
- js_errors: false config is being ignored
- Is it possible to configure "headless: true | false" at session opening? HOT 2
- Chrome is activated but the test times out HOT 4
- `run_command.sh` improvements HOT 1
- Running wallaby `feature` tests in VS Code HOT 1
- Minor thing: change wording of docs --> browser / users are not the same. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wallaby.