Forum Discussion

WesWhit's avatar
WesWhit
Contributor
4 days ago

Unable to assert text in WPF ListView item

I am trying to assert the text of a specific cell in a WPF ListView item. 

but they are both identical except for the text. this is what I'm using to do the assertion but it's very flaky. It will always target "Asset 1" correctly when asked but will only sometimes target "Asset 2" when asked otherwise it targets the first in the list.  

Does anyone know how you can consistently target the cell you want when all attributes are identical? 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    What properties and property values are you using to refer to the object?



    • rraghvani's avatar
      rraghvani
      Champion Level 3

      The value of WPFControlAutomationID is "Name", which seems to be referring to the column name, and not "Asset 1" or "Asset 2"?

      Within the column, the text property may be shown as "Asset 1\nAsset 2\n", and cmpContains will check whether the property value contains the value e.g. "Asset 2". In theory, this should work.

      I'm not entirely sure what the issue is!?

  • it should but it doesn't. Here is how the list looks in the failing test 

    and this is the code that does the check.

    and this is what I get in the test report even though the item is there.

    even though I am specifically asking for the the second item it's still checking against the first 

    • rraghvani's avatar
      rraghvani
      Champion Level 3

      Just before the CheckProperty method, can you insert the following

      Sys.HighlightObject(Aliases.GDP.HwndSource_AssetsWindow.AssetsWindow.AssetList.Name_)
      Log.Message(Aliases.GDP.HwndSource_AssetsWindow.AssetsWindow.AssetList.Name_.text)

      Is it highlighting the correct UI control that you are referring to, and what log output is shown for text property?

      Also, the method assetList(name) is different to Assets.assetListValidation(name)!?

      • WesWhit's avatar
        WesWhit
        Contributor

        okay so using this above it just consistently targets the text in the  1st row of the name column and doesn't seem to know about any other rows. I then tried highlighting the whole of row 2 before hand but it still went back to Row 1. 

        so I have had to add the WPFControlText property to the name mapping and hook that up to a project variable. 

        then define the variables value as the text I'm looking for then do the property check.

        as long as it's there it pass but I will just have to accept that if it's slightly wrong it will say it doesn't exist but at least it will fail or pass when it should.