btomas btomas - 3 months ago 39
C# Question

Teststack.White not always finds Tab's child control

Got some random issue with finding control. Issue happens with control that is located in the tab. I do use some logic to select the tab if not selected and get the control. For example I got 3 ribbon tabs in WPF application:

mTarget.Tabs.ATab.FindTab();
mTarget.Tabs.ATab.SelectTab();
mTarget.Tabs.ATab.FindAndValidateTreeView();


Code always finds the tab using title text in FindTab() method:

var criteria = SearchCriteria.ByText(mTabTitle);
mTabPage = mMainWindow.Get<TabPage>(criteria);


But not always finds a control inside the tab when tab is already selected before the test:

// TreeView
var mTree = TabPage.Items.Find(x => x.Id == TabNames.TREE_ID && x.Name == TabNames.TREE_ID) as Tree;


Similar random issue I get with other controls like Ribbon groups when looking child controls. The only thing I noticed that if I select another tab and re-run the test won't fail.

Why this happens and how to get round this issue??
I use default White's settings on caching.

Answer

It may fail to find a control second time so I had to improve my code by converting to class variable once it is already found:

// TreeView
if (mTree == null)
    mTree = TabPage.Items.Find(x => x.Id == TabNames.TREE_ID && x.Name == TabNames.TREE_ID) as Tree;
Comments