1

I am at my wits end, trying to automate our tests for the Windows SaveAs-dialog. The thing is that the automation code works on some machines but not all. It works on my local box and a few other, but we need to make it work on all our test machines. Something is different but what I can see sofar is

  • Same windows version
  • Same dotnet --info

The test code I have tried to make work is something like

...

        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));
        }

1 Answers1

2

After another day going at this, I found that it seems to be the "SetValue" pattern that looks like it works, but doesn't change the Dialogs actual filename.

But moving the mouse,clicking and typing like below actually works:

        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);

Edit #2: I seems that it is the Windows Explorer option "View File name extensions" that affects the automation behavior of the "SaveFileDialog". If we turn on "View file name extensions" the "SetValue" pattern starts working. Turn the setting off and the "SetValue" stops working! Unexpected, to say the least!