Skip to content

Commit

Permalink
Fix consistently failing test: Selector with a wait (#135)
Browse files Browse the repository at this point in the history
* Fix consistently failing test: Selector with a wait

On moderately slow networks, the "selector with a wait" test fails.

This commit replaces the `--wait 2000` argument with `--wait-for "!!document.querySelector('section.secondary')"`.

Closes #134
  • Loading branch information
nielthiart authored Mar 9, 2024
1 parent 278fda2 commit 0268b0c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/run_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ shot-scraper https://simonwillison.net/ \
# JPEG quality
shot-scraper https://simonwillison.net/ \
-h 800 -o examples/simonwillison-quality-80.jpg --quality 80
# Selector with a wait
# Selector with a wait for remote page element
shot-scraper 'https://www.owlsnearme.com/?place=127871' \
--selector 'section.secondary' \
-o examples/owlsnearme-wait.jpg \
--wait 2000
--wait-for "!!document.querySelector('section.secondary')"
# Accessibility
shot-scraper accessibility https://datasette.io/ \
> examples/datasette-accessibility.json
Expand Down Expand Up @@ -103,6 +103,11 @@ shot-scraper examples/div-after-2-seconds.html \
shot-scraper examples/div-after-2-seconds.html \
-o examples/wait-for.png -w 300 -h 200 \
--wait-for "document.querySelector('div')"
# Selector with a wait
shot-scraper examples/div-after-2-seconds.html \
--selector 'div' \
-o examples/wait.png -w 300 -h 200 \
--wait 2100
# And using multi
echo '# empty file' > empty.yml
shot-scraper multi empty.yml
Expand Down Expand Up @@ -158,6 +163,12 @@ shot-scraper multi empty.yml
height: 200
wait_for: |-
document.querySelector("div")
# wait
- url: div-after-2-seconds.html
output: wait-multi.png
width: 300
height: 200
wait: 2100
' | shot-scraper multi - --fail)
# --bypass-csp
shot-scraper javascript github.com "async () => { await import('https://cdn.jsdelivr.net/npm/left-pad/+esm'); return 'content-security-policy ignored' }" -o examples/github-csp.json --bypass-csp
Expand Down

0 comments on commit 0268b0c

Please sign in to comment.