ocornut / imgui_test_engine

Dear ImGui Automation Engine & Test Suite
386 stars 40 forks source link

Testing click and drag from a pop up #5

Closed peterigz closed 1 year ago

peterigz commented 1 year ago

I've run into an issue when testing clicking and dragging from a pop up window. I can see what's happening:

1) I ItemClick() the button that opens the popup. 2) I then use //$FOCUSED to get the pop up path to the button that I want to drag with ItemDragAndDrop() 3) Inside the ItemDragAndDrop it successfully finds the src and dst ref but then it calls WindowBringToFront(item_dst->Window->ID); which switches to the dst window. 4) Then it does MouseMove(ref_src, ImGuiTestOpFlags_NoCheckHoveredId); but now $FOCUSED points has the dst path instead so the src_ref isn't found anymore.

It seems to give pop up windows a generated path like "##Popup_438a024f" rather then the actual id for the pop up window so I'm not sure how to get a stable path to the item that I want to drag. I tried a wildcard too but couldn't get it to work with the pop up either (could be doing it wrong though, will keep testing.

Absolutely love this test engine though, will make life so much easier to test for bugs before each release, thanks for the hard work!

ocornut commented 1 year ago

Where are the src and dst items located (in/out the popup?). It seems like the issue is the WindowBringToFront() call should be avoided, favoring moving windows instead.

peterigz commented 1 year ago

Here's is the test code:

        t->TestFunc = [](ImGuiTestContext* ctx)
        {
            ctx->SetRef("Import Library");
            ctx->ItemClick(ICON_FA_SHAPES "##import_shapes");
            ctx->ItemClick("//$FOCUSED/sparkleflare.png#image");
            ctx->ItemDragAndDrop("//$FOCUSED/sparkleflare.png#image", "//Shapes");
        };

Import Library contains a button (ICON_FA_SHAPES) which opens a pop up containing a bunch of image buttons. I put ctx->ItemClick("//$FOCUSED/sparkleflare.png#image"); in there just to make sure it's finding it ok which it is. Shapes is another window where the drop target is.

Commenting out the WindowBringToFront() does work ok but I need to add a ctx->ItemClick("Shapes"); at the start of the test to make sure the window is in view (it's a tabbed window using the docking branch).

ocornut commented 1 year ago

Sorry for my late answer.

I realized it would make sense for functions like ItemDragAndDrop() to "lock" the ID so helpers such as //$FOCUSED are not reevaluated multiple times.

I believe it can easily be done by changing the MouseMove() calls in ItemDragAndDrop():

From:

MouseMove(ref_src, ImGuiTestOpFlags_NoCheckHoveredId);
[...]
MouseMove(ref_dst, ImGuiTestOpFlags_NoCheckHoveredId | ImGuiTestOpFlags_NoFocusWindow);

To

MouseMove(item_src->ID, ImGuiTestOpFlags_NoCheckHoveredId);
[...]
MouseMove(item_dst->ID, ImGuiTestOpFlags_NoCheckHoveredId | ImGuiTestOpFlags_NoFocusWindow);

It should be enough and then the WindowBringToFront() is not really a problem.

ocornut commented 1 year ago

Added a fix + a test in 016d97a Thank you for reporting!