<前提>
C#で生成しているフォームアプリの結合テストを、Codeer.Friendlyを用いた自動化テストによる実施を考えています。
Codder.Friendlyは、テスト対象のフォームアプリとは別のプロジェクトの単体テストプロジェクトで使用しています。
実際に各テストケースの動作自体はできました。
<問題>
この結合テストは、テストケース実施後、フォームアプリのキャプチャをエビデンスとして残したいです。
しかし、スクリーン全体であれば取得も可能なのですが、フォームアプリのみの画像に絞ろうとすると方法が分かりません。
フォームサイズなどは、WindowControlクラスから取得できるようなのですが、位置情報の取得に難航という状況です。
ProcessクラスやWindowsAppFriendクラスなどから取得できないかなども調査していますが、こちらも遅々として進まずといった具合です。
Codeer.Friendlyを用いたウィンドウキャプチャ取得方法はないでしょうか?
例)
C#
1// 実行ボタンクリックを経由して、テキストボックスの値をラベルに表示する動作のフォームアプリ対象 2namespace FriendlyTest 3{ 4 [TestClass] 5 public class FriendlyTest 6 { 7 Process process; 8 WindowsAppFrinend App; 9 WindowControl Form; 10 FormsButton ExeButton; 11 FormsTextBox MessageTextBox; 12 FormsLabel MessageLabel; 13 14 [TestInitialize] 15 public void TestInitialize() 16 { 17 process = Process.Start("Sample.exe"); 18 App = new WindowsAppFriend(process); 19 WindowControl = new WindowControl(App.Type<Application>().OpenForms[0]); 20 ExeButton = new FormsButton(Form.Dynamic().ExeButton); 21 MessageTextBox = new FormsTextBox(Form.Dynamic().MessageTextBox); 22 MessageLabel = new FormsLabel(Form.Dynamic().MessageLabel); 23 } 24 25 [TestCleanup] 26 public void TestCleanup() 27 { 28 Process.GetProcessById(App.ProcessId).CloseMainWindow(); 29 } 30 31 private void SaveCapture(string filePath) 32 { 33 Bitmap bmp = new Bitmap(Form.Size.Width, Form.Size.Height, PixelFormat.Format32bppArgb); 34 using (Graphics g = Graphics.FromImage(bmp)) 35 { 36 g.CopyFromScreen(X位置, Y位置, 0, 0, Form.Size, CopyPixelOperation.SourceCopy); 37 // ↑この処理の第1引数、第2引数の値に難航しています。 38 } 39 bmp.Save(filePath, ImageFormat.Png); 40 } 41 42 [TestMethod] 43 public void テストケース001() 44 { 45 string inputMessage = "メッセージ"; 46 47 MessageTextBox.EmulateChangeText(inputMessage); 48 ExeButton.EmulateClick(); 49 50 Assert.AreEqual(inputMessage, MessageLabel.Text); 51 52 SaveCapture(MethodBase.GetCurrentMethod().Name + ".Png"); 53 } 54 } 55} 56
<補足>
開発言語:C#
開発環境:VisualStudio2015 Professional
.NET:バージョン4.6
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/29 02:31
2019/03/29 13:34