public void TestInitialize()
 {
     _app = new WindowsAppFriend(Process.Start(Target.Path));
     _main = WindowControl.FromZTop(_app);
     _comboBox = new GcComboBoxDriver(_main.Dynamic()._comboBox);
     _comboBoxShiftJIS = new GcComboBoxDriver(_main.Dynamic()._comboBox_ShiftJIS);
 }
        public static AppVar Initialize(WindowsAppFriend app)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            string key = typeof(WindowControl).Module.Name + "[Initialize]";
            object ohterSystemAnalyzersObj;
            if (!app.TryGetAppControlInfo(key, out ohterSystemAnalyzersObj))
            {
                //自身のアセンブリをロードさせる。
                WindowsAppExpander.LoadAssembly(app, typeof(TargetAppInitializer).Assembly);

                //WpfAnalyzerをコンパイルしてインストール
                AppVar ohterSystemAnalyzers = null;
                try
                {
                    app["System.Windows.Application.Current"]()["Windows"]()["Count"]()["ToString"](); //ここでWPFのライブラリがロードできるかチェックする。
                    if ((bool)app[typeof(TargetAppInitializer), "InstallWpfInApp"]().Core)
                    {
                        AppVar wpfAnalyzer = app.Dim(new NewInfo("Codeer.Friendly.Windows.Wpf.Grasp.WpfAnalyzer"));
                        ohterSystemAnalyzers = app.Dim(new IOtherSystemWindowAnalyzer[1]);
                        ohterSystemAnalyzers["[]"](0, wpfAnalyzer);
                    }
                }
                catch { }
                if (ohterSystemAnalyzers == null)
                {
                    ohterSystemAnalyzers = app.Dim(new IOtherSystemWindowAnalyzer[0]);
                }
                app.AddAppControlInfo(key, ohterSystemAnalyzers);
                ohterSystemAnalyzersObj = ohterSystemAnalyzers;
            }
            return ohterSystemAnalyzersObj as AppVar;
        }
Beispiel #3
0
        public void TestButtonClick()
        {
            app.LoadAssembly(GetType().Assembly);
            app.LoadAssembly(typeof(Cell).Assembly);
            app.LoadAssembly(typeof(WindowControl).Assembly);
            app.LoadAssembly(typeof(FormsControlBase).Assembly);
            var    cell = app.Dim(new Cell());
            string t    = (string)cell["GetType"]()["Assembly"]()["ToString"]().Core;

            app[GetType(), "AAA"]();

            FormsButton button = new FormsButton(testDlg["button"]());

            button.EmulateClick();
            int count = (int)testDlg["async_counter"]().Core;

            Assert.AreEqual(1, count);

            //非同期
            app[GetType(), "ClickEvent"](button.AppVar);
            button.EmulateClick(new Async());
            new NativeMessageBox(testDlg.WaitForNextModal()).EmulateButtonClick("OK");
            count = (int)testDlg["async_counter"]().Core;
            Assert.AreEqual(2, count);
        }
Beispiel #4
0
        public void TestExpandAssemblyFile()
        {
            WindowControl targetForm = WindowControl.FromZTop(app);

            WindowsAppExpander.LoadAssemblyFromFile(app, typeof(ExpandMethods).Assembly.Location);
            app[typeof(ExpandMethods), "SetText"]("xxx", targetForm.AppVar);
            Assert.AreEqual(targetForm["Text"]().ToString(), "xxx");
            Assert.AreEqual((int)app[typeof(ExpandMethods), "GetDataValue"](new Data(3)).Core, 3);
        }
Beispiel #5
0
        public void TestMaxPostMessage2()
        {
            WindowControl targetForm = WindowControl.FromZTop(app);

            app[typeof(Thread), "Sleep", new Async()](20000);
            targetForm["_incValue"](0);
            for (int i = 0; i < 11000; i++)
            {
                targetForm["Inc", new Async()]();
            }
            Assert.AreEqual(targetForm["_incValue"](), 11000);
        }
        public void TestEmulateChangeSelect()
        {
            FormsComboBox comboBox = new FormsComboBox(testDlg["comboBox"]());

            comboBox.EmulateChangeSelect(2);
            Assert.AreEqual(2, comboBox.SelectedItemIndex);

            //非同期
            app[GetType(), "SelectEvent"](comboBox.AppVar);
            comboBox.EmulateChangeSelect(1, new Async());
            new NativeMessageBox(testDlg.WaitForNextModal()).EmulateButtonClick("OK");
            Assert.AreEqual(1, comboBox.SelectedItemIndex);
        }
Beispiel #7
0
        public void EmulateSelectDayTest()
        {
            FormsMonthCalendar monthcalendar = new FormsMonthCalendar(testDlg["monthCalendar1"]());

            monthcalendar.EmulateSelectDay(new DateTime(2013, 10, 30));
            DateTime datetime = monthcalendar.SelectedDay;

            Assert.AreEqual(new DateTime(2013, 10, 30), datetime);
            // 非同期
            app[GetType(), "ChangeDateTimeEvent"](monthcalendar.AppVar);
            monthcalendar.EmulateSelectDay(new DateTime(2013, 10, 25), new Async());
            new NativeMessageBox(testDlg.WaitForNextModal()).EmulateButtonClick("OK");
            datetime = monthcalendar.SelectedDay;
            Assert.AreEqual(new DateTime(2013, 10, 25), datetime);
        }
 public void Attach()
 {
     _core.Attach();
     _app = new WindowsAppFriend(_core.Process);
     MainForm = new MainFormDriver(new WindowControl(_app, _core.Process.MainWindowHandle));
     InitApp();
 }
Beispiel #9
0
        public void TestInitialize()
        {
            //attach to target process!
            var path = Path.GetFullPath("../../../Target/bin/Debug/Target.exe");

            _app = new WindowsAppFriend(Process.Start(path));
        }
Beispiel #10
0
 public static OrderDocumentUserControlDriver AttachOrderDocumentUserControl(this WindowsAppFriend app, string identifier)
 //アプリの全てのウィンドウからTypeが一致するものを取得
 => app.GetTopLevelWindows().
 SelectMany(e => e.GetFromTypeFullName("WpfDockApp.OrderDocumentUserControl")).
 //その中でタイトルが一致するものを取得
 Where(e => GetTitle(e) == identifier).
 FirstOrDefault()?.Dynamic();
Beispiel #11
0
 public ClickModalOrSync(WindowsAppFriend app, ClickModal <T> .ShowModal show, ClickModal <T> .CreateWindowDriver create, ClickSync.Sync sync)
 {
     _app    = app;
     _show   = show;
     _create = create;
     _sync   = sync;
 }
Beispiel #12
0
        /// <summary>
        /// VOICEROID2への接続を試みます。
        /// 既に接続されている場合でも再接続を試みます。
        /// 接続に成功していれば、IsValidがtrueを返すようになります。
        /// </summary>
        public void TryToAttach()
        {
            foreach (Process p in Process.GetProcessesByName("VoiceroidEditor"))
            {
                if (p.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }
                else if (CheckIfIsValidWindowTitle(p.MainWindowTitle))
                {
                    TimedAction(() => {
                        app         = new WindowsAppFriend(p);
                        rootControl = new WindowControl(app, p.MainWindowHandle);

                        if (rootControl == null)
                        {
                            Detach();
                            return;
                        }

                        wpfControls = new WPFControls(rootControl);
                    }, 5000);
                }
            }
        }
        public static WindowsAppFriend Start()
        {
            if (_app != null)
            {
                bool exist = false;
                try
                {
                    exist = Process.GetProcessById(_app.ProcessId) != null;
                }
                catch { }

                if (!exist)
                {
                    _app = null;
                }
            }

            if (_app == null)
            {
                _app = ProcessController.Start();
            }
            else
            {
                _app.ResetTimeout();
            }

            return(_app);
        }
Beispiel #14
0
        public AppDriver()
        {
            var process = Process.Start("EmployeeManagement.exe");

            _app     = new WindowsAppFriend(process);
            MainForm = new MainFormDriver(new WindowControl(_app, process.MainWindowHandle));
        }
        public void TestErrorCLRForecast()
        {
            Process process = null;

            try
            {
                if (IntPtr.Size == 4)
                {
                    process = Process.Start(TargetPath.Path32);
                }
                else
                {
                    process = Process.Start(TargetPath.Path64);
                }
                using (WindowsAppFriend app = new WindowsAppFriend(process, "2.0")) { }
                using (WindowsAppFriend app = new WindowsAppFriend(process, "4.0")) { }
                WindowsAppFriend appCpuTest = new WindowsAppFriend(process);
                Assert.IsTrue(false);
            }
            catch (FriendlyOperationException e)
            {
                Assert.AreEqual(e.Message, "CLRのバージョンが予測できません。" + Environment.NewLine +
                                "対象アプリ内に複数のCLRがロードされている可能性があります。" + Environment.NewLine +
                                "対象のCLRのバージョンを明示するコンストラクタを使用してください。");
            }
            finally
            {
                process.Kill();
            }
        }
Beispiel #16
0
        /// <summary>
        /// 起動きりたん(Process) I/O取得
        /// </summary>
        private void controlvoiceroid()
        {
            //VOICEROID起動
            Process watch;

            watch = Process.GetProcessesByName("VOICEROID")[0];

            var w    = new WindowsAppFriend(watch);
            var main = WindowControl.FromZTop(w);

            //テキストボックス
            tb = main.IdentifyFromZIndex(2, 0, 0, 1, 0, 1, 1);

            //再生ボタン
            playbtn = new FormsButton(main.IdentifyFromZIndex(2, 0, 0, 1, 0, 1, 0, 3));

            //保存ボタン
            savebtn = new FormsButton(main.IdentifyFromZIndex(2, 0, 0, 1, 0, 1, 0, 1));
            //main.GetFromWindowText(" 再生") 用spy++ 去看function 找出來
            //new FormsButton(指定某個東西 EXmain.GetFromWindowText(" 再生")).EmulateClick(); 點他(event)
            //或是main.IdentifyFromZIndex 一層一層往下找 跟psy++ 所標得 大小相同就是那個object


            ShowWindow(FindWindow(main.IdentifyFromZIndex(0).WindowClassName, null), 2);
        }
Beispiel #17
0
 public void Attach()
 {
     _core.Attach();
     _app     = new WindowsAppFriend(_core.Process);
     MainForm = new MainFormDriver(new WindowControl(_app, _core.Process.MainWindowHandle));
     InitApp();
 }
Beispiel #18
0
        /// <summary>
        /// もし <see cref="IProcessOperation"/> 実装クラスならば、
        /// すべてのモーダルウィンドウに WM_CLOSE メッセージを送信する。
        /// </summary>
        protected static void CloseAllModalsIfProcessOperation(ITalker talker)
        {
            try
            {
                var processOpe = talker as IProcessOperation;
                if (processOpe == null)
                {
                    return;
                }
                var mainWinHandle = processOpe.MainWindowHandle;
                if (mainWinHandle == IntPtr.Zero)
                {
                    return;
                }

                using (var app = new WindowsAppFriend(mainWinHandle))
                {
                    while (true)
                    {
                        var topWin = WindowControl.FromZTop(app);

                        // メインウィンドウなら処理終了
                        if (topWin == null || topWin.Handle == mainWinHandle)
                        {
                            break;
                        }

                        topWin.SendMessage(WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                    }
                }
            }
            catch { }
        }
        public void TestContextNotDisposedByGC()
        {
            WindowsAppFriend app2 = null;

            if (IntPtr.Size == 4)
            {
                app2 = new WindowsAppFriend(Process.Start(TargetPath.Path32), "2.0");
            }
            else
            {
                app2 = new WindowsAppFriend(Process.Start(TargetPath.Path64), "2.0");
            }

            try
            {
                WindowControl targetForm = WindowControl.FromZTop(app2);
                //実行コンテキストを変更
                ExecuteContext context = new ExecuteContext(app2, targetForm.AppVar);
                var            old     = app2.ChangeContext(context);
                //古いコンテキストを破棄
                old.Dispose();

                //nullにしてもapp2が持っているのでコンテキストは破棄されない
                context = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();

                //これは正常に動くこと
                app2.Dim();
            }
            finally
            {
                Process.GetProcessById(app2.ProcessId).CloseMainWindow();
            }
        }
 public void TestInitialize()
 {
     app = new WindowsAppFriend(Process.Start("Target.exe"));
     WindowsAppExpander.LoadAssembly(app, GetType().Assembly);
     dynamic main = app.Type<Application>().Current.MainWindow;
     dataGrid = new WPFDataGrid(app.Type<WPFDataGridTest>().InitDataGrid(main._grid));
 }
Beispiel #21
0
        /// <summary>
        /// 認証コードを取得する。
        /// VOICEROID2エディタが実行中である必要がある。
        /// </summary>
        /// <returns>認証コードのシード値</returns>
        public static string GetKey(string process_name)
        {
            // VOICEROIDエディタのプロセスを検索する
            Process[] voiceroid_processes = Process.GetProcessesByName(process_name);
            if (voiceroid_processes.Length == 0)
            {
                return(null);
            }
            Process process = voiceroid_processes[0];

            // プロセスに接続する
            WindowsAppFriend app = new WindowsAppFriend(process);

            WindowsAppExpander.LoadAssembly(app, typeof(Injecter).Assembly);
            dynamic injected_program = app.Type(typeof(Injecter));

            try
            {
                // 認証コードを読み取って返す
                return(injected_program.InjectedGetKey());
            }
            catch (Exception)
            {
                return(null);
            }
        }
 public void SetUp()
 {
     //テスト用の画面起動
     app     = new WindowsAppFriend(Process.Start(Settings.TestApplicationPath));
     testDlg = WindowControl.FromZTop(app);
     WindowsAppExpander.LoadAssemblyFromFile(app, GetType().Assembly.Location);
 }
 public void TestInitialize()
 {
     _app = new WindowsAppFriend(Process.Start("Target.exe"));
     WindowsAppExpander.LoadAssembly(_app, GetType().Assembly);
     dynamic main = _app.Type<Application>().Current.MainWindow;
     _ctrl = _app.Type<WPFListViewTest>().Init(main._grid);
 }
Beispiel #24
0
        void initVoiceroid2()
        {
            voiceroidProcess = GetOrStartVoiceroid();
            var timeout = TimeSpan.FromSeconds(30);
            var begin   = DateTime.Now;

            _app = new WindowsAppFriend(voiceroidProcess);
            while (DateTime.Now - begin < timeout)
            {
                try
                {
                    uiTreeTop = WindowControl.FromZTop(_app);
                    var editUis = uiTreeTop.GetFromTypeFullName("AI.Talk.Editor.TextEditView")[0].LogicalTree();

                    talkTextBox = new WPFTextBox(editUis[4]);
                    playButton  = new WPFButtonBase(editUis[6]);
                    stopButton  = new WPFButtonBase(editUis[11]);
                    beginButton = new WPFButtonBase(editUis[15]);
                    break;
                }
                catch (Exception ev2)
                {
                    Console.WriteLine("waiting VOICEROID2 init :{0}", ev2.Message + ev2.StackTrace);
                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #25
0
        WindowsAppFriend FindTargetVs()
        {
            var devenvs = System.Diagnostics.Process.GetProcessesByName("devenv");

            foreach (var e in devenvs)
            {
                if (0 == e.MainWindowTitle.Length)
                {
                    continue;
                }

                //for developing.
                if (e.MainWindowTitle.IndexOf("Friendly.UWP") != -1)
                {
                    continue;
                }

                using (var app = new WindowsAppFriend(e))
                {
                    var dte      = GetDTE2(app);
                    var solution = dte.Solution;
                    var s        = solution.FileName;
                    if (string.Compare(s, Solution, true) != 0)
                    {
                        continue;
                    }
                }
                return(new WindowsAppFriend(e));
            }
            return(StartVisualStudio());
        }
Beispiel #26
0
        /// <summary>
        /// https://hgotoh.jp/wiki/doku.php/documents/voiceroid/tips/tips-003 様より
        /// </summary>

        // テキスト転記と再生ボタン押下
        public static void Talk(string talkText)
        {
            if (hWnd == IntPtr.Zero)
            {
                hWnd = GetVoiceroid2HWnd();
            }

            if (hWnd == IntPtr.Zero)
            {
                Console.WriteLine("VOICEROID2を起動してください。");
                return;
            }

            try
            {
                // プロセスに接続する
                var app = new WindowsAppFriend(hWnd);

                // テキスト入力欄と再生ボタンを特定する
                var uiTreeTop    = WindowControl.FromZTop(app);
                var textEditView = uiTreeTop.GetFromTypeFullName("AI.Talk.Editor.TextEditView")[0].LogicalTree();
                var talkTextBox  = new WPFTextBox(textEditView[4]);
                var playButton   = new WPFButtonBase(textEditView[6]);

                // テキストを入力し、再生する
                talkTextBox.EmulateChangeText(talkText);
                playButton.EmulateClick();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                hWnd = IntPtr.Zero;
            }
        }
Beispiel #27
0
        public void TestErrorCLR()
        {
            Process process = null;

            try
            {
                if (IntPtr.Size == 4)
                {
                    process = Process.Start(TargetPath.Path32);
                }
                else
                {
                    process = Process.Start(TargetPath.Path64);
                }
                WindowsAppFriend appCpuTest = new WindowsAppFriend(process, "3.5");
                Assert.IsTrue(false);
            }
            catch (FriendlyOperationException e)
            {
                Assert.AreEqual(e.Message, "対象プロセスの操作に失敗しました。" + Environment.NewLine +
                                "以下の可能性が考えられます。" + Environment.NewLine +
                                "・CLRのバージョン指定が間違っている。" + Environment.NewLine +
                                "・対象プロセスを操作する権限が足りていない。" + Environment.NewLine +
                                "・接続中に対象プロセスが終了した。" + Environment.NewLine +
                                "・指定のウィンドウハンドルのウィンドウが破棄された。" + Environment.NewLine +
                                "スプラッシュウィンドウを表示するアプリケーションの場合は、起動直後にメインウィンドウがスプラッシュウィンドウになっている場合があります。" + Environment.NewLine +
                                "明示的に期待のウィンドウのハンドルを指定してください。");
            }
            finally
            {
                process.Kill();
            }
        }
        public void WinForms()
        {
            var app = new WindowsAppFriend(Process.Start("WinForms.exe"));
            var mainForm = app.Type().System.Windows.Forms.Application.OpenForms[0];

            //WinFormsの場合は変数名で取りましょう。
            var _buttonX = new FormsButton(mainForm._buttonX);
            _buttonX.EmulateClick();

            //ポップアップメニューも変数からとる
            var _toolStripMenuItemA = new FormsToolStripItem(mainForm._toolStripMenuItemA);
            _toolStripMenuItemA.EmulateClick();

            //とは言え、取れないときも
            //そんなときは工夫する
            WindowsAppExpander.LoadAssembly(app, GetType().Assembly);
            var button名無し = new FormsButton(app.Type().Tips.ChildControl.Get名無し(mainForm));
            button名無し.EmulateClick();

            //メニューアイテムも上位ライブラリ使えばインデックスとかテキストから取れたり
            var menu = new FormsToolStrip(mainForm._contextMenuStrip);
            var b = menu.FindItem("B");
            b.EmulateClick();

            Process.GetProcessById(app.ProcessId).Kill();
        }
Beispiel #29
0
        /// <summary>
        /// AppVarを宣言
        /// 宣言する元はこの関数内で接続する
        /// これでも、WindowsAppFriendがGCで消されないことを証明したい
        /// </summary>
        /// <param name="process">プロセス</param>
        /// <returns>AppVar</returns>
        private static AppVar DimAppVar(Process process)
        {
            WindowsAppFriend appCpuTest = new WindowsAppFriend(process, "2.0");
            AppVar           list       = appCpuTest.Dim(new List <int>());

            return(list);
        }
 public void でもさけれるならその方がいいよね()
 {
     var app = new WindowsAppFriend(Process.Start("WinForms.exe"));
     var form = app.Type().System.Windows.Forms.Application.OpenForms[0];
     form.CountA(@"c:\TestData\data.txt");
     Process.GetProcessById(app.ProcessId).Kill();
 }
Beispiel #31
0
        public void TestCpuTarget()
        {
            Process process = null;

            try
            {
                if (IntPtr.Size != 4)
                {
                    process = Process.Start(TargetPath.Path32);
                }
                else
                {
                    process = Process.Start(TargetPath.Path64);
                }
                WindowsAppFriend appCpuTest = new WindowsAppFriend(process, "2.0");
                Assert.IsTrue(false);
            }
            catch (FriendlyOperationException e)
            {
                Assert.AreEqual(e.Message, "プラットフォームターゲットがテスト対象とテストプロセスで異なります。合わせてください。");
            }
            finally
            {
                process.Kill();
            }
        }
 public void TestErrorCLR()
 {
     Process process = null;
     try
     {
         if (IntPtr.Size == 4)
         {
             process = Process.Start(TargetPath.Path32);
         }
         else
         {
             process = Process.Start(TargetPath.Path64);
         }
         WindowsAppFriend appCpuTest = new WindowsAppFriend(process, "3.5");
         Assert.IsTrue(false);
     }
     catch (FriendlyOperationException e)
     {
         Assert.AreEqual(e.Message, "対象プロセスの操作に失敗しました。" + Environment.NewLine +
             "以下の可能性が考えられます。" + Environment.NewLine +
             "・CLRのバージョン指定が間違っている。" + Environment.NewLine +
             "・対象プロセスを操作する権限が足りていない。" + Environment.NewLine +
             "・接続中に対象プロセスが終了した。" + Environment.NewLine +
             "・指定のウィンドウハンドルのウィンドウが破棄された。" + Environment.NewLine +
             "スプラッシュウィンドウを表示するアプリケーションの場合は、起動直後にメインウィンドウがスプラッシュウィンドウになっている場合があります。" + Environment.NewLine +
             "明示的に期待のウィンドウのハンドルを指定してください。");
     }
     finally
     {
         process.Kill();
     }
 }
 public void TestCpuTarget()
 {
     Process process = null;
     try
     {
         if (IntPtr.Size != 4)
         {
             process = Process.Start(TargetPath.Path32);
         }
         else
         {
             process = Process.Start(TargetPath.Path64);
         }
         WindowsAppFriend appCpuTest = new WindowsAppFriend(process, "2.0");
         Assert.IsTrue(false);
     }
     catch (FriendlyOperationException e)
     {
         Assert.AreEqual(e.Message, "プラットフォームターゲットがテスト対象とテストプロセスで異なります。合わせてください。");
     }
     finally
     {
         process.Kill();
     }
 }
Beispiel #34
0
        public Yukari()
        {
            Process process = null;

            var processList = Process.GetProcessesByName("VoiceroidEditor");

            //VOICEROID2が起動していない
            if (processList.Length == 0)
            {
                Process.Start(@"C:\Program Files (x86)\AHS\VOICEROID2\VoiceroidEditor.exe");
                while (processList.Length == 0 || processList[0].MainWindowTitle != "VOICEROID2" || processList[0].MainWindowHandle == IntPtr.Zero)
                {
                    processList = Process.GetProcessesByName("VoiceroidEditor");
                    Thread.Sleep(500);
                }
                process = processList[0];
            }
            else
            {
                process = processList[0];
            }

            mainWindowHandle = process.MainWindowHandle;

            _app      = new WindowsAppFriend(process);
            uiTreeTop = WindowControl.FromZTop(_app);

            var editUis = uiTreeTop.GetFromTypeFullName("AI.Talk.Editor.TextEditView")[0].LogicalTree();

            talkTextBox = new WPFTextBox(editUis[4]);
            playButton  = new WPFButtonBase(editUis[6]);
            saveButton  = new WPFButtonBase(editUis[24]);
        }
Beispiel #35
0
        static void Main(string[] args)
        {
            var app = new WindowsAppFriend(Process.GetProcessById(int.Parse(args[0])));
            var bin = app.HandOverResources(int.Parse(args[1]));

            File.WriteAllBytes(args[2], bin);
        }
        public void WPF()
        {
            var app = new WindowsAppFriend(Process.Start("Wpf.exe"));
            var window = app.Type().System.Windows.Application.Current.MainWindow;

            //ガタガタ言わずにx:Name使えばいいじゃん。
            var _textBox = new WPFTextBox(window._textBox);
            _textBox.EmulateChangeText("x:Name最高!");

            //嫌って言う人いるから頑張ったよ。
            AppVar windowAppVar = window;
            var logicalTree = windowAppVar.LogicalTree();
            var textBox = new WPFTextBox(logicalTree.ByBinding("Memo").ByType<System.Windows.Controls.TextBox>().Single());
            var textBlock = new WPFTextBlock(logicalTree.ByBinding("Memo").ByType<System.Windows.Controls.TextBlock>().Single());
            var buttonModal = new WPFButtonBase(logicalTree.ByBinding("CommandModal").Single());
            var buttonModalSequential = new WPFButtonBase(logicalTree.ByBinding("CommandModalSequential").Single());
            var buttonModeless = new WPFButtonBase(logicalTree.ByBinding("CommandModeless").Single());
            var listBox = new WPFListBox(logicalTree.ByBinding("Persons").Single());

            //VisualTreeにしか現れない要素は気を付けて
            var item = listBox.GetItem(20);
            var itemText = new WPFTextBlock(item.VisualTree().ByBinding("Name").Single());

            //これでもダメな場合は工夫してね!

            Process.GetProcessById(app.ProcessId).Kill();
        }
Beispiel #37
0
        static string SendKeysCore(WindowsAppFriend app, string keys)
        {
            var modifyed = new List <Keys>();

            int f(int n) => n >= 1 ? n * f(n - 1) : 1;

            while (!string.IsNullOrEmpty(keys))
            {
                var special = SpecialKeys.Select(e => new { e.Key, index = keys.IndexOf(e.Key), execute = e.Value }).Where(e => e.index != -1).OrderBy(e => e.index).FirstOrDefault();
                if (special == null)
                {
                    ModifyAndAdjustSendKeys(app, keys, modifyed);
                    break;
                }

                var before = keys.Substring(0, special.index);
                if (!string.IsNullOrEmpty(before))
                {
                    ModifyAndAdjustSendKeys(app, before, modifyed);
                }

                special.execute(KeyAction.DownUp, app, modifyed);

                keys = keys.Substring(special.index + special.Key.Length);
            }

            return(keys);
        }
        public void TestEmulateClick()
        {
            FormsToolStripItem item = new FormsToolStrip(testDlg["contextMenuStrip1"]()).GetItem(1);

            item.EmulateClick();
            int count = (int)testDlg["async_counter"]().Core;

            Assert.AreEqual(0, count);

            //非同期
            app[GetType(), "ClickEvent"](testDlg.AppVar, item.AppVar);
            item.EmulateClick(new Async());
            new NativeMessageBox(testDlg.WaitForNextModal()).EmulateButtonClick("OK");
            count = (int)testDlg["async_counter"]().Core;
            Assert.AreEqual(0, count);
        }
Beispiel #39
0
        public void TestEmulateChangeSelectedIndex()
        {
            FormsCheckedListBox checkedlistbox1 = new FormsCheckedListBox(testDlg["checkedListBox1"]());

            checkedlistbox1.EmulateChangeSelectedIndex(4);
            string checkedlistbox1Text = checkedlistbox1.Text;

            Assert.AreEqual("Item-5", checkedlistbox1Text);

            //非同期
            app[GetType(), "ChangeSelectedIndexEvent"](checkedlistbox1.AppVar);
            checkedlistbox1.EmulateChangeSelectedIndex(2, new Async());
            new NativeMessageBox(testDlg.WaitForNextModal()).EmulateButtonClick("OK");
            checkedlistbox1Text = checkedlistbox1.Text;
            Assert.AreEqual("Item-3", checkedlistbox1Text);
        }
Beispiel #40
0
        static void SendSimpleModifyKeys(WindowsAppFriend app, string keys)
        {
            var modifyKeyUp = new List <Action>();

            foreach (var e in keys)
            {
                if (SpecialKeys.TryGetValue(e.ToString(), out var sendSpecialKey))
                {
                    sendSpecialKey(KeyAction.Down, app, new List <Keys>()); if (IsModifyKey(e.ToString()))
                    {
                        modifyKeyUp.Add(() => sendSpecialKey(KeyAction.Up, app, new List <Keys>()));
                    }
                    else
                    {
                        sendSpecialKey(KeyAction.Up, app, new List <Keys>());
                    }
                }
                else
                {
                    var keyCode = (Keys)e.ToString().ToUpper()[0];
                    app.KeyDown(keyCode);
                    app.KeyUp(keyCode);
                }
            }
            modifyKeyUp.Reverse();
            modifyKeyUp.ForEach(e => e());
        }
		public void TestInitialize()
		{
			_app = new WindowsAppFriend( Process.Start( Target.Path ) );
			var main = _app.Type<Application>().OpenForms[ 0 ];
			new FormsButton( main._buttonNormal ).EmulateClick( new Async() );
			var dlg = new WindowControl( main ).WaitForNextModal();
			_grid = new GcMultiRowDriver( dlg.Dynamic()._grid );
		}
 public void TestInitialize()
 {
     app = new WindowsAppFriend(Process.Start("Target.exe"));
     dynamic win = app.Type<Application>().Current.MainWindow;
     dynamic grid = win._grid;
     target = app.Type<ListBox>()();
     grid.Children.Add(target);
 }
 public void TestInitialize()
 {
     _app = new WindowsAppFriend(Process.Start(Target.Path));
     _main = WindowControl.FromZTop(_app);
     _textBox = new GcTextBoxDriver(_main.Dynamic()._textBox);
     _textBoxShiftJIS = new GcTextBoxDriver(_main.Dynamic()._textBoxShiftJIS);
     _multiLineText = new GcTextBoxDriver(_main.Dynamic()._multiLineText);
 }
 void ResetConnection()
 {
     int id = _app.ProcessId;
     _app.Dispose();
     _app = new WindowsAppFriend(Process.GetProcessById(id));
     dynamic main = _app.Type<Application>().Current.MainWindow;
     _ctrl = _app.Type<WPFListViewTest>().Init(main._grid);
 }
 public void TestInitialize() {
     app = new WindowsAppFriend(Process.Start("Target.exe"));
     WindowsAppExpander.LoadAssembly(app, GetType().Assembly);
     win = app.Type(typeof(Application)).Current.MainWindow;
     dynamic grid = win._grid;
     control = app.Type<WPFContextMenuTestControl>()();
     grid.Children.Add(control);
 }
 public void TestInitialize()
 {
     _app = new WindowsAppFriend(Process.Start(Target.Path));
     var main = WindowControl.FromZTop(_app);
     var a = new Async();
     new WPFButtonBase(main.Dynamic()._buttonXamOutlookBar).EmulateClick(a);
     _dlg = main.WaitForNextModal();
     _outlook = new XamOutlookBarDriver(_dlg.Dynamic()._outlook);
 }
 public void SetUp()
 {
     app = new WindowsAppFriend(Process.Start(TargetPath.NativeControls));
     EventChecker.Initialize(app);
     WindowControl main = WindowControl.FromZTop(app);
     NativeButton buttonTest = new NativeButton(main.IdentifyFromDialogId(1030));
     buttonTest.EmulateClick(new Async());
     testDlg = main.WaitForNextModal();
 }
 public void TestInitialize()
 {
     _app = new WindowsAppFriend(Process.Start("Target.exe"));
     WindowsAppExpander.LoadAssembly(_app, GetType().Assembly);
     dynamic main = _app.Type<Application>().Current.MainWindow;
     dynamic checkBox = _app.Type<CheckBox>()();
     main._grid.Children.Add(checkBox);
     _toggle = new WPFToggleButton(checkBox);
 }
Beispiel #49
0
        public void Test()
        {
            //アタッチ
            WindowsAppFriend app = new WindowsAppFriend(vsProcess);

            //DLLインジェクション
            WindowsAppExpander.LoadAssembly(app, GetType().Assembly);

            //Microsoft.VisualStudio.Shell.Package.GetGlobalServiceの呼び出し
            var dteType = app.Type(GetType()).DTEType;
            AppVar obj = app.Type().Microsoft.VisualStudio.Shell.Package.GetGlobalService(dteType);

            //注目!
            //インターフェイスでプロキシが作成できる!
            var dte = obj.Pin<DTE2>();
            var solution = dte.Solution;

            //ソリューション作成
            solution.Create(SolutionDir, "Test.sln");
            string solutionPath = Path.Combine(SolutionDir, "Test.sln");
            solution.SaveAs(solutionPath);

            //プロジェクト追加
            solution.AddFromTemplate(
                @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates\CSharp\Windows\1041\WPFApplication\csWPFApplication.vstemplate",
                Path.Combine(SolutionDir, "WPF"), "WPF", true);

            //保存
            solution.SaveAs(solutionPath);

            //閉じる
            solution.Close();

            //再度開く
            solution.Open(solutionPath);

            //クリーン→ビルド
            solution.SolutionBuild.Clean(true);
            solution.SolutionBuild.Build(true);

            //デバッグ
            solution.SolutionBuild.Debug();

            //デバッグ対象プロセスを操作
            var debProcess = System.Diagnostics.Process.GetProcessById(dte.Debugger.DebuggedProcesses.Item(1).ProcessID);
            using (var debApp = new WindowsAppFriend(debProcess))
            {
                debApp.Type().System.Windows.Application.Current.MainWindow.Close(new Async());
            }

            //編集モードに戻るまで待つ
            while (dte.Debugger.CurrentMode != dbgDebugMode.dbgDesignMode)
            {
                System.Threading.Thread.Sleep(10);
            }
        }
 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<ListBox>()();
     grid.Children.Add(target);
     target.ItemsSource = Enumerable.Range(0, 100).Select(i => "value " + i).ToArray();
     listBox = new WPFListBox(target);
 }
        public void TestInitialize()
        {
            _app = new WindowsAppFriend(Process.Start(Target.Path));
            var main = WindowControl.FromZTop(_app);
            var a = new Async();

            new FormsButton(main.Dynamic()._buttonFlexGrid).EmulateClick(a);
            _dlg = main.WaitForNextModal();
            _grid = new C1FlexGridDriver(_dlg.Dynamic()._grid);
        }
 internal static void Init(WindowsAppFriend app)
 {
     string key = typeof(Initializer).FullName;
     object isInit;
     if (!app.TryGetAppControlInfo(key, out isInit))
     {
         WindowsAppExpander.LoadAssembly(app, typeof(Initializer).Assembly);
         app.AddAppControlInfo(key, true);
     }
 }
        public void Win32()
        {
            var app = new WindowsAppFriend(Process.Start(Path.GetFullPath("../../../MFCDlg.exe")));

            //Win32の場合はWindowControlを使うのが現実的
            //もちろん自分でWin32APIを駆使して見つけることも可能
            var w = WindowControl.IdentifyFromWindowText(app, "MFCDlg");

            Process.GetProcessById(app.ProcessId).Kill();
        }
 public void TearDown()
 {
     if (app != null)
     {
         app.Dispose();
         Process process = Process.GetProcessById(app.ProcessId);
         process.CloseMainWindow();
         app = null;
     }
 }
        /// <summary>
        /// Install RM.Friendly.WPFStandardControls.3.dll to target process.
        /// </summary>
        /// <param name="app">Application manipulation object.</param>
#else
        /// <summary>
        /// 対象プロセスにRM.Friendly.WPFStandardControls.3.dllをインジェクションします。
        /// </summary>
        /// <param name="app">アプリケーション操作クラス。</param>
#endif
        public static void Injection(WindowsAppFriend app)
        {
            string key = typeof(WPFStandardControls_3).FullName;
            object isInit;
            if (!app.TryGetAppControlInfo(key, out isInit))
            {
                WindowsAppExpander.LoadAssembly(app, typeof(WPFStandardControls_3).Assembly);
                ResourcesLocal3.Initialize(app);
                app.AddAppControlInfo(key, true);
            }
        }
 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<Expander>()();
     grid.Children.Add(target);
     expander = new WPFExpander(target);
     window = new WindowControl(win);
 }
 internal static void Initialize(WindowsAppFriend app)
 {
     Type myType = typeof(Initializer);
     string key = myType.Module.Name + "[Initialize]";
     object isInit;
     if (!app.TryGetAppControlInfo(key, out isInit))
     {
         WindowsAppExpander.LoadAssembly(app, myType.Assembly);
         app.AddAppControlInfo(key, true);
     }
 }
 public void SetUp()
 {
     if (IntPtr.Size == 4)
     {
         app = new WindowsAppFriend(Process.Start(TargetPath.Path32), "2.0");
     }
     else
     {
         app = new WindowsAppFriend(Process.Start(TargetPath.Path64), "2.0");
     }
 }
 public void TearDown()
 {
     if (app != null)
     {
         new NativeButton(testDlg.IdentifyFromWindowText("OK")).EmulateClick();
         MessageBoxUtility.CloseAll(testDlg);
         app.Dispose();
         Process process = Process.GetProcessById(app.ProcessId);
         process.CloseMainWindow();
         app = null;
     }
 }
        public void SetUp()
        {
            _app = new WindowsAppFriend(Process.Start("Target.exe"));
            _mainWindow = WindowControl.FromZTop(_app);

            dynamic win = _app.Type<Application>().Current.MainWindow;
            dynamic grid = win._grid;
            _target = _app.Type<ProgressBar>()();
            grid.Children.Add(_target);

            WindowsAppExpander.LoadAssemblyFromFile(_app, GetType().Assembly.Location);
        }