ocornut / imgui_test_engine

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

GatherItems can't see through childs and tables #11

Closed gan74 closed 1 year ago

gan74 commented 1 year ago

Hi! I am automating tests on an app using ImGui for its UI, and I am running into trouble with exploring childs, and more importantly tables. As the title states: GatherItems doesn't seem to be able to find items inside childs (BeginChild/EndChild) or tables BeginTable/EndTable), while it will find items inside things like tree nodes.

Here is a minimalist-ish test case.

    auto test = IM_REGISTER_TEST(engine, "tests", "gather childs");
    test->GuiFunc = [](ImGuiTestContext*) {
        if(ImGui::Begin("Window")) {
            if(ImGui::BeginChild("Child")) {
                ImGui::Button("Button1");
                ImGui::Button("Button2");
                ImGui::Button("Button3");
                ImGui::Button("Button4");
            }
            ImGui::EndChild();
            ImGui::End();
        }
    };
   test->TestFunc = [](ImGuiTestContext* ctx) {
        IM_CHECK_NE(ctx->ItemInfoOpenFullPath("//Window")->ID, 0);             // Ok
        IM_CHECK_NE(ctx->ItemInfoOpenFullPath("//Window/**/Button2")->ID, 0);  // Ok

        ImGuiTestItemList items;
        ctx->GatherItems(&items, "//Window");

        std::printf("%llu items\n", items.size());                             //  Only 2 items found, not sure what they are, but they do not match any of the expected items
        for(const ImGuiTestItemInfo& info : items) {               
            std::printf("    %x: '%s'\n", info.ID, info.DebugLabel);
        }

        IM_CHECK_GT(items.size(), 2);                                          // Fails: items.size() is 2
    };
ocornut commented 1 year ago

Right, this is missing and we should work on adding it (perhaps with an opt-in or opt-out flag).

ocornut commented 1 year ago

This should be fixed with a32597e, 223ca91.