Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

inject a script/fixture at the end of every page load #1003

Answered by mdmintz
webmoskal asked this question in Q&A
Discussion options

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.)"

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
0 replies
Answer selected by mdmintz
Comment options

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?

You must be logged in to vote
0 replies
Comment options

@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

You must be logged in to vote
0 replies
Comment options

@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().

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /