Created
May 11, 2011 18:10
-
-
Save natritmeyer/966981 to your computer and use it in GitHub Desktop.
A tiny c# app that operates the Open File dialog using White. Useful if you're testing a WPF app with bewildr (http://www.bewildr.info) but the app you're testing uses the old Win32 dialog boxes. The compiled exe takes one arg; the value you want typed in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Create a console app, add references to the various white libraries and use the following as a template for operating the Open Dialog window | |
Get the white binaries from here: http://white.codeplex.com/ | |
*/ | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Windows.Automation; | |
using White.Core; | |
using White.Core.UIItems; | |
using White.Core.UIItems.Finders; | |
using White.Core.UIItems.WindowItems; | |
namespace OpenFile | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Application myApp = Application.Attach("YOUR_APP_PROCESS_NAME_HERE"); | |
List<Window> myWindows = myApp.GetWindows(); | |
Window openDialog = myWindows.Where(n => n.Name == "Open").First(); | |
TextBox textField = openDialog.Get<TextBox>(SearchCriteria.ByControlType(ControlType.Edit).AndByText("File name:")); | |
textField.Text = args.First(); | |
Button openButton = openDialog.Get<Button>(SearchCriteria.ByControlType(ControlType.Button).AndByText("Open")); | |
openButton.Click(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
childWindow.Get(SearchCriteria.ByAutomationId("1148")).Select(1);
var OpenButton = childWindow.Get(SearchCriteria.ByClassName("Button").AndAutomationId("1"));
OpenButton.DoubleClick();
works for me.