CodedUI object creation based on UITestControl

半世苍凉 提交于 2019-12-08 06:37:56

问题


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.



来源:https://stackoverflow.com/questions/31671337/codedui-object-creation-based-on-uitestcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!