rainmanwy / robotframework-SikuliLibrary

Sikuli Robot Framework Library provide keywords for Robot Framework to test UI through Sikuli.
Apache License 2.0
144 stars 61 forks source link

Keyword to drag from specific location to another location #62

Open Harri opened 6 years ago

Harri commented 6 years ago

It would be nice to have a keyword that could be used to drag from specific point to another specific point. In order it to be more robust, it should use reference image as an origo. So something like this:

@RobotKeyword("Drag from source point to offset point using refImg as origo.")
@ArgumentNames({"xSrc", "ySrc", "xOffset", "yOffset", "refImg"})
public void dragAndDropByLocation(int xSrc, int ySrc, int xOffset, int yOffset, String refImg) throws Exception {
    int result = 0;

    Match match = wait(refImg, Double.toString(this.timeout));
    Location origo = match.getCenter();

    Location srcLocation = new Location(origo + xSrc, origo + ySrc);
    Location newLocation = new Location(origo + xSrc + xOffset, origo + ySrc + yOffset);

    result = screen.dragDrop(srcLocation, newLocation);
    if (result==0) {
        capture();
        throw new ScreenOperationException("Failed to drag "+srcLocation +" to " +newLocation);
    }
}

I have not written Java in more than a decade, so no idea whether that works :) I hope the idea get through.

rainmanwy commented 6 years ago

@Harri , thanks for the suggestion. Could you describe why you need this keyword, i am not sure whether "Drag And Drop By Offset" is enough.

Harri commented 6 years ago

This can be used to scroll touch screens fairly easily. For example Android has bottom bar with right pointing triangle, circle and square. One could use any of those as an origo, then go 20 pixels up and drag 500 pixels up from there. This allows implementing scroll keywords that do not care at all what the application under test looks like, all we have to rely on is that there is the bottom bar with those three fixtures.

Or if you have a drawing app, you could use this to draw really simple pictures. Start from corner of the canvas, then move [+10px, +10px], start drawing to [+50px, +50px]. This enough is to test whether the drawing canvas registers touch correctly.

In general this is useful for creating keywords that only care about the surroundings of the thing we are testing. External application borders, canvas borders, etc.