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

FlaUI unable to identify the change in Automation ID #79

Open
Muthuvenaktesh opened this issue Dec 23, 2022 · 13 comments
Open

FlaUI unable to identify the change in Automation ID #79

Muthuvenaktesh opened this issue Dec 23, 2022 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@Muthuvenaktesh
Copy link

Hi,

Thanks for the Support !!!

I am facing issue with the FlaUI with the latest version, I have my application opened already and attaching it to FlaUI with ID.

Getting an error that,

FlaUiError: Element from XPath '//*[@AutomationId="inst1-base-Sales-ringing"]' could not be found, but still it can be found with the FlaUI inspect and the element is visible in the screen. The ID of this button changes dynamically when some actions are triggered.

PFA attached screen shot - In the FlaUI inspect in details changed ID is reflecting , but in the summary it is old ID.

FlaUI_Id_Change

@Nepitwin
Copy link
Member

Nepitwin commented Dec 23, 2022

@Muthuvenaktesh

Did you refresh the flaui inspector? Because it's probably an old cache from flaui from element if you don't refresh you will not see any changes here on the inspector tool.

On Robotframework side you can check it on multiple ways.

By robotframework 5 IF Version

IF  Element Should Exist <XPATH_A>  ${FALSE}
  Log  Found Element A
ELSE IF  Element Should Exist <XPATH_B>  ${FALSE}
  Log  Found Element B
END

The second argument avoids an element not found exception and returns true if element could be found otherwise false.

So you can write your logic code what to do here aftewards your id was changed.

@Muthuvenaktesh
Copy link
Author

@Nepitwin , I have tried it, the framework is still not able to find the ID.

Is there any way we can refresh the cache from framework also.

@Nepitwin
Copy link
Member

@Muthuvenaktesh

All keywords from robotframework flaui will receive all gui element from user interface.

So if you use some of these keywords if the id was changed the element should be accessible.

Can you pls use the keyword

${RESULT}  Get Childs From Element  /Pane/Document
Log  ${RESULT}

Here you can verify if you Button element exists from child element and which automation properties they got. It's a keyword for debugging purpose to identify xpath from childs.

Only the inspector tool contains a cache implemented. To refresh by inspector tool simple use F5 the element should be updated if not the user automation id is not changed.

This could be verify by Get Childs From Element keywords.

@Muthuvenaktesh
Copy link
Author

Hi @Nepitwin ,

Tried using the command, with the tool I can see the change in ID, but the framework is still showing the old ID.

Refer the attached screen shot,

FlaUI_ID

@Nepitwin
Copy link
Member

Nepitwin commented Dec 27, 2022

Thanks for the information i look into FlaUI C# Code and found that code.

public override AutomationElement GetDesktop()
        {
            return Com.Call(() =>
            {
                var desktop = CacheRequest.IsCachingActive
                    ? NativeAutomation.GetRootElementBuildCache(CacheRequest.Current.ToNative(this))
                    : NativeAutomation.GetRootElement();
                return WrapNativeElement(desktop);
            });
        }

My first idea is that the Flag IsCachingActive is True so your first request stores all data but does not refresh, But in your use case you want to update the change. I think i can easily reproduce it now and fix it by an adittional new keyword

Disable Cache
Enable Cache

So afterwards your test can disable the caching feature and reenable it because it will be a heavy intensive operation. But for your use case you want to recognize the change.

@Nepitwin Nepitwin added the bug Something isn't working label Dec 27, 2022
@Nepitwin Nepitwin self-assigned this Dec 27, 2022
Nepitwin added a commit that referenced this issue Dec 28, 2022
Nepitwin added a commit that referenced this issue Dec 28, 2022
Nepitwin added a commit that referenced this issue Dec 28, 2022
Nepitwin added a commit that referenced this issue Dec 28, 2022
@Nepitwin
Copy link
Member

Nepitwin commented Dec 29, 2022

@Muthuvenaktesh

If you want to pre test changes you can install one of these wheel files from zip.

robotframework_flaui-1.0.549rc549.zip

This has now the ability to disable caching feature by Library include or by Keywords

Enable Caching
Disable Caching
${RESULT}  Is Cache Enabled
Refresh Cache
Library FlaUILibrary use_cache=True/False

Currently it's missing test by automation id change behavior like your mentioned. If it's implemented then this will be merged to main branch and released.

Nepitwin added a commit that referenced this issue Dec 29, 2022
Nepitwin added a commit that referenced this issue Dec 29, 2022
Nepitwin added a commit that referenced this issue Dec 29, 2022
Nepitwin added a commit that referenced this issue Dec 29, 2022
Nepitwin added a commit that referenced this issue Dec 29, 2022
Nepitwin added a commit that referenced this issue Dec 29, 2022
Nepitwin added a commit that referenced this issue Dec 29, 2022
@Nepitwin
Copy link
Member

@Muthuvenaktesh

After i write your use case that an automation id is changed by an interaction i can not reproduce your issue.

I extend my wpf test application by an button Change Automation Id.

image

If i click on it i will update the automation id property by C# Code.

private void ChangeAutomationId(object sender, RoutedEventArgs e)
        {
            if (sender is Button button)
            {
                button.SetValue(AutomationProperties.AutomationIdProperty, "ChangeAutomationIdUpdate");
            }
        }

Afterwards my test is quite simple

Element Should Be Updated If Property Is Changed
   [Setup]       Init Main Application
   [Teardown]    Stop Application  ${MAIN_PID}
   Element Should Exist      ${XPATH_BUTTON_ELEMENT_ORIGIN}
   Element Should Not Exist  ${XPATH_BUTTON_ELEMENT_CHANGED}
   ${CHILDS}  Get Childs From Element  ${MAIN_WINDOW_SIMPLE_CONTROLS}
   Log  ${CHILDS}
   Click                     ${XPATH_BUTTON_ELEMENT_ORIGIN}
   ${CHILDS}  Get Childs From Element  ${MAIN_WINDOW_SIMPLE_CONTROLS}
   Log  ${CHILDS}
   Element Should Not Exist  ${XPATH_BUTTON_ELEMENT_ORIGIN}
   Element Should Exist      ${XPATH_BUTTON_ELEMENT_CHANGED}

After the execution id was changed.

image

This is tested by robotframeowrk-flaui version 2.0.1.

Could it be that your test execution is too early that the automation id property does not change on your robot test?

Did you use an Wait Until Keyword Succeeds? Because i think your test is that you wait for an call an service instance is changing the id if the telephone is ringing. So your test has to wait an amount of time if this signal is coming to your application.

Nepitwin added a commit that referenced this issue Dec 29, 2022
Nepitwin added a commit that referenced this issue Dec 29, 2022
Nepitwin added a commit that referenced this issue Dec 29, 2022
@Muthuvenaktesh
Copy link
Author

Muthuvenaktesh commented Jan 3, 2023

Hi @Nepitwin,

Thanks for the support !!!

My requirement is as you said it was telephony app, so if the call was triggered by someone, it will reflect in my app that particular contact is ringing, active and hold.

Yes I have waited few seconds also for the ID to reflect .

Tried using Disable Caching and Refresh Cache keyword, still facing the same issue. new ID not getting reflected.

@Muthuvenaktesh
Copy link
Author

Hi @Nepitwin ,

Is there any way we can get the button attributes like background colour and border colour. If its there, I can validate the colours instead of ID's.

@Nepitwin
Copy link
Member

Nepitwin commented Jan 4, 2023

@Muthuvenaktesh

I analyze the code from flaui and found some properties --> https://github.com/FlaUI/FlaUI/blob/master/src/FlaUI.Core/FrameworkAutomationElementBase.Properties.cs

I would test it by my own if this values are the correct one and implement this feature to your response from #72

But one thing is clear if your solution will work by your changing of color codes then automation id should asweel work because these are all properties which are updated automatically by each request. Why this not working on your side i currently don't know sadly.

@Muthuvenaktesh
Copy link
Author

Hi @Nepitwin

Need a help !!! I wanted to try the same with class names.

I have class property in my exe, I can see it in the developer tools. But in the FlaUI inspect tool class name is showing as not supported. Please refer the below screen shot. Please let me know what could be the issue.

Have tried adding the value also, but its not showing in the tool.

Class_name

@Nepitwin
Copy link
Member

Nepitwin commented Jan 9, 2023

@Muthuvenaktesh

Intresting now i know which gui tool your use case is. It's not an desktop user interface element. This is quite easy to answer for you. This html5 elements are not implements with UIA3 or UIA2 interface from microsoft.

https://learn.microsoft.com/en-us/windows/win32/winauto/windows-automation-api-overview

I thought your application is based on a desktop application like wpf but it seems it's a hybrid application as html5 as dom tree usage. Yeah you probable see xpaths from this element on gui side but probably it's quite not supported to interact with them like your use case.

Did you think to use web application based testing libraries like

https://applitools.com/tutorials/quickstart/web/robot-framework

https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html

Which you can handle xpaths like robotframework-flaui by your dom tree.

FlaUI can be used for browser related testing but it's not recommended for my opinion because it handles windows automation based elements. If you want to test it you can try UIA2 interface maybe it's supported their if not you don't have access to an automation interface implementation from windows.

@schidach
Copy link

Hello,

I am having a similar problem to the original poster where robotframework-flaui is not picking up a dynamically changed property on an element. It is a WPF application, but unfortunately I don't have access to the source code, so I don't know exactly how this update is done in the code. I have tried using the Wait Until Element Exist, but it does not work in this scenario. When I log the elements using Get Childs From Element, I can see that the element still has the old property (Name in this case), but the screenshot taken at the same time shows that the UI has been updated. I think a "Refresh Cache" keyword would help in this scenario to force a new scan of the UI elements. Would it be possible for you to reimplement the "Refresh Cache" keyword for the newest version of robotframework-flaui for a test?
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants