Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Add PixelMatcher to CaptureSupport. #248

Merged
merged 15 commits into from Feb 27, 2016

Conversation

hastebrot
Copy link
Member

Problem

In TestFX 3 GuiTest created screenshots when errors occurred, i.e. when a Node for a mouse interaction wasn't found or an verifyThat() assertion failed. We need to port this functionality to TestFX 4 FxRobot and FxAssert.

Solution

Extend CaptureSupport which allows to capture nodes and regions (i.e. a desktop, screen, stage, scene, bounds) as an in-memory Image. It is possible to annotate captured images with rectangles (e.g. the area of missing nodes) and texts (e.g. the assertion error text).

interface CaptureSupport {
    // capture methods.
    Image captureNode(Node node);
    Image captureRegion(Rectangle2D region);

    // load and save methods.
    Image loadImage(Path path);
    void saveImage(Image image, Path path);

    // annotation and match methods.
    Image annotateImage(Shape shape, Image image);
    PixelMatcherResult matchImages(Image image0, Image image1, PixelMatcher matcher);
}

A PixelMatcher allows to match two images and return a match result.

interface PixelMatcher {
    PixelMatcherResult match(Image image0, Image image1);
    boolean matchColors(Color color0, Color color1);

    WritableImage createEmptyMatchImage(Image image0, Image image1);
    Color createMatchColor(Color color0, Color color1);
    Color createNonMatchColor(Color color0, Color color1);
}

class PixelMatcherResult {
    public PixelMatcherResult(Image matchImage, long matchPixels, long totalPixels) {}

    public Image getMatchImage() {}
    public long getTotalPixels() {}
    public long getMatchPixels() {}
    public long getNonMatchPixels() {}
    public double getMatchFactor() {}
    public double getNonMatchFactor() {}
}

Testing

PixelMatcherResult::getNonMatchPixels() varies between Java versions for the same Scene, e.g. Java 1.8.31 and 1.8.72.


Subtask of: #167

@hastebrot hastebrot changed the title (feat) Add ScreenCapture and PixelMatcher support. (feat) Add ScreenCapturer and PixelMatcher support. Feb 23, 2016
@hastebrot hastebrot force-pushed the feat-capture-support branch 2 times, most recently from 39b292e to 218f54f Compare February 23, 2016 10:13
@hastebrot hastebrot changed the title (feat) Add ScreenCapturer and PixelMatcher support. (feat) Add PixelMatcher to CaptureSupport. Feb 26, 2016
@hastebrot
Copy link
Member Author

FxRobot and FxService need a method to describe screenshot captures.

interface CaptureBuilder {
    CaptureBuilder capture(Bounds bounds);
    CaptureBuilder annotateWith(Shape shape);

    CaptureBuilder saveTo(Path path);
    Image toImage();
}

hastebrot added a commit that referenced this pull request Feb 27, 2016
(feat) Add PixelMatcher to CaptureSupport.
@hastebrot hastebrot merged commit 43f8277 into TestFX:master Feb 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant