-->

CodedUI object creation based on UITestControl

2019-06-07 12:59发布

问题:

My question is a continuation on the following CodedUI not recognizing HtmlControl when searched within scope of UITestControl instead of BrowserWindow question.

I'm experiencing the same problem and I would like to know why this is happening. Here are my findings.

BrowserWindow inherits from ApplicationUnderTest, which on his own inherits on ApplicationBase, which again inherits from UITestControl.

All the controls as HtmlRow do contain a constructor requesting as a parameter UITestControl. From the experience I can confirm that, no mater if you pass in an instance of at example HtmlDiv or BrowserWindow, the control will construct and behave correctly.

This is a strange behavior I can't explain and needs a bit more analyzing.

I do see that I can replicate the same with the following case:

private readonly UITestControl _container;

protected Page(Process process)
{
    _container = BrowserWindow.FromProcess(process);
}

protected Page(UITestControl testControl)
{
    _container = testControl;
}

public UITestControl Container
{
    get { return _container; }
}

private HtmlEdit _startDateTextBox;

protected HtmlEdit StartDateTextBox
{
    get
    {
        if (_startDateTextBox == null)
        {
            _startDateTextBox = new HtmlEdit(Container);
            _startDateTextBox.SearchProperties.Add(HtmlControl.PropertyNames.Id, StartDateTextBoxId,
                PropertyExpressionOperator.Contains);
        }

        return _startDateTextBox;
    }
}

This example is failing, meanwhile I expect it should work as the following example works correctly:

private readonly BrowserWindow _container;

protected Page(Process process)
{
    _container = BrowserWindow.FromProcess(process);
}

public UITestControl Container
{
    get { return _container; }
}

private HtmlEdit _startDateTextBox;

protected HtmlEdit StartDateTextBox
{
    get
    {
        if (_startDateTextBox == null)
        {
            _startDateTextBox = new HtmlEdit(Container);
            _startDateTextBox.SearchProperties.Add(HtmlControl.PropertyNames.Id, StartDateTextBoxId,
                PropertyExpressionOperator.Contains);
        }

        return _startDateTextBox;
    }
}

If anyone has a clue about this problem, I'll be really curious to understand why.

Thanks

回答1:

are you able to send me a repro zip as I asked in the afore mentioned question? I would love to dive in to this since I was not able to repro based on the code provided.