2017-08-07 70 views
3

我在Visual Studio企业运行编码的UI测试2017C#编码的UI测试 - 文本输入到一个javascript window.prompt文本框

我测试的网页有一个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 = "[email protected]"; 

的亮点是围绕正确的控制绘制,但textInput.Text =行给出了一个错误 附加信息:控件类型不支持“文本”的SetProperty:窗口

任何想法我做错了什么?

+0

您确定您发布的代码是正在运行的代码吗?该错误表明控件类型错误。您不需要为类名称添加搜索属性,它将成为WinEdit定义的一部分。您不应该需要指定TechnologyName。在DrawHighlight调用中,突出显示文本区域还是整个确认弹出窗口? – MPavlak

+0

我是新来的,所以是的,这是代码运行,但我完全接受它可能既不是好也不是必要的代码。 drawhighlight就在文本区域周围。如果我确认confirmationPopup.DrawHighlight(),那么包围整个确认弹出窗口。 – gregm

回答

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

+0

互动,有一个'中间窗口'。我会尝试这种方法并回报。 - 谢谢 – gregm

+0

解决了,谢谢。问题是有一个'隐藏'(又名看起来不够硬),窗口内的窗口和文本输入是在 – gregm

相关问题