mattheworiordan / capybara-screenshot

Automatically save screen shots when a Capybara scenario fails
MIT License
1.02k stars 168 forks source link

MHTML screenshots #285

Open AlexWayfer opened 3 years ago

AlexWayfer commented 3 years ago

As you wrote in the README:

Better looking HTML screenshots

By the default, HTML screenshots will not look very good when opened in a browser. This happens because the browser can't correctly resolve relative paths like <link href="/assets/...." />, which stops CSS, images, etc... from being loaded. To get a nicer looking page, configure Capybara with:

Capybara.asset_host = 'http://localhost:3000'

This will cause Capybara to add <base>http://localhost:3000</base> to the HTML file, which gives the browser enough information to resolve relative paths. Next, start a rails server in development mode, on port 3000, to respond to requests for assets:

rails s -p 3000

Now when you open the page, you should have something that looks much better. You can leave this setup in place and use the default HTML pages when you don't care about the presentation, or start the rails server when you need something better looking.

It's understandable, but not the best solution for each case, especially for CI (like GitHub Actions) with artifacts.


So, my suggestion is to make MHTML screenshots. Chrome supports it (you can try, it's wonderful!), maybe some other drivers (browsers) too.

TylerRick commented 2 years ago

Ooh, nice idea! I use .mhtml files all the time when saving web pages from a browser (so that they're self contained and contain all the assets they need).

It does seem like they could potentially help with this problem too...

TylerRick commented 2 years ago

Just noticed that ferrum has built-in support for saving as .mhtml (https://github.com/rubycdp/ferrum#mhtmloptions--string--integer). :eyes: :exclamation:

Not sure other drivers do, though (I doubt it). But I may play around with Cuprite/Ferrum now that I know it exists...