从编码的UI测试中的文本框中读取文本 [英] Read text from textbox in Coded UI Tests

查看:53
本文介绍了从编码的UI测试中的文本框中读取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编码的UI测试 WinEdit 类中存在错误/限制:覆盖 OnKeyDown 方法或订阅时到文本框中的 KeyDown 事件,将无法使用 WinEdit.Text 属性。

There is a bug/limitation in the Coded UI Test WinEdit class: when overriding the OnKeyDown method or subscribing to the KeyDown event in a text box, it is not possible to use the WinEdit.Text property.

也就是说,当您拥有这个...

That is, when you have this...

private void myTextbox_KeyDown(object sender, KeyEventArgs e)
{
    // ...
}

...这不起作用:

var edit = new WinEdit(ancestor);
edit.SearchProperties[WinControl.PropertyNames.ControlName] = "myTextbox";
edit.Text = "New value"; // This doesn't work

我找到了设置值此处:

var edit = new WinEdit(ancestor);
edit.SearchProperties[WinControl.PropertyNames.ControlName] = "myTextbox";
Mouse.Click(edit);
System.Windows.Forms.SendKeys.SendWait("New value");

我的问题:有谁知道读取值的解决方法?

My question: does anyone know a work-around for reading the value?

var edit = new WinEdit(Window);
edit.SearchProperties[WinControl.PropertyNames.ControlName] = "myTextbox";
string actual = edit.Text; // This doesn't work


推荐答案

我找到了工作-我周围:

I found a work-around myself:

[DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = CharSet.Auto)]
public static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, StringBuilder lParam);

const int WM_GETTEXT = 0x000D;

var edit = new WinEdit(Window);
edit.SearchProperties[WinControl.PropertyNames.ControlName] = "myTextbox";
var sb = new StringBuilder(1024);
SendMessage(edit.WindowHandle, WM_GETTEXT, sb.Capacity, sb);
string actual = sb.ToString();

这篇关于从编码的UI测试中的文本框中读取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆