Exemplo n.º 1
0
        public void ButtonClickAsyncTest()
        {
            // Arrenge
            dynamic main       = _app.Type <Application>().Current.MainWindow;
            AppVar  buttonCore = _app.Type <Button>()();

            main._grid.Children.Add(buttonCore);
            dynamic       checker       = _app.Type <ButtonEventCheck>()(buttonCore, true);
            WindowControl windowControl = WindowControl.FromZTop(_app);
            WPFButtonBase ButtonBase    = new WPFButtonBase(buttonCore);

            // Act
            Async async = new Async();

            ButtonBase.EmulateClick(async);

            // Assert
            WindowControl    messageBoxControl = windowControl.WaitForNextModal();
            NativeMessageBox messageBox        = new NativeMessageBox(messageBoxControl);

            Assert.AreEqual("TestMessageWindow", messageBox.Message);
            Assert.IsTrue((bool)checker.ButtonClickCalled);

            // Teardown
            messageBox.EmulateButtonClick("OK");
            messageBoxControl.WaitForDestroy();
            async.WaitForCompletion();
        }
Exemplo n.º 2
0
        public string ButtonEntry_EmulateClickAndGetMessage()
        {
            Async async = new Async();

            ButtonEntry.EmulateClick(async);
            var msgBox = new NativeMessageBox(Window.WaitForNextModal());
            var msg    = msgBox.Message;

            msgBox.EmulateButtonClick("OK");
            async.WaitForCompletion();
            return(msg);
        }
Exemplo n.º 3
0
        public void MessageBoxTest()
        {
            var async = new Async();

            _messageBoxButton.EmulateClick(async);

            //メッセージボックスを取得
            var main        = new WindowControl(mainCore);
            var childWindow = main.WaitForNextModal();
            var msg         = new NativeMessageBox(childWindow);

            //メッセージを取得
            Assert.AreEqual("msg", msg.Message);

            //テキストからボタンを検索して押す
            msg.EmulateButtonClick("OK");

            //非同期処理の完了待ち
            async.WaitForCompletion();
        }
Exemplo n.º 4
0
        public async Task Save(string msg, string fileName)
        {
            await Task.Run(async() =>
            {
                try
                {
                    //フォーカスしないようにする
                    //ShowWindow(mainWindowHandle.ToInt32(), SW_HIDE);
                    await Task.Delay(100);

                    //再生完了待機
                    while (!saveButton.IsEnabled)
                    {
                        Console.WriteLine("saveBtn is not enabled");
                        await Task.Delay(100);
                    }

                    talkTextBox.EmulateChangeText(msg);

                    var async = new Async();
                    saveButton.EmulateClick(async);
                    //名前を付けて保存ダイアログ
                    var saveFileWindow = uiTreeTop.WaitForNextModal();
                    var saveFileDialog = new NativeMessageBox(saveFileWindow);

                    //ファイル名を入力
                    //右上の検索欄にも入力されてしまうが無視
                    var edits = saveFileDialog.Window.GetFromWindowClass("Edit");
                    foreach (var t in edits)
                    {
                        var edit = new NativeEdit(t);
                        edit.EmulateChangeText(fileName);
                    }

                    saveFileDialog.EmulateButtonClick("保存(&S)");
                    //saveFileWindow.WaitForDestroy();

                    //出力状況を表示するダイアログの表示を待つ
                    Console.WriteLine("waiting for showing progress window");
                    var progressWindow = uiTreeTop.WaitForNextModal();
                    if (progressWindow == null)
                    {
                        progressWindow = uiTreeTop.WaitForNextModal();
                    }
                    Console.WriteLine("showed " + progressWindow.GetWindowText());

                    var tokenSource = new CancellationTokenSource();
                    var task        = new TaskFactory().StartNew(() =>
                    {
                        //完了通知ダイアログの表示を待つ
                        Console.WriteLine("wationg for showing saving complete window");
                        var completeWindow = progressWindow.WaitForNextModal();
                        if (completeWindow != null)
                        {
                            Console.WriteLine("showed " + completeWindow.GetWindowText());
                            Console.WriteLine(DateTime.Now);
                            try
                            {
                                var completeDialog = new NativeMessageBox(completeWindow);
                                completeDialog.EmulateButtonClick("OK");
                                Console.WriteLine("wating for destroying");
                                completeWindow.WaitForDestroy();
                                Console.WriteLine("finish");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                        }
                    }, tokenSource.Token);
                    try
                    {
                        Console.WriteLine(DateTime.Now);
                        if (!task.Wait(5000))
                        {
                            tokenSource.Cancel();
                            Console.WriteLine("timeout");
                            Console.WriteLine(DateTime.Now);
                            var windows = WindowControl.GetTopLevelWindows(uiTreeTop.App);
                            foreach (var window in windows)
                            {
                                Console.WriteLine(window.GetWindowText());
                                var btnList = window.LogicalTree().ByType <Button>();
                                var count   = btnList.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    var btn        = new WPFButtonBase(btnList[i]);
                                    var btnTxtList = btn.LogicalTree(TreeRunDirection.Descendants).ByType <TextBlock>();
                                    if (btnTxtList.Count == 1)
                                    {
                                        var btnTxt = new WPFTextBlock(btnTxtList.Single());
                                        Console.WriteLine(btnTxt.Text);
                                        if (btnTxt.Text.Equals("キャンセル"))
                                        {
                                            btn.EmulateClick();
                                        }
                                    }
                                }
                            }

                            var completeWindow = progressWindow.WaitForNextModal();
                            Console.WriteLine("showed2 " + completeWindow.GetWindowText());
                            Console.WriteLine("2" + DateTime.Now);
                            var completeDialog = new NativeMessageBox(completeWindow);
                            completeDialog.EmulateButtonClick("OK");
                            Console.WriteLine("wating for destroying2");
                            completeWindow.WaitForDestroy();
                            Console.WriteLine("finish2");
                        }
                    }
                    catch (AggregateException)
                    {
                        //タスクがキャンセルされた
                        Console.WriteLine("task was canceled");
                        var completeWindow = WindowControl.FromZTop(uiTreeTop.App);
                        Console.WriteLine("showed3 " + completeWindow.GetWindowText());
                        var completeDialog = new NativeMessageBox(completeWindow);
                        completeDialog.EmulateButtonClick("OK");
                        Console.WriteLine("wating for destroying3");
                        completeWindow.WaitForDestroy();
                        Console.WriteLine("finish3");
                    }

                    if (!async.IsCompleted)
                    {
                        try
                        {
                            Console.WriteLine("wating for async finish");
                            async.WaitForCompletion();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }
                finally
                {
                    //ShowWindow(mainWindowHandle.ToInt32(), SW_MINIMIZE);
                    Console.WriteLine("complete saving");
                }
            });
        }
Exemplo n.º 5
0
 public void Button_OK_Click()
 => _core.EmulateButtonClick("OK");