Element not found when using a Coded Step in WPF Application

1 Answer 25 Views
Coded Steps WPF Testing
Garry
Top achievements
Rank 1
Garry asked on 21 Nov 2024, 03:33 PM

We have a WPF Application that when I use a coded step rather than a Test Step, I get an error message that the Element cannot be found. If the coded step is after a Test Step that does interact with the same page, the Element is found with no issues. 

Here is the Element example:

XamlTag=button,AutomationId=Vendor Search

If I set a breakpoint and open the DOM Explorer, and then close it, the Element is found as expected. Just stopping at the breakpoint is not enough, so it isn't an issue with waiting for the Element to be populated.

This issue also happens when we export our test to be a C# coded test. 

I have attached a video showing the behavior working and then breaking. We are unable to share the program with you since it is an internal application. 

Coded Step:

[CodedStep(@"Click VendorSearchButton")]
        public void Purchasing_CodedStep8()
        {
            System.Threading.Thread.Sleep(1000);
            Applications.IdsLocalRunnerexe.Purchasing__Webstaurant_Store_Inc__Inventory_Distribution_System.VendorSearchButton.Wait.ForExists();
            // Click VendorSearchButton    
            Applications.IdsLocalRunnerexe.Purchasing__Webstaurant_Store_Inc__Inventory_Distribution_System.VendorSearchButton.User.Click();

        }

Here is the code within the application setting the AutomationId:

<Button x:Name="NavigateButton" Margin="0,1,0,0" Command="{Binding CommandOnClick}" IsEnabled="{Binding Enabled}"
        Height="43" VerticalAlignment="Center" HorizontalAlignment="Stretch"
        Style="{StaticResource MenuItemButtonStyle}"
        AutomationProperties.Name="{Binding DisplayText}" 
        AutomationProperties.AutomationId="{Binding DisplayText}" 
        Visibility="{Binding IsEditable, Converter={StaticResource BooleanInverseVisibilityConverter}}">
    <TextBlock Foreground="{StaticResource MenuItemTextBrush}" FontSize="14" Padding="4"
               Visibility="{Binding IsEditable, Converter={StaticResource BooleanInverseVisibilityConverter}}">
        <Run Text="{Binding Index, Mode=OneWay}" FontWeight="Thin" /><Run Text="." FontWeight="Thin" />
        <Run Text="{Binding DisplayText, Mode=OneWay}" FontWeight="SemiBold" />
    </TextBlock>
</Button>

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Plamen Mitrev
Telerik team
answered on 25 Nov 2024, 01:25 PM

Hello Garry,

Thank you for sharing detailed information about the behavior and your observations. I will share my thoughts and suggestions and I hope we can work together to figure out a solution.

I watched the video with the limited context that I have so far and it seems that there is an issue with the coded step and the target element that it references. It is a bit blurry and I could not make out everything though. I will ask for a bit more troubleshooting information. If you are not comfortable sharing the Step Failure Details that include the Visual Tree of the application in the public forum post, please open a private technical support ticket from here.

Even though in this case the Wait and Verification steps might not be the solution, I would still strongly advise you to add them every time a new window is opened, or new content is loaded in the application. This will help you in the long run, when tests are executed on different machines and by different people on your team.

I see that your coded step starts with an execution delay of 1000 ms. I suggest that you add the code line below to refresh the Visual Tree and then another execution delay of 1000 ms after that. Let me know if that improved the behavior in any way, as this can be a clue for us about the underlining issue.

Manager.ActiveApplication.MainWindow.VisualTree.Refresh();   

In case the refreshed Visual Tree and the Wait/Verification steps do not help, please run the test again, so it fails, and attach the exported Step Failure Details either here or in a private support ticket. In addition to that, share the current version of your coded step and a screenshot from the application for where you need to click for a successful step. I will analyze that information and will have a better understanding about the issue.

Thank you for your detailed description so far. I am waiting for your reply.

Regards,
Plamen Mitrev
Progress Telerik

Virtual Classroom is the free self-paced technical training portal that gets you up to speed with Telerik and Kendo UI products including Telerik Test Studio! Check it out at https://learn.telerik.com/.
Garry
Top achievements
Rank 1
commented on 25 Nov 2024, 04:41 PM

Hello Plamen,

Sorry about the quality of the video, I have to trim and reduce the quality to make it small enough to be able to upload. 

Adding the "Refresh()" resolved the issue. Adding a "Wait.ForVisable()" did not resolve the issue, resulting in Element not found.  

This resolved the issue:

Manager.ActiveApplication.MainWindow.VisualTree.Refresh();   

 

Thank you,

Garry

Plamen Mitrev
Telerik team
commented on 26 Nov 2024, 08:24 AM

Hello Garry, thank you for testing both suggestions and confirming which worked and which did not. This information will benefit our team and it can also help someone else with a similar issue.

The behavior that your described and the fact that the Refresh() method worked, but the Wait step did not work, tells me that the issue is specific to the application under test. There is probably some different mechanics for how the Visual Tree is loaded. I could not reproduce this on several test WPF apps that we have here. I will be happy to debug the issue, if you can reproduce it in a sample WPF application and share it with me.

If you need help with anything else, please let us know.

Tags
Coded Steps WPF Testing
Asked by
Garry
Top achievements
Rank 1
Answers by
Plamen Mitrev
Telerik team
Share this question
or