LoginSignup
8
16

More than 5 years have passed since last update.

Windows Application Driver を利用した Windows アプリケーションの自動テスト作成方法

Last updated at Posted at 2017-05-05

はじめに

Windows Application Driver を利用した xunit のテストプロジェクトの作成方法を示します。

Windows Application Driver が何であるかとかは示していません。

この記事を読んでできるようになること

movie1.gif

事前準備

手順

  • Visual Studio 2017 のプロジェクトを新規作成する C# のクラスライブラリ(以降、デフォルトのClass1.csを想定)として作成する
  • Nuget Package で、xunit をインストールする(v.2.2.0)
  • Nuget Package で、xunit.runner.visualstudioをインストールする(v.2.2.0)
  • Nuget Package で、Appium.WebDriver(v.3.0.0.2)をインストールする
  • Class1.cs に以下のコードを張り付ける(namespaceは適宜変更のこと)
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;
using System;
using Xunit;

namespace WindowsApplicationDriverUnitTest
{

    public class TestClass
    {
        [Fact]
        public void WindowsApplicationTest()
        {
            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("app", @"C:\Windows\System32\notepad.exe");
            var NotepadSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);

            NotepadSession.FindElementByClassName("Edit").SendKeys("This is some text");

            var NotepadResult = NotepadSession.FindElementByClassName("Edit");

            Xunit.Assert.Equal(NotepadResult.Text, "This is some text");
        }
    }
}
  • WinAppDriverを実行する C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe
  • テストエクスプローラーで、テストを実行する。Notepadが起動して、自動的に"This is some text"が入力されることが確認される

補足

Step 5 のコード中に、以下の記述がある。

FindElementByClassName("Edit")

これによって、自動操作するコントロールを取得している。

"Edit"というキーワードは、inpsect.exe を実行することで取得できる。

詳細は、GitHubの公式サイトに記述されている。

参考にさせていただいたサイト

8
16
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
16