-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
Using pytest/seleniumbase, I've added a custom pytest option "--check-links" , just not sure where to plugin sb.assert_no_404_errors() so that its executed after each page load. Similar to:
"--check-js # (Check for JavaScript errors after page loads.)"
Beta Was this translation helpful? Give feedback.
All reactions
Hi @webmoskal, --check-js
also detects broken links, and it does it in a way that's must faster than self.assert_to_404_errors()
. That's why it wasn't implemented in the same way, but more for specific pages within tests to speed things up. Here's a sample output from using --check-js
on https://seleniumbase.io/other/broken_page.html:
Exception: JavaScript errors found on https://seleniumbase.io/other/broken_page.html => [
{'level': 'SEVERE', 'message': 'https://seleniumbase.io/broken_links/bad_image_1.png - Failed to load resource: the server responded with a status of 404 ()', 'source': 'network', 'timestamp': 1633537464418},
{'level': 'SEVERE', 'message': 'https://seleniumbase.io/broke...
Replies: 4 comments
-
Hi @webmoskal, --check-js
also detects broken links, and it does it in a way that's must faster than self.assert_to_404_errors()
. That's why it wasn't implemented in the same way, but more for specific pages within tests to speed things up. Here's a sample output from using --check-js
on https://seleniumbase.io/other/broken_page.html:
Exception: JavaScript errors found on https://seleniumbase.io/other/broken_page.html => [
{'level': 'SEVERE', 'message': 'https://seleniumbase.io/broken_links/bad_image_1.png - Failed to load resource: the server responded with a status of 404 ()', 'source': 'network', 'timestamp': 1633537464418},
{'level': 'SEVERE', 'message': 'https://seleniumbase.io/broken_links/bad_image_2.png - Failed to load resource: the server responded with a status of 404 ()', 'source': 'network', 'timestamp': 1633537464419},
{'level': 'SEVERE', 'message': 'https://seleniumbase.io/broken_links/bad_image_3.png - Failed to load resource: the server responded with a status of 404 ()', 'source': 'network', 'timestamp': 1633537464422},
{'level': 'SEVERE', 'message': 'https://seleniumbase.io/broken_links/bad_image_4.png - Failed to load resource: the server responded with a status of 404 ()', 'source': 'network', 'timestamp': 1633537464422}]
I could potentially improve on that so that it automatically does line-spacing automatically, as seen above. The original has everything on one line.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks for a super quick response. Was wondering in general, in case I want to also inject Axe (accessibility test tool) for every page load.
Also, on the semi related. Have a page with <link rel="preconnect" href="https://fonts.gstatic.com">
in the <head>
, self.assert_to_404_errors()
Fails and --check-js
does not. From what I understand is that some sort of dns prefetch, is there a reason one would fail and another would not?
Beta Was this translation helpful? Give feedback.
All reactions
-
@webmoskal Looks like going to https://fonts.gstatic.com directly does return a 404 error, but since it's a preconnect, there's probably something that doesn't have the browser directly go there without the rest of the URL, or something like that. I'll update the self.assert_no_404_errors()
method to skip that particular check.
As for the Axe (accessibility test tool), that's a Chrome extension, and you can load Chrome extensions from the command-line with pytest using:
pytest --extension-zip=ZIPFILE
Beta Was this translation helpful? Give feedback.
All reactions
-
@webmoskal See https://github.com/seleniumbase/SeleniumBase/releases/tag/v1.66.10 for improvements to --check-js
output, self.assert_no_js_errors()
, and self.assert_no_404_errors()
.
Beta Was this translation helpful? Give feedback.