Esempio n. 1
0
        public void TestBindingExtensions()
        {
            AppVar target  = _ctrl;
            AppVar button1 = target.LogicalTree().ByBinding("Button1Command").Single();

            Assert.IsTrue(button1.Equals(_ctrl._button1));

            var collection = target.LogicalTree().ByBinding("DataText");

            Assert.AreEqual(2, collection.Count);

            var textBox = target.LogicalTree().ByBinding("DataText", new ExplicitAppVar(_ctrl.DataContext)).Single();

            Assert.IsTrue(textBox.Equals(_ctrl._textBox));
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
        public void TestNameTextExtensions()
        {
            AppVar target     = _ctrl;
            var    collection = target.LogicalTree().ByType <FrameworkElement>();
            string name       = collection.ByName("_listView").Single().Dynamic().Name;

            Assert.AreEqual("_listView", name);
        }
Esempio n. 4
0
        public void TestTextExtensions()
        {
            AppVar target     = _ctrl;
            var    collection = target.LogicalTree().ByType <TextBlock>();
            string name       = collection.ByText("AAA").Single().Dynamic().Name;

            Assert.AreEqual("_textBlockA", name);
        }
Esempio n. 5
0
        public void TestContentTextExtensions()
        {
            AppVar target     = _ctrl;
            var    collection = target.LogicalTree().ByType <ContentControl>();
            string name       = collection.ByContentText("abc").Single().Dynamic().GetType().Name;

            Assert.AreEqual("CheckBox", name);
        }
Esempio n. 6
0
        public void TestTypeExtensions()
        {
            AppVar target     = _ctrl;
            var    collection = target.LogicalTree().ByType(typeof(Button).FullName);

            Assert.AreEqual(2, collection.Count);
            collection = target.LogicalTree().ByType <Button>();
            Assert.AreEqual(2, collection.Count);
            collection = target.LogicalTree().ByType <ButtonBase>();
            Assert.AreEqual(3, collection.Count);

            var list = target.LogicalTree().ByType(typeof(ListView).FullName).Single();

            Assert.AreEqual(list, _ctrl._listView);
            list = target.LogicalTree().ByType <ListView>().Single();
            Assert.AreEqual(list, _ctrl._listView);
        }
Esempio n. 7
0
        public void TestToArray()
        {
            AppVar target     = _ctrl;
            var    collection = target.LogicalTree().ByType <FrameworkElement>().ToArray();
            var    listView   = collection.Where(e => (string)e.Dynamic().GetType().FullName == typeof(ListView).FullName).Single().Dynamic();

            string name = listView.Name;

            Assert.AreEqual("_listView", name);
        }
Esempio n. 8
0
        public void TestLogicalAncestors()
        {
            var collection = ((AppVar)_ctrl._button1).LogicalTree(TreeRunDirection.Ancestors);

            Assert.AreEqual(collection[0], _ctrl._button1);
            Assert.AreEqual(collection[collection.Count - 1], _app.Type <Application>().Current.MainWindow);

            AppVar item = ((AppVar)_ctrl._listView).VisualTree().ByType <ListViewItem>()[0];

            collection = item.LogicalTree(TreeRunDirection.Ancestors);
            Assert.AreEqual(1, collection.Count);
        }
Esempio n. 9
0
        public void TestFirstOrDefault()
        {
            AppVar target     = _ctrl;
            var    collection = target.LogicalTree().ByType <FrameworkElement>();
            string name       = collection.ByName("_listView").FirstOrDefault().Dynamic().Name;

            Assert.AreEqual("_listView", name);

            var notFound = collection.ByName("xxxxxx").FirstOrDefault();

            Assert.IsTrue(notFound == null);
        }
Esempio n. 10
0
        public void コントロール特定()
        {
            AppVar main        = _app.Type <Application>().Current.MainWindow;
            var    userControl = main.LogicalTree().ByType("WpfApplication.DemoSimpleControl").Single();

            var logicalTree = userControl.LogicalTree();

            var textBoxX          = new WPFTextBox(userControl.Dynamic()._textBox);
            var textBoxMail       = new WPFTextBox(logicalTree.ByBinding("Mail").Single());
            var comboBoxxLanguage = new WPFComboBox(logicalTree.ByBinding("Language").Single());
            var buttons           = userControl.LogicalTree().ByType <Button>();
            var buttonOpen        = new WPFButtonBase(buttons.ByCommand(ApplicationCommands.Open).Single());
            var button1           = new WPFButtonBase(buttons.ByCommandParameter("1").Single());
            var buttonA           = new WPFButtonBase(buttons.ByCommandParameter((AppVar)_app.Type().WpfApplication.EnumPram.A).Single());
            var buttonCancel      = new WPFButtonBase(buttons.ByIsCancel().Single());
        }
Esempio n. 11
0
        public void コントロール特定3()
        {
            WindowsAppExpander.LoadAssembly(_app, GetType().Assembly);
            WPFStandardControls_3_5.Injection(_app);

            AppVar main        = _app.Type <Application>().Current.MainWindow;
            var    userControl = main.LogicalTree().ByType("WpfApplication.DemoSimpleControl").Single();
            var    elements    = _app.Type(GetType()).GetDemoSimpleControlElements(userControl);

            var textBlokX         = new WPFTextBlock(elements.TextBlockXName);
            var textBlokMail      = new WPFTextBlock(elements.TextBlockMail);
            var textBlokxLanguage = new WPFTextBlock(elements.TextBlockLanguage);

            var textBoxX          = new WPFTextBox(elements.TextBoxXName);
            var textBoxMail       = new WPFTextBox(elements.TextBoxMail);
            var comboBoxxLanguage = new WPFComboBox(elements.ComboBoxLanguage);
            var buttonOpen        = new WPFButtonBase(elements.ButtonOpen);
            var button1           = new WPFButtonBase(elements.Button1);
            var buttonA           = new WPFButtonBase(elements.ButtonA);
            var buttonCancel      = new WPFButtonBase(elements.ButtonCancel);
        }
Esempio n. 12
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 は開発者、シナリオは開発者以外がかけるようになっている。
        }