public void TestChangeContextByWindowObject() { //フォームの取得 WindowControl targetForm = WindowControl.FromZTop(app); //別スレッドウィンドウを表示 WindowControl _buttonOtherThread = targetForm.IdentifyFromZIndex(0); _buttonOtherThread["PerformClick"](); //表示待ち AppVar next = null; while (next == null) { Thread.Sleep(10); AppVar all = app["System.Windows.Forms.Application.OpenForms"](); foreach (AppVar element in new Enumerate(all)) { if (!(bool)targetForm.AppVar["Equals"](element).Core) { next = element; break; } } } //実行コンテキストを変更 using (ExecuteContext context = new ExecuteContext(app, next)) { ExecuteContext oldContext = app.ChangeContext(context); AppVar _textBoxSrc = next["_textBoxSrc"](); _textBoxSrc["Text"]("xxx"); AppVar _buttonCopyText = next["_buttonCopyText"](); _buttonCopyText["PerformClick"](); AppVar _textBoxDst = next["_textBoxDst"](); //操作の結果_textBoxDstにxxxが入力される Assert.AreEqual(_textBoxDst["Text"]().ToString(), "xxx"); try { next["Close"](); } catch (FriendlyOperationException) { }//スレッドが終了してしまうので、通信途中で通信不能となる これは仕様 //コンテキストをもとに戻す app.ChangeContext(oldContext); } //ウィンドウを操作しても例外が発生しない targetForm["Handle"](); targetForm["Text"]("xxx"); }