Comments (34)
Holy smokes! Nice work!! I thought I had it documented... (probably just buried) https://joelgriffith.github.io/navalia/chrome/constructor/. Probably should document it in the code as well.
This is a really nice feature that I'd like to write something about. Not sure if you'd be interested in sharing (Medium or whatever)? Could co-author the article? PEOPLE NEED TO KNOW!
from navalia.
Cool, I'll get a screenshot/gif for the article this evening!
from navalia.
All the work in Navalia is there now to support this in 0.0.17
. screenshot
now returns a base-64 encoded buffer when no filepath is supplied. This allows for custom Jest
methods to consume that, save snapshots, and do diffing.
I can start work on this Jest extension, but it's up for grabs as well :) I was going to pursue using https://github.com/mapbox/pixelmatch since it operates on Buffer'd data, and requires no outside libs like imagemagick
from navalia.
I'm going to close this out @joefraley, but we can continue discussing how to get this out to a wider audience. I think I'll try and write something up on Medium, have you and @anescobar1991 make any edits/tweaks you'd like?
from navalia.
Awesome I will take a look later today! And definitely need to myspace it. Very important medium to communicate this.
from navalia.
Yeah I'll see if I can find someone. If it's any help the reason I found Navalia and subsequently this issue was from reddit. So it does work whether it looks like you're gaining traction or not.
from navalia.
I like this idea a lot, and there's already an excellent package for doing image based snapshots.
There's a few tweaks that need to happen in Navalia to make this happen, but other than that it's just an education problem. I also need to get a RECIPES type file in this project, and this is a great opportunity for that
from navalia.
Cool, I'm happy to discuss a plan and contribute to that effort. It would definitely pay off for me!
What package do you have in mind for the snapshotting?
from navalia.
Awesome! Here's my opinion thus far (I'm open to feedback):
-
Expose the ability to not pass in a file-path in the
screenshot
method (should be located here:src/Chrome.ts
. Not passing in a FP will instead return the base64 string that Chrome generates for the screenshot. -
Recommend something like: https://github.com/americanexpress/jest-image-snapshot for screenshot diffing in Jest. We can easily add a HOWTO piece of documentation for how to achieve this type of workflow.
-
Profit
Since Jest has a nice API for diffing deltas (snapshoting) I'd rather not build the diff-ing portion in this repo. jest-image-snapshot
might fit the bill, but I haven't investigated what they're using internally to do the delta's (whereas something like https://github.com/mapbox/pixelmatch is doing it via array-buffers === faster and less setup confusion).
I think for this to really do well we'll probably have to paint the diff inside a terminal window... which might be tricky to achieve...
from navalia.
I agree, it seems awkward to include the diff engine here.
So I'm hearing that:
- we can get the base64 string from a screenshot 👍
- actionable item: expose this api
- We can use that to compare against other base64 strings and just leave that up to pixelmatch or jest 👍
- actionable item: document this integration
- We can make assertions about the differences
👍
- actionable item: document this strategy.
all low-hanging fruit.
but the thing I'm still not seeing is the developer niceties, like being presented with the differences, and not needing to manually manage the canonical base64 string. those are things that i want to be the purview of the tools. do you think those are features in the scope of this project? Part of what's so convenient about the jest snapshot workflow is that you don't have to keep track of your canonical image files by hand.
from navalia.
but the thing I'm still not seeing is the developer niceties, like being presented with the differences, and not needing to manually manage the canonical base64 string
On point. We'd need some way to present to the user the delta of the images, and for now I think this means rendering the delta inside a terminal (which is somewhat tricky). This I don't have a good answer for, but I'd be shocked if it didn't already exist.
Another approach would be to set a threshold of changes, and when it's breached prompt the user that a significant change has taken place and expose a link to the delta? That way we're only bound to showing a message as opposed to fully rendering inside a terminal.
What do you think your ideal workflow would be?
from navalia.
personally i think a link would be even better than the terminal approach
from navalia.
Cool. I guess the order might be:
- Prove that pixelmatch diffs correctly and that a good api interface is possible.
- Demonstrate linking Jest as a consumer.
- I guess this is the part that would store images for comparison, handle clean-up, etc
- Handle the diffing display. Which might involve demoing several different outputs/feedback loops. For example, I'm thinking about test watchers. I'm not sure how much of this Jest makes easy or difficult.
- Publicly document the results.
I think (1)
and (2)
can happen independently. Have you already used pixelmatch
or written a Jest interface in the past? I haven't done either, but could try both.
from navalia.
Yeah, 1
and 2
I haven't attempted. pixelmatch
looks fairly easy to consume, however the bulk of work is in writing the expect
extension for Jest as it will have to:
- Deal with the snapshotting (the snapshot extension API only has hooks for printing, not low-level file-handling), and persisting of snapshots
- Constructing failures + messaging
- Draw the diff, set it into a temporary place, and exposing it in the CLI
I think this would be a good MVP for the desired features, and we can iterate on it to make any improvements. For reference, here's a library that does effectively that https://www.npmjs.com/package/jest-image-snapshot. Might even consider using that to see how it does?
from navalia.
Hey guys I'm the maintainer for jest-image-snapshot and I'd be happy to collaborate with you guys on this! I haven't tried it yet but the way I see it you should be able to get a screenshot from chrome using your API and then just pass it to toMatchImageSnapshot()
.
toMatchImageSnapshot()
already replicates all of the jest toMatchSnapshot()
functionality, handles the failure messages and the places the diff in the file directory while exposing it on the CLI.
If there is something missing that you guys need let me know though as I am looking into using navalia
for my team's use cases and would love to improve on it.
from navalia.
@anescobar1991 nice!! I think that would fit the features in this issue, though I haven't tried it out yet. The biggest "gotta-have" was the ability to present some sort of diff to the user (which a link in to the png/image in the file-system is great). I'll give this a whirl and report back here if there's an issue.
from navalia.
@anescobar1991 sounds great! we were talking over in americanexpress/jest-image-snapshot#1
the dream api here would be if toMatchImageSnapshot()
accepted a base64 encoded buffer directly.
// actual is a base64 buffer
const actual = await chrome.goto(myComponentLib).then(() => chrome.screenshot())
expect.toMatchImageSnapshot(actual) 🔥
then i don't have to bother saving or reading anything by hand
from navalia.
We can (probably easily) translate the base64
buffer into just a good-ol' buffer to get the API's aligned
from navalia.
awesome! Let me know how it works. Without actually trying it out I think you can without any modification to either library do something like:
const actual = await chrome
.goTo(myComponentLib)
.screenshot();
expect(actual).toMatchImageSnapshot();
The reason I am saying it should work is that all I am doing is passing the image data directly to blink-diff which is what I use to do the actual image comparison and according to the blink-diff docs either a "PNGImage instance or a Buffer instance with PNG data" should work.
from navalia.
@joefraley have you attempted the above? My suspicion is that the buffer we have isn't encoded properly for consumption by PNGImage
from navalia.
yeah it didn't seem to work last i checked. blink-diff was throwing internally. let me repro real quick
from navalia.
Oddly enough it kinda worked for me, no thrown errors and a written snapshot. Snapshot I got was just a blank png though but I believe that is a chrome headless issue as I was seeing that before even with Selenium when running headless.
Are you guys seeing the same thing? I'm running Mac OS 10.12.5 with Chrome 59.0.3071.115 and [email protected]
from navalia.
I've noticed (and seen) issues in Chrome 59.x.x.x. I have Canary installed which generally seems to function properly with screenshots (Navalia will default to Canary over vanilla Chrome when present).
I'll try and give this some hands-on time tomorrow
from navalia.
Got it working with no modification! I discovered your undocumented way to pass chrome some flags and ran it without headless and got an image snapshot!
const chrome = new Chrome({ flags: { headless: false } });
it('should work', () => {
await chrome.goto(url);
await chrome.wait(elementToWaitOn);
const image = await chrome.screenshot();
await chrome.done();
expect(image).toMatchImageSnapshot();
});
from navalia.
Might also be good to get a discord channel or something like that going for faster iteration on stuff like this
from navalia.
Yeah I'd love to co author an article about this, just let me know where and how we can collaborate on it.
from navalia.
wow, good job @anescobar1991
from navalia.
@joefraley and @anescobar1991 I've done a pretty fast write-up here: https://medium.com/@griffith_joel/automatic-visual-regression-testing-23cc06471dd, leave whatever comments you'd like and I can publish it (also can tweet/share/mail/friendster/myspace it around)
from navalia.
Thanks for the feedback! I've updated and did some tweaks to the article
@anescobar1991 could you give it a quick read through? Some sections have changed a bit to accommodate your feedback
@joefraley if you don't have time I can do the gif preview.
from navalia.
Looks great! Ship it!
from navalia.
from navalia.
Llooks really great! Any plan to get it on reddit, hackernews, etc...?
from navalia.
I've made some attempts.... HN doesn't really give me much love. If you know someone with some "push" there let me know (same with Reddit). I'll upvote away!
from navalia.
I'll try and submit another later today
from navalia.
Related Issues (20)
- Setting window size causes screenshot test to timeout HOT 1
- Add firefox support HOT 1
- Is there anyway to press enter in a textbox? HOT 3
- Can you show an example script on how to run navalia on windows? HOT 2
- Implement mouseDown HOT 2
- Get current URL HOT 3
- #wait(Number) crashes with timeout HOT 2
- Screenshots are blank after resizing browser on 1.2.0 HOT 1
- Cannot take screenshot after resizing browser HOT 1
- Not working with Chrome Stable (Version 62.0.3202.62) HOT 4
- Trying to grok 'Error: [object Object]' HOT 1
- Need to set local storage values HOT 1
- RFC: Remove GraphQL? HOT 2
- .select throws ReferenceError: option is not defined HOT 1
- `navalia.run` errors with a 404 HOT 9
- Goto failed to load in the timeout specified HOT 3
- What do I do after installing Navalia to execute a test script?
- Unable to run with Jest in create-react-app environment HOT 1
- Navalia closes chrome after page load HOT 1
- Is this project still active? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from navalia.