ささいなことですが。

Windowsアプリテスト自動化ライブラリFriendly開発者の日記です。

Friendly.UWP_α 0.0.5 をリリースしました。

すごい久しぶりのリリースです。半年以上ほったらかしてましたからねー。
www.nuget.org

そもそも、動かなくなってた

おいおいって感じですが。UWPの画面描画に関するオブジェクトの生成をメインスレッド以外で実行した場合、例外が発生するようになっていました。Microsoftも結構な破壊的変更をぶっこんできますねー。newもメインスレッドで実行するようにしました。

UWPAppFriendから現在のウィンドウを取得できるプロパティを追加

地味機能です。さらにそこからContentも取得できます。もちろんFriendlyの素の機能でもできますが、インテリセンス効いた方が格段に便利ですよね。

var content = app.CurrentWindow.Content;

VisualTree検索機能

WPFの時に評判の良かったツリーからの検索機能を実装しました。UWPはLogicalTreeってないんですねー。VisualTreeからタイプとバインディングで検索できるようにしています。

var tree = app.CurrentWindow.Content.VisualTree();

//型から取得
var textBox = tree.ByType("Windows.UI.Xaml.Controls.TextBox").Single();

//バインディングパスから取得
var button = tree.ByBinding("Execute").Single());

コントロールラッパーの作成開始

とりあえず、以下作りました。順次増やしていきます。

  • Button
  • CheckBox
  • RadioButton
  • ComoboBox
  • ListBox
  • TextBox

で、今のところこんな操作ができます。

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Codeer.Friendly.Dynamic;
using System.IO;
using VSHTC.Friendly.PinInterface;
using EnvDTE80;

namespace Friendly.UWP.Test
{
    [TestClass]
    public class TestAttach
    {
        [TestMethod]
        public void Test()
        {
            using (var app = new UWPAppFriend(new ByVisualStudio(Path.GetFullPath("../../../TargetApp/TargetApp.sln"))
            {
                VisualStudioPath = @"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe",
                ChangeVisualStudioSetting = (vs, dteSrc)=>
                {
                    var dte = dteSrc.Pin<DTE2>();
                    dte.Solution.SolutionBuild.SolutionConfigurations.Item(3).Activate();
                }
            }))
            {
                //Visual Tree取得
                var tree = app.CurrentWindow.Content.VisualTree();

                //テキストボックス
                var textBox = new TextBox(tree.ByType(TextBox.TypeFullName).Single());
                textBox.EmulateChangeText("abc");

                //ボタン
                var button = new Button(tree.ByBinding("Execute").Single());
                button.EmulateClick();

                //コンボボックス
                var comboBox = new ComboBox(tree.ByType(ComboBox.TypeFullName).Single());
                comboBox.EmulateChangeSelectedIndex(2);

                //リストボックス
                var listBox = new ListBox(tree.ByType(ListBox.TypeFullName).Single());
                listBox.EmulateChangeSelectedIndex(2);

                //ラジオボタン
                var radioButton = new RadioButton(tree.ByType(RadioButton.TypeFullName).Single());
                radioButton.EmulateCheck(true);

                //チェックボタン
                var check = new CheckBox(tree.ByType(CheckBox.TypeFullName).Single());
                check.EmulateCheck(true);

                //もちろん素のFriendlyの機能で、内部APIを直で実行できます。
                //背景色変更
                var mainPage = app.CurrentWindow.Content.Dynamic().Content;
                var color = app.Type("Windows.UI.Colors").Blue;
                var brush = app.Type("Windows.UI.Xaml.Media.SolidColorBrush")(color);
                mainPage.Content.Background = brush;
            }
        }
    }
}

実行結果です。
f:id:ishikawa-tatsuya:20160905010130p:plain