Exemplo n.º 1
0
        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 は開発者、シナリオは開発者以外がかけるようになっている。
        }
Exemplo n.º 2
0
 /// <summary>
 /// インデクサ
 /// </summary>
 /// <param name="row"></param>
 /// <param name="col"></param>
 /// <returns></returns>
 public object this[int row, int col] {
     set { _core.Dynamic()[row, col] = value; }
     get { return(_core.Dynamic()[row, col]); }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 現在のショートカットキーを変更します。
 /// </summary>
 /// <param name="values">キーコード</param>
 public void EmulateChangeCurrent(int[] values)
 {
     AppVar.Dynamic().Focus();
     AppVar.Dynamic().Current = values;
 }