C#编码的UI测试 - 在javascript window.prompt文本框中输入文本

时间:2017-08-07 12:54:08

标签: c# coded-ui-tests

我在Visual Studio Enterprise 2017中运行编码的UI测试。

我正在测试的网页上有一个javascript弹出窗口,要求输入一个电子邮件地址。我可以找到confirmationPopup(突出显示正确),我可以单击其中的按钮,例如取消。

confirmationPopup = new WinWindow();
confirmationPopup.SearchProperties.Add(WinWindow.PropertyNames.ControlType, "Dialog");
confirmationPopup.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "#32770");
confirmationPopup.TechnologyName = "MSAA";
confirmationPopup.Find();
confirmationPopup.DrawHighlight();

var cancelButton = new WinButton(confirmationPopup);
cancelButton.SearchProperties.Add(WinButton.PropertyNames.Name, "Cancel");
Mouse.Click(cancelButton);

我正在努力做的是在弹出的输入框中输入文字:

var textInput = new WinEdit(confirmationPopup);
textInput.SearchProperties.Add(WinEdit.PropertyNames.ClassName, "Edit");
textInput.TechnologyName = "MSAA";
textInput.DrawHighlight();
textInput.Text = "bill@microsoft.com";

突出显示在正确的控件周围,但textInput.Text = line给出错误 其他信息:控件类型不支持“文本”的SetProperty:窗口

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:1)

以下是与javascript提示窗口进行交互的示例。

// go to a public site which has a prompt
var window = BrowserWindow.Launch("http://www.javascriptkit.com/javatutors/alert2.shtml");

var contentDiv = new HtmlDiv(window);
contentDiv.SearchProperties.Add(HtmlDiv.PropertyNames.Id, "contentcolumn", PropertyExpressionOperator.EqualTo);

var promptButton = new HtmlInputButton(contentDiv);
promptButton.SearchProperties.Add(HtmlInputButton.PropertyNames.ControlDefinition, "name=\"B4\"", PropertyExpressionOperator.Contains);

promptButton.SetFocus();
Keyboard.SendKeys("{ENTER}");

// now the prompt is showing, find it and set text
var promptWindow = new WinWindow();
promptWindow.SearchProperties.Add(WinWindow.PropertyNames.ControlType, "Dialog");
promptWindow.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "#32770");

promptWindow.DrawHighlight();

var middleWindow = new WinWindow(promptWindow);
middleWindow.DrawHighlight();

var inputBox = new WinEdit(middleWindow);
inputBox.DrawHighlight();
inputBox.Text = "Hello world!";

当使用编码ui的检查功能时,我看到有一个中间窗口。使用与否,我能够找到编辑。

2 Windows