我是在我的智囊团,试图自动化我们的测试的Windows对话框。问题是自动化代码在某些机器上工作,但不是全部。它工作在我的本地盒和其他一些,但我们需要使它工作在我们的所有测试机器。有些东西是不一样的,但到目前为止我能看到的是
我尝试过的测试代码如下所示
..。
var app = FlaUI.Core.Application.Launch("FlaUISaveDialog.exe");
using (var automation = new UIA3Automation())
{
var window = app.GetMainWindow(automation);
var button1 = window.FindFirstDescendant(cf => cf.ByAutomationId("ClickIt"))?.AsButton();
button1?.Patterns.Invoke.PatternOrDefault.Invoke();
Thread.Sleep(2400); // Wait for window to appear!
var dialog = window.FindFirstDescendant(cf => cf.ByControlType(ControlType.Window));
Thread.Sleep(1000);
var fileNameTextBox = dialog.FindFirstDescendant(e => e.ByAutomationId("1001"));
fileNameTextBox.Focus();
fileNameTextBox.Patterns.Value.Pattern.SetValue(resultFile);
Thread.Sleep(2400);
//FlaUI.Core.Input.Keyboard.Press(VirtualKeyShort.RETURN);
var save = dialog.FindFirstChild(e => e.ByAutomationId("1").And(e.ByControlType(ControlType.Button)));
save.Focus();
var mousePoint = new Point(save.BoundingRectangle.X + save.BoundingRectangle.Width/2, save.BoundingRectangle.Y + save.BoundingRectangle.Height/2);
FlaUI.Core.Input.Keyboard.Press(VirtualKeyShort.RETURN);
//FlaUI.Core.Input.Mouse.Click(mousePoint);
//save.Patterns.Invoke.Pattern.Invoke();
Thread.Sleep(2400); // Wait for file save to complete
Assert.IsTrue(File.Exists(resultFile));
}发布于 2022-10-24 13:57:01
在接下来的一天里,我发现似乎是"SetValue“模式看起来起作用了,但并没有改变对话框的实际文件名。
但是移动鼠标,点击并按下面的方式输入实际上是有效的:
var fileNameTextBox = dialog.FindFirstDescendant(e => e.ByAutomationId("1001"));
var mousePoint = new Point(fileNameTextBox.BoundingRectangle.X + fileNameTextBox.BoundingRectangle.Width/2, fileNameTextBox.BoundingRectangle.Y + fileNameTextBox.BoundingRectangle.Height/2);
Thread.Sleep(1000);
FlaUI.Core.Input.Mouse.MoveTo(mousePoint);
FlaUI.Core.Input.Mouse.Click(mousePoint);
Thread.Sleep(1000);
FlaUI.Core.Input.Keyboard.TypeSimultaneously(VirtualKeyShort.CONTROL, VirtualKeyShort.KEY_A);
Thread.Sleep(1000);
FlaUI.Core.Input.Keyboard.Type(resultFile);
Thread.Sleep(1000);
FlaUI.Core.Input.Keyboard.Press(VirtualKeyShort.RETURN);编辑2:我似乎是Windows选项“查看文件扩展名”影响了"SaveFileDialog“的自动化行为。如果我们打开“查看文件扩展名”,"SetValue“模式就会开始工作。关闭启动和"SetValue“停止工作!至少可以说是出乎意料的!
https://stackoverflow.com/questions/74181075
复制相似问题