public BiaComboboxTest(MockAppFixture mockApp) { _mockApp = mockApp; var tab = new WPFTabControl(_mockApp.MainWindow.LogicalTree().ByType <System.Windows.Controls.TabControl>().Single()); tab.EmulateChangeSelectedIndex(7); }
public BiaToggleButtonTest(MockAppFixture mockApp) { _mockApp = mockApp; var tab = new WPFTabControl(_mockApp.MainWindow.LogicalTree().ByType <TabControl>().Single()); tab.EmulateChangeSelectedIndex(3); }
public void TestInitialize() { app = new WindowsAppFriend(Process.Start("Target.exe")); WindowsAppExpander.LoadAssembly(app, GetType().Assembly); dynamic win = app.Type(typeof(Application)).Current.MainWindow; dynamic grid = win._grid; dynamic target = app.Type<TabControl>()(); grid.Children.Add(target); target.ItemsSource = Enumerable.Range(0, 10).Select(i => "value " + i).ToArray(); tabControl = new WPFTabControl(target); }
public void TestInitialize() { app = new WindowsAppFriend(Process.Start("Target.exe")); WindowsAppExpander.LoadAssembly(app, GetType().Assembly); dynamic win = app.Type(typeof(Application)).Current.MainWindow; dynamic grid = win._grid; dynamic target = app.Type <TabControl>()(); grid.Children.Add(target); target.ItemsSource = Enumerable.Range(0, 10).Select(i => "value " + i).ToArray(); tabControl = new WPFTabControl(target); }
public void コントロール特定2() { AppVar main = _app.Type <Application>().Current.MainWindow; var tab = new WPFTabControl(main.LogicalTree().ByType <TabControl>().Single()); tab.EmulateChangeSelectedIndex(1); var userControl = main.LogicalTree().ByType("WpfApplication.DemoItemsControl").Single(); var listBox = new WPFListBox(userControl.LogicalTree().ByType <ListBox>().Single()); var textBoxAge = new WPFTextBox(listBox.GetItem(2).VisualTree().ByBinding("Age").Single()); textBoxAge.EmulateChangeText("50"); }
void Assert(string accessPath, WPFTabControl tabControl) => CaptureAdaptor.AddCode($"{accessPath}.SelectedIndex.Is({tabControl.SelectedIndex});");
public void コントロール特定() { // STEP1. // 複数のウィンドウ取得方法がある。 // 1.最前面のウィンドウを取得する。 var main = WindowControl.FromZTop(_app); // 2.アセンブリの正式名称を指定してウィンドウを取得する。 var main2 = WindowControl.IdentifyFromTypeFullName(_app, "WpfApplication.MainWindow"); // 3.ウィンドウタイトルを指定してウィンドウを取得する。 var main4 = WindowControl.IdentifyFromWindowText(_app, "Friendly Handson"); // 4.Application からアクセスしてメインウィンドウ=ターゲットのウィンドウを取得する。 var appWindow = _app.Type <Application>().Current.MainWindow; var main3 = new WindowControl(appWindow); // STEP2. // LogicalTree から対象のコントロールを取得する。 // ここで取得できるLogicalTree はFriendly 独自に列挙している。 var logical = main2.LogicalTree(); // .ByType<T>() で指定した型のコントロールを列挙する。 // .Single() で一つのコントロール用データに変換する。 AppVar tabCore = logical.ByType <TabControl>().Single(); var tabControl = new WPFTabControl(tabCore); tabControl.EmulateChangeSelectedIndex(1); tabControl.EmulateChangeSelectedIndex(0); // STEP3. // 独自コントロール(ユーザーコントロール)を取得する。 // 基本的にユーザーコントロールは1画面に一つなので.ByType() がおすすめ。 AppVar demoSimpleControlCore = logical.ByType("WpfApplication.DemoSimpleControl").Single(); // ここで取得するLogicalTree はDemoSimpleControl.xaml のルート要素から取得できるものとなる。 var innerLogicalTree = demoSimpleControlCore.LogicalTree(); // こんな方法でアクセスもできる。 var x = demoSimpleControlCore.Dynamic(); var fullNameCore = x.GetType().FullName; string fullName = fullNameCore; Console.WriteLine(fullName); // 動作は上と同じ。 //AppVar type = demoSimpleControlCore["GetType"](); //var fullNameCore = type["FullName"](); //string fullName = (string)fullNameCore.Core; // ユーザーコントロール配下のテキストボックスへアクセスする。 // x:Name をつけていればコントロール名でアクセス可能。 var textBox = new WPFTextBox(demoSimpleControlCore.Dynamic()._textBox); textBox.EmulateChangeText("abc"); // STEP4. // Window のDataContext(ViewModel)からコントロールを取得する。 var textBoxMail = new WPFTextBox(innerLogicalTree.ByBinding("Mail").Single()); textBoxMail.EmulateChangeText("[email protected]"); // Assertをかける。 Assert.AreEqual("[email protected]", textBoxMail.Text); // ComboBox を取得する。 var comboBoxLanguage = new WPFComboBox(innerLogicalTree.ByBinding("Language").Single()); comboBoxLanguage.EmulateChangeSelectedIndex(1); // GUIのテストシナリオ // https://github.com/Ishikawa-Tatsuya/WPFFriendlySampleDotNetConf2016 // シナリオテストをする場合、Driver は開発者、シナリオは開発者以外がかけるようになっている。 }