GDATASoftwareAG / robotframework-flaui

Windows user interface automation library for Robot-Framework. FlaUILibrary is a wrapper for the FlaUI automation library.
MIT License
60 stars 12 forks source link

Objects found with Find All Elements get destroyed #185

Closed djalan closed 6 months ago

djalan commented 6 months ago

Hello

I greatly appreciate the work you did by creating a vast library of keywords. But unfortunately, basic operations like the below do not work.

A simple change in the FOR loop causes the code to crash with:

FlaUiError: Element from XPath '<FlaUILibrary.flaui.util.automationelement.AutomationElement object at
0x0000021EED91A450>' could not be found

Here is a sample Robot file with 1 test that fails all the time and 2 others that pass all the time.

The nice thing about the last test is that it shows that an element can still be found using Xpath. It shows that FlaUI is still connected to the application.

*** Settings ***
Documentation       Flaui POC

Library             FlaUILibrary    uia=UIA3    screenshot_on_failure=False

*** Variables ***
${APP}      App.Windows.Exe

*** Test Cases ***
Carousel fails
    ${pid}    Attach Application By Name    ${APP}
    Log    ${pid}

    @{elements}    Find All Elements    //*[@AutomationId="CarouselMenuText"]

    FOR    ${element}    IN    @{elements}
        ${name}    Get Name From Element    ${element}    # CRASH
        Log    ${name}
    END

Carousel works all the time
    ${pid}    Attach Application By Name    ${APP}
    Log    ${pid}

    @{elements}    Find All Elements    //*[@AutomationId="CarouselMenuText"]

    FOR    ${element}    IN    @{elements}
        Log    ${element.Xpath}
    END

Carousel works too
    ${pid}    Attach Application By Name    ${APP}
    Log    ${pid}

    @{elements}    Find All Elements    //*[@AutomationId="CarouselMenuText"]

    FOR    ${element}    IN    @{elements}
        ${xpath}    Set Variable    ${element.Xpath}
        ${name}    Get Name From Element    ${xpath}
        Log    ${name}
    END

Notes: 1- This is a Windows application made with Avalonia 2- I will try the same 3 test cases with Calculator and post the results tomorrow morning.

Nepitwin commented 6 months ago

Hi @djalan

what did you expect on "Carousel fails" keyword?

Find All Elements returns a simple dictionary as a list which include informations about an xpath, classname or name.

Approaches like Carousel works all the time and Carousel works too are correct here and should work on xpaths.

On carousel fails you try to set the object as xpath and this is why you receive a flaui error with this object idenditifier.

This test should fail because it's not a xpath which is included into.

Nepitwin commented 6 months ago

I extend usage keyword to additionally use automation elements as reference for all keywords like your example.

So Carousel fails test case should work for all keywords like you handled.

So combination from Find All Elements and Keyword usage can be done.