Open iancampelo opened 8 years ago
The OpenFileDialog is just another Window containing UI Items. Best is to write yourself a small Page Object Class that you can pass the FileDialog Window and then expose the required functionality to your Test or Productive code.
This should be a workable Example that you should be able to directly use. The Automation IDs are fixed for Windows7. Not sure if they change between Windows Versions.
Hope it helps.
TestStack.White.UIItems.WindowItems.Window openFileDialogWindow = MethodToLocateTheOpenFileDialogWindow();
var openFileDialogWindowWrapper = new OpenFileDialogWrapper(openFileDialogWindow);
openFileDialogWindowWrapper.FilePaths.EditableText = "SomePathToAFile";
openFileDialogWindowWrapper.OkButton.Click();
internal class OpenFileDialogWrapper : TestStack.White.UIItems.WindowItems.Window
{
private readonly TestStack.White.UIItems.WindowItems.Window _window;
public OpenFileDialogWrapper (TestStack.White.UIItems.WindowItems.Window window)
{
_window = window;
LoadControls();
}
public TestStack.White.UIItems.Button CancelButton { get; private set; }
public TestStack.White.UIItems.Button OkButton { get; private set; }
public TestStack.White.UIItems.ListBoxItems.ComboBox FilePaths { get; private set; }
public TestStack.White.UIItems.ListBoxItems.ComboBox FileTypeFilter { get; private set; }
public TestStack.White.UIItems.WindowStripControls.ToolStrip AddressBar { get; private set; }
#region Overwrite all the TestStack.White.UIItems.WindowItems.Window virtual functions
// For Example
public override string Title { get { return _window.Title; } }
#endregion
private void LoadControls()
{
CancelButton = _window.Get<TestStack.White.UIItems.Button>(SearchCriteria.ByClassName("Button").AndAutomationId("2"));
OkButton = _window.Get<TestStack.White.UIItems.Button>(SearchCriteria.ByClassName("Button").AndAutomationId("1"));
FilePaths = _window.Get<TestStack.White.UIItems.ListBoxItems.ComboBox>(SearchCriteria.ByAutomationId("1148"));
FileTypeFilter = _window.Get<TestStack.White.UIItems.ListBoxItems.ComboBox>(SearchCriteria.ByAutomationId("1136"));
AddressBar = _window.Get<TestStack.White.UIItems.WindowStripControls.ToolStrip>(SearchCriteria.ByClassName("ToolbarWindow32").AndAutomationId("1001"));
}
}
On Windows 7 the OkButton was not working for me. Eighter with AutomationId or SearchByName. Maybe the difference of the button:
Windows 10:
Windows 7 (turned of aero design):
I made it eork simply just pressing enter:
Keyboard.Instance.HoldKey(KeyboardInput.SpecialKeys.RETURN);
Keyboard.Instance.LeaveKey(KeyboardInput.SpecialKeys.RETURN);
Any other idea?
Hi guys,
How can I get OpenFileDialog and select the right file (I need to set the file place too)?
Thanks!