1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

clarify AJAX wait behaviour example in README

I explained with some more details to the `!has_xpath/has_no_xpath` differences. 

I tried to use simple english and to
This commit is contained in:
Adrien Di Pasquale 2022-06-28 16:30:54 +02:00 committed by GitHub
parent 8350c78823
commit d179d2d871
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -795,13 +795,23 @@ Be aware that because of this behaviour, the following two statements are **not*
equivalent, and you should **always** use the latter!
```ruby
!page.has_xpath?('a')
page.has_no_xpath?('a')
# consider a page where the `a` tag is removed through AJAX after 1s
visit(some_path)
!page.has_xpath?('a') # is false
page.has_no_xpath?('a') # is true
```
The former would immediately fail because the content has not yet been removed.
Only the latter would wait for the asynchronous process to remove the content
from the page.
First expression:
- `has_xpath?('a')` is called right after the page visit. It is `true` because the link has not yet been removed
- Capybara does not wait upon successful assertions, therefore **it returns `true` right ahead**
- The expression returns `false` (because it is inverted with the leading `!`)
Second expression:
- `has_no_xpath?('a')` is called right after the page visit. It is `false` because the link has not yet been removed.
- Capybara waits upon failed assertions, therefore **it does not return `false` right ahead**
- Capybara will periodically re-check the assertion up to the `default_max_wait_time` defined
- after 1s, the assertion becomes `true` (because the link has been removed)
- The expression returns `true`
Capybara's RSpec matchers, however, are smart enough to handle either form.
The two following statements are functionally equivalent: