0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Robot Framework] Windows Applicationのテスト自動化を構築からスクリプティングまでやってみる

Last updated at Posted at 2024-12-23

はじめに

Windows Applicationをテスト自動化を行いたい。
幸いに、キーワード駆動の Robot Framework にいくつか Windows Applicationのテストを行うライブラリがある。その中でここでは FlaUILibrary を用いる。
※Appiumをつかって自動化することもできる。ただドライバ回り構築必要で少し大変です。

今回、windows 環境に robot frameworkの環境構築から、Windows Applicationの簡単な処理の作成、実行までを初心者でもできるようにドキュメント化した

セットアップ

Python

Pythonサイトから、Stable Releasesのバージョンをダウンロードする

image.png

「Add python.exe to PATH」のチェックを入れて、どこからでも実行できるようにする。
その後、「Install Now」をクリックし、インストールを完了させる。

任意の場所でコマンドプロンプトを開き、以下コマンドを実施し、動作確認をする

python --version

image.png

robot framework

robotframeworkでWEBアプリケーションのテストを行うライブラリをインストールする

pip install robotframework

次に、robotコマンドを実行する

robot

image.png

※なお、環境やログインユーザーによって、上記 robotのPATHが正しく通ってなく、動かない可能性がある。
その場合、 pipでインストールしたライブラリが、個人のpython folderにインストールされているからです。
その場合、そのfolderもPATHに追加する必要がある

その時、環境変数のpathに追加するfolderは以下のとおりである。

%UserProfile%\AppData\Roaming\Python\Python312\Scripts

まず、exploreで対象folderが存在することを確認する。
その後、exploreで開いたパスを環境変数のpathに追加設定する
追加後に、改めてコマンドプロンプトを開き、実行できるかを確認する

image.png

robotframework flaui library

次に、WEBのテストを行うライブラリ flaui libraryをインストールする

pip install --upgrade robotframework-flaui

Inspect

Windows SDK に、Chrome Developer toolと同じように、要素のlocatorを取得するツール、Inspectが含まれています。

最低限のSDKを選ぶとき、以下の2つパッケージを選ぶ

image.png

インストールが終わると、インストールしたフォルダ以下にinspect.exeが存在する。
こちらをクリックする

image.png

以下のようなアプリが立ち上がり、windowsアプリのlocator情報をとることができる。

image.png

XPath取得

例えば、電卓の"C"ボタンのXpathを取得する
"C"をクリックすると、Inspectで属性情報が出てくる
ClassName = "Button"
AutomationId = "clearButton"

この場合、XPathは //Button[@AutomationId = 'clearButton'] となる

image.png

テスト対象

windows標準でついてる電卓
単純に電卓をたたいて演算する処理を自動化する

image.png

テストコード実装

スクリプトを記述するに用いるキーワードはこちらになります。

*** Settings ***
Library  FlaUILibrary
Library  BuiltIn

*** Variables ***
${APP}  C:\\Windows\\System32\\calc.exe
${pid}  0

*** Keywords ***
Open APP
	${_pid} =  Launch Application  ${APP}
	Sleep  1
	Set Global Variable  ${pid}  ${_pid}

Close APP
	Log to Console  close ${pid}
	Close Application  ${pid}


*** Test Cases ***
Setup
	Open APP

Calculation
	Click  /Window[@Name='電卓']//Button[@AutomationId='clearButton']
	Click  /Window[@Name='電卓']//Button[@AutomationId='num3Button']
	Click  /Window[@Name='電卓']//Button[@AutomationId='plusButton']
	Click  /Window[@Name='電卓']//Button[@AutomationId='num9Button']
	Click  /Window[@Name='電卓']//Button[@AutomationId='equalButton']
	Take Screenshot

Teardown
	Close APP

実行

robot  xxx.robot    <- 実行するrobotのファイル名

image.png

実行結果

電卓の結果12になることのエビデンスを残して、レポートが作成されます

image.png

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?