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); } } }
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(); }
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(); }
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]); }
/// <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; } }
public void RegisterFemaleSns() { Thread.Sleep(1000); dynamic window = _app.Type <Application>().Current.MainWindow; var nameTextBox = new WPFTextBox(window.Name); nameTextBox.EmulateChangeText("Peach"); Thread.Sleep(1000); var sexRadio = new WPFButtonBase(window.Female); sexRadio.EmulateClick(); Thread.Sleep(1000); var reasonComboBox = new WPFComboBox(window.Reason); reasonComboBox.EmulateChangeSelectedIndex(2); Thread.Sleep(1000); var registerBtn = new WPFButtonBase(window.RegisterBtn); registerBtn.EmulateClick(); var outputTxtBlock = new WPFTextBlock(window.Output); Assert.AreEqual(outputTxtBlock.Text.Replace("\n", ""), $"登録者名: Peach\n性別: 女性\n登録する経緯: SNSで見た".Replace("\n", "")); Thread.Sleep(1000); }
/// <summary> /// VOICEROID2 の再生を停止します(停止ボタンを押す) /// </summary> public void Stop() { StopSpeech(); WPFButtonBase stopButton = new WPFButtonBase(_root.IdentifyFromLogicalTreeIndex(0, 4, 3, 5, 3, 0, 3, 1)); stopButton.EmulateClick(); }
public MainViewDirver(dynamic mainView) { var w = new WindowControl(mainView); //指定のオブジェクトを起点とした //ロジカルツリー中にあるLhsというパスにバインドされている要素のコレクション //Identifyは一つだけであることを保障する //コレクションの要素が1以外だった場合は例外発生 w.LogicalTree().ByBinding("Lhs").Identify(); //ビジュアルツリーでは、こんな感じで書く w.VisualTree().ByBinding("Lhs").Identify(); //データアイテムを指定して、さらに厳密な指定にできる var dataItem = new ExplicitVar(w.Dynamic().DataContext); w.LogicalTree().ByBinding("Lhs", dataItem).Identify(); Lhs = new WPFTextBox(w.LogicalTree().ByBinding("Lhs").Identify()); CalculateTypes = new WPFComboBox(w.LogicalTree().ByBinding("CalculateTypes").Identify()); Rhs = new WPFTextBox(w.LogicalTree().ByBinding("Rhs").Identify()); CalculateCommand = new WPFButtonBase(w.LogicalTree().ByBinding("CalculateCommand").Identify()); Answer = w.LogicalTree().ByBinding("Answer").Identify().Dynamic(); }
public void GetCoreElementTest() { WPFMenuBase menu = new WPFMenuBase(_ctrl._menu); var item = menu.GetItem(2); var button = new WPFButtonBase(item.GetCoreElement(typeof(Button).FullName)); button.EmulateClick(); Assert.IsTrue((bool)_ctrl.menuButtonClicked); }
public void HeaderContentTest() { WPFTreeView tree = new WPFTreeView(_ctrl._tree); var item = tree.GetItem(1); var button = new WPFButtonBase(item.HeaderContent.VisualTree().ByType <Button>().Single()); button.EmulateClick(); Assert.IsTrue((bool)_ctrl.treeButtonClicked); }
public void GetCoreElementTest() { WPFTreeView tree = new WPFTreeView(_ctrl._tree); var item = tree.GetItem(1); var button = new WPFButtonBase(item.GetCoreElement(typeof(Button).FullName)); button.EmulateClick(); Assert.IsTrue((bool)_ctrl.treeButtonClicked); }
/// <summary> /// VOICEROID2 に入力された文字列を再生します /// </summary> public void Play() { WPFButtonBase playButton = new WPFButtonBase(_root.IdentifyFromLogicalTreeIndex(0, 4, 3, 5, 3, 0, 3, 0)); playButton.EmulateClick(); Application.DoEvents(); _isPlaying = true; _isRunning = false; _timer.Start(); }
public void TestInitialize() { _app = new WindowsAppFriend(Process.Start("C:\\Users\\t-yamazaki\\Desktop\\Sample\\Sample\\bin\\Debug\\Sample.exe")); mainCore = _app.Type <Application>().Current.MainWindow; _messageBoxButton = new WPFButtonBase(mainCore.MessageBoxButton); _startButton = new WPFButtonBase(mainCore.StartButton); _stopButton = new WPFButtonBase(mainCore.StopButton); _resetButton = new WPFButtonBase(mainCore.ResetButton); _lapButton = new WPFButtonBase(mainCore.LapButton); }
public void ButtonClickTest() { // Arrenge dynamic main = _app.Type<Application>().Current.MainWindow; AppVar buttonCore = _app.Type<Button>()(); main._grid.Children.Add(buttonCore); dynamic checker = _app.Type<ButtonEventCheck>()(buttonCore, false); WPFButtonBase ButtonBase = new WPFButtonBase(buttonCore); // Act ButtonBase.EmulateClick(); Assert.IsTrue((bool)checker.ButtonClickCalled); }
public void ButtonClickTest() { // Arrenge dynamic main = _app.Type <Application>().Current.MainWindow; AppVar buttonCore = _app.Type <Button>()(); main._grid.Children.Add(buttonCore); dynamic checker = _app.Type <ButtonEventCheck>()(buttonCore, false); WPFButtonBase ButtonBase = new WPFButtonBase(buttonCore); // Act ButtonBase.EmulateClick(); Assert.IsTrue((bool)checker.ButtonClickCalled); }
public VoiceroidEngine() { Program.Logger.Info("VOICEROID init started..."); process = GetOrCreateVoiceroidProcess(); app = new WindowsAppFriend(process); try { // Timeout = 60 sec for (var i = 0; i < 1200; i++) { var window = app.FromZTop(); WinApi.ShowWindow(window.Handle, WinApi.SwMinimize); var tree = window.GetFromTypeFullName("AI.Talk.Editor.TextEditView") .FirstOrDefault() ?.LogicalTree(); if (tree == null) { Thread.Sleep(50); continue; } var text = tree.ByType <TextBox>().Single(); var play = tree.ByBinding("PlayCommand").Single(); var stop = tree.ByBinding("StopCommand").Single(); // var move = tree.ByBinding("MoveToBeginningCommand").Single(); talkTextBox = new WPFTextBox(text); playButton = new WPFButtonBase(play); stopButton = new WPFButtonBase(stop); moveButton = new WPFButtonBase(tree[15]); // moveButton = new WPFButtonBase(move); Program.Logger.Info("VOICEROID ready!"); Task.Run(ConsumeAsync); return; } } catch (Exception exception) { Program.Logger.Error(exception); throw new ApplicationException("VOICEROID init failed."); } throw new TimeoutException("VOICEROID init timed out."); }
public void Clear() { dynamic window = _app.Type <Application>().Current.MainWindow; var nameTextBox = new WPFTextBox(window.Name); nameTextBox.EmulateChangeText(string.Empty); var sexRadio = new WPFButtonBase(window.Male); sexRadio.EmulateClick(); var reasonComboBox = new WPFComboBox(window.Reason); reasonComboBox.EmulateChangeSelectedIndex(-1); }
public void Wpf() { var app = new WindowsAppFriend(Process.Start("Wpf.exe")); AppVar window = app.Type().System.Windows.Application.Current.MainWindow; var logicalTree = window.LogicalTree(); var buttonModal = new WPFButtonBase(logicalTree.ByBinding("CommandModal").Single()); var buttonModeless = new WPFButtonBase(logicalTree.ByBinding("CommandModeless").Single()); //モーダレスは通常はそのままでOK buttonModeless.EmulateClick(); var next = app.Type().System.Windows.Application.Current.Windows[1]; next.Title = "aaa"; //でもたまに変なことしているやつがいれば注意 //まあ、こっち使った方が無難 var nextW = WindowControl.WaitForIdentifyFromWindowText(app, "aaa"); nextW.Dynamic().Close(); //モーダルは要注意 var current = new WindowControl(window); { var a = new Async(); buttonModal.EmulateClick(a); var modal = current.WaitForNextModal(); modal.Dynamic().Close(); a.WaitForCompletion(); } //連続で出るやつはもっと注意 var buttonModalSequential = new WPFButtonBase(logicalTree.ByBinding("CommandModalSequential").Single()); { var a = new Async(); buttonModalSequential.EmulateClick(a); var modal1 = current.WaitForNextModal(); modal1.Dynamic().Close(); modal1.WaitForDestroy(); var modal2 = current.WaitForNextModal(); modal2.Dynamic().Close(); modal2.WaitForDestroy(); a.WaitForCompletion(); } Process.GetProcessById(app.ProcessId).Kill(); }
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()); }
private void timer_Elapsed(object sender, EventArgs e) { _timer.Stop(); // 途中の処理が重いため、タイマーをいったん止める lock (_lockObject) { _tickCount += _timer.Interval; // ここからプロセス間通信&UI操作(重い) //WPFButtonBase playButton = new WPFButtonBase(_root.IdentifyFromLogicalTreeIndex(0, 4, 3, 6, 3, 0, 3, 0)); WPFButtonBase playButton = new WPFButtonBase(_root.IdentifyFromLogicalTreeIndex(0, 4, 3, 6, 3, 0, 0, 0, 1, 3, 0)); var d = playButton.LogicalTree(); System.Windows.Visibility v = (System.Windows.Visibility)(d[2])["Visibility"]().Core; // [再生]の画像の表示状態 // ここまで if (v != System.Windows.Visibility.Visible && !_isRunning) { _isRunning = true; } else // 再生開始から 500 ミリ秒程度経過しても再生ボタンがうまく確認できなかった場合にも完了とみなす if (v == System.Windows.Visibility.Visible && (_isRunning || (!_isRunning && _tickCount > 500))) { if (_queue.Count == 0) { StopSpeech(); return; // タイマーが止まったまま終了 } else { // 喋るべき内容が残っているときは再開 string t = _queue.Dequeue(); // WPFTextBox textbox = new WPFTextBox(_root.IdentifyFromLogicalTreeIndex(0, 4, 3, 6, 3, 0, 2)); WPFTextBox textbox = new WPFTextBox(_root.IdentifyFromLogicalTreeIndex(0, 4, 3, 6, 3, 0, 0, 0, 1, 2)); textbox.EmulateChangeText(t); playButton.EmulateClick(); _isPlaying = true; _isRunning = false; _tickCount = 0; } } _timer.Start(); } }
public void TestInitialize() { //start process. var process = Process.Start(ProcessPath); //attach by friendly. _app = new WindowsAppFriend(process); //show next dialog. var mainWindow = _app.WaitForIdentifyFromTypeFullName("SampleApp.MainWindow"); var button = new WPFButtonBase(mainWindow.Dynamic()._buttonNextDialog); button.EmulateClick(new Async()); //get next dialog. var nextDialog = _app.WaitForIdentifyFromTypeFullName("SampleApp.NextDialog"); //create driver. _driver = new CefSharpDriver(nextDialog.Dynamic()._browser); }
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); }
/// <summary> /// 指定パスにあるフレーズ辞書を現在使用されているフレーズ辞書に統合します。 /// 統合は後勝ちで実行されます。 /// </summary> /// <param name="srcPdicPath"></param> public void MergePdicToCurrent(string srcPdicPath) { Async async = new Async(); Async async1 = new Async(); WPFMenuItem mi = new WPFMenuItem(rootControl.LogicalTree().ByType <MenuItem>().ByBinding("OptionsCommand").Single()); mi.EmulateClick(async); WindowControl settingsWindow = rootControl.WaitForNextModal(); WPFButtonBase mergePhraseDicButton = new WPFButtonBase(settingsWindow.LogicalTree().ByType <Button>().ByBinding("MergePhraseDicCommand").Single()); mergePhraseDicButton.EmulateClick(async1); WindowControl selectDialog = rootControl.WaitForNextModal(); MergeFile(selectDialog, srcPdicPath); WindowControl resultDialog = settingsWindow.WaitForNextModal().WaitForNextModal(); new NativeButton(resultDialog.IdentifyFromWindowText("OK")).EmulateClick(); new WPFButtonBase(settingsWindow.LogicalTree().ByType <Button>().ByBinding("OkCommand").Single()).EmulateClick(); async1.WaitForCompletion(); async.WaitForCompletion(); }
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(); }
/// <summary> /// VOICEROID2 に入力された文字列を保存します /// </summary> private void Save(string outputFilePath) { // 「音声保存」ボタン押下 WPFButtonBase saveButton = new WPFButtonBase(_root.IdentifyFromLogicalTreeIndex(0, 4, 3, 5, 3, 0, 3, 5)); saveButton.EmulateClick(new Async()); Application.DoEvents(); // 音声保存設定ダイアログの OK ボタン押下 var saveWindow = WindowControl.GetFromWindowText(_app, "音声保存")[0]; WPFButtonBase saveOkButton = new WPFButtonBase(saveWindow.IdentifyFromLogicalTreeIndex(0, 1, 0)); saveOkButton.EmulateClick(new Async()); Application.DoEvents(); // 「名前を付けて保存」ダイアログで出力ファイル名を入力して OK ボタン押下 WindowControl saveDialog = WindowControl.WaitForIdentifyFromWindowText(_app, "名前を付けて保存"); NativeButton saveDialogButton = new NativeButton(saveDialog.IdentifyFromDialogId(1)); NativeEdit saveFileNameTextBox = new NativeEdit(saveDialog.IdentifyFromZIndex(11, 0, 4, 0, 0)); saveFileNameTextBox.EmulateChangeText(outputFilePath); Application.DoEvents(); saveDialogButton.EmulateClick(new Async()); Application.DoEvents(); // 上書き確認ダイアログが出てきたら、 OK ボタンを押下 // 出てくる前提で作っているけど、なぜか出ない場合でも問題なく動いているっぽい。 while (true) { try { WindowControl saveConfirmDialog = WindowControl.IdentifyFromWindowText(_app, "名前を付けて保存"); NativeButton saveConfirmDialogButton = new NativeButton(saveConfirmDialog.IdentifyFromDialogId(6)); saveConfirmDialogButton.EmulateClick(new Async()); Application.DoEvents(); } catch (WindowIdentifyException e) { // do nothing } // 保存成功通知ダイアログの OK ボタンを押下 try { WindowControl infoDialog = WindowControl.IdentifyFromWindowText(_app, "情報"); NativeButton infoDialogButton = new NativeButton(infoDialog.IdentifyFromDialogId(2)); infoDialogButton.EmulateClick(new Async()); Application.DoEvents(); break; } catch (WindowIdentifyException e) { // do nothing } Thread.Sleep(100); } // おまじない // 再生の時もこれやっているので、何か意味があるのだろう。 _isPlaying = false; _isRunning = false; _timer.Start(); }
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"); } }); }
public void HeaderContentTest() { WPFTreeView tree = new WPFTreeView(_ctrl._tree); var item = tree.GetItem(1); var button = new WPFButtonBase(item.HeaderContent.VisualTree().ByType<Button>().Single()); button.EmulateClick(); Assert.IsTrue((bool)_ctrl.treeButtonClicked); }
static void Main(string[] args) { // プロセスの取得 Process[] ps = Process.GetProcessesByName("VoiceroidEditor"); if (ps.Length == 0) { Console.Error.WriteLine("VOICEROID2を起動してください"); return; } // WindowsAppFriendをプロセスから作成する // 接続できない旨のエラーの場合、別のプロセスでテスト対象のプロセスを操作している場合がある。 // TestAssistant使いながら動作できないようなので、注意。 var app = new WindowsAppFriend(ps[0]); var mainWindow = WindowControl.FromZTop(app); // 茜ちゃんしゃべる WPFTextBox txtMessage = new WPFTextBox(mainWindow.IdentifyFromLogicalTreeIndex(0, 4, 3, 5, 3, 0, 2)); txtMessage.EmulateChangeText("アカネチャンカワイイヤッタ"); WPFButtonBase btnPlay = new WPFButtonBase(mainWindow.IdentifyFromLogicalTreeIndex(0, 4, 3, 5, 3, 0, 3, 0)); btnPlay.EmulateClick(); // ステータスバーを監視してしゃべり終わるまでまつ String sts; do { System.Threading.Thread.Sleep(500); var txtStatusItem = mainWindow.IdentifyFromVisualTreeIndex(0, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0).Dynamic();; sts = txtStatusItem.Text.ToString(); } while (!sts.Equals("テキストの読み上げは完了しました。")); // 保存ボタン押下 // ダイアログが表示されると引数なしのEmulateClickだと止まるのでAsyncオブジェクトを渡しておく var async = new Async(); WPFButtonBase btnSave = new WPFButtonBase(mainWindow.IdentifyFromLogicalTreeIndex(0, 4, 3, 5, 3, 0, 3, 5)); btnSave.EmulateClick(async); // 音声保存ダイアログ操作 var dlgSaveWav = mainWindow.WaitForNextModal(); var asyncSaveWin = new Async(); WPFButtonBase buttonOK = new WPFButtonBase(dlgSaveWav.IdentifyFromLogicalTreeIndex(0, 1, 0)); buttonOK.EmulateClick(asyncSaveWin); // ファイル名指定後の保存 var asyncSaveFile = new Async(); var dlgFileSave = dlgSaveWav.WaitForNextModal(); NativeEdit editFileName = new NativeEdit(dlgFileSave.IdentifyFromZIndex(11, 0, 4, 0, 0)); editFileName.EmulateChangeText(System.DateTime.Now.ToString("yyyymMMddhhmmss") + ".wav"); NativeButton btnSaveOk = new NativeButton(dlgFileSave.IdentifyFromDialogId(1)); btnSaveOk.EmulateClick(asyncSaveFile); // 情報ダイアログが表示されるまで待機してOKを押下 var dlgInfo = WindowControl.WaitForIdentifyFromWindowText(app, "情報"); NativeButton btn = new NativeButton(dlgInfo.IdentifyFromWindowText("OK")); btn.EmulateClick(); //非同期で実行した保存ボタン押下の処理が完全に終了するのを待つ asyncSaveFile.WaitForCompletion(); asyncSaveWin.WaitForCompletion(); async.WaitForCompletion(); // 葵ちゃんに切り替えてしゃべる // UIAutomationだと葵ちゃん切り替えが行えない。 WPFListView ListView = new WPFListView(mainWindow.IdentifyFromLogicalTreeIndex(0, 4, 3, 3, 0, 1, 0, 2)); ListView.EmulateChangeSelectedIndex(1); txtMessage.EmulateChangeText("オネエチャンカワイイヤッタ"); btnPlay.EmulateClick(); ListView.EmulateChangeSelectedIndex(0); }