10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gaugeをインストールして公式のサンプルを動かすまで

Last updated at Posted at 2019-11-14

基本的に公式Documentが充実しているので、読んでいけばスムーズに使い始められます。

ただ、一部

  • 公式通りにやってもうまくいかない
  • 手順が抜けている
  • 全体が英語

などあるので、改めて説明する意味も無くはないかな、と思って書きました。

そもそもGaugeとは

Markdownで仕様を書いて自動テストができるツールです。
といってもMarkdownさえ書けばいいわけではなく、コーディングも必要です。

たとえば「ネットで何か検索をする」という処理(Gaugeの単位で言うとシナリオ)を実現するために、

  • Googleのホームに遷移する
  • 「ほげ」と検索する

という操作(Gaugeの単位で言うとステップ)が必要になります。

それぞれのステップを以下のようにコーディングをしておきます。

step("Goto Google's home page", () => {
  goto("google.com")
});

step("Search for <query>", (query) => {
  write(query);
  press("Enter");
});

実際のテストシナリオを書く時にはこれらを呼び出して、以下のように書きます。

# Search the internet

## Look for cakes
* Goto Google's home page
* Search for "Cup Cakes"

## Look for movies
* Goto Google's home page
* Search for "Star wars"

Seleniumそのままでテスト手順をコーディングしていったものに比べて、自然言語に近い分テストの内容がぱっと見でわかりやすく、テスター向きだとされています。

このように書くと「BDDか」と思うかもしれませんが、Gaugeの公式では「我々が提供しているのはBDDツールではない」と言っています。

Minding the Gap between BDD and Executable Specifications | Gauge Blog

Although there are instances where our users use Gauge as a BDD Tool, our focus hasn't been BDD but on building features that give teams the confidence to release.

チームにリリースする勇気を与えるための機能に注力したい、と書かれています。

1. インストール

公式のインストール手順に従います。

Gauge Documentation — Gauge 0.9.9 documentation

OSと言語とIDEを選ぶとそれにあったインストール手順が出てきます。初見のとき感動しましたこれ。

Gauge_1.PNG

今回はWindows/Python/Visual Studio Codeを選択しました。

1-1. Gaugeのインストール

インストーラのリンクがあるので、クリックしてダウンロードし、インストーラを実行。

インストールの過程で、コンポーネントの選択を求められます。

Additional plugins can be install using the command 'gauge install <plugin>'

とあるように、あとから追加もできるので、今時点で必要なPythonのみにチェックを入れます。

Gauge_2.PNG

1-2. VSCodeの拡張機能をインストール

VSCode上で"Gauge"で拡張機能を検索したらすぐに出てきました。

Install。

Gauge_3.PNG

2. プロジェクトを作る

成功した手順

Gaufeのプロジェクト用にフォルダを作成し、その中で以下コマンドを実行。

> gauge init python

一瞬で成功しました。

C:\>gauge init python

Telemetry
---------

This installation of Gauge collects usage data in order to help us improve your experience.
The data is anonymous and doesn't include command-line arguments.
To turn this message off opt in or out by running 'gauge telemetry on' or 'gauge telemetry off'.

Read more about Gauge telemetry at https://gauge.org/telemetry


Downloading python.zip
.
Copying Gauge template python to current directory ...
Successfully initialized the project. Run specifications with "gauge run specs/".

Compatible language plugin python is not installed. Installing plugin...
.
Successfully installed plugin 'python' version 0.3.6

※Gaugeのインストール手順の途中でPythonにチェックを入れたはずなのですが・・・

必要なモジュールをインストールするため、プロジェクト内のrequirements.txtを使って、

> pip install -r requirements.txt

を実行しましょう。

失敗した手順

一応残しておきます。

Gauge Documentation — Gauge 0.9.9 documentationに沿って行います。

VSCode上でCtrl+Shift+pを押してコマンドパレットを出し、

Gauge: Create a new Gauge Project

を選択
→Pythonを選択
→フォルダのルートを選ぶように出てくるので、選択
→プロジェクト名を設定

このあと、Initializing project... と表示された状態で待ち続け、なぜか処理が終わらず・・・。

3. サンプルの実行

作成したプロジェクトの中にサンプルファイルが入っているので、実行してみます。

コマンドは

> gauge run specs

です。

成功すると以下のようなログが表示されます。

C:>gauge run specs
Python: 3.7.2
# Specification Heading
  ## Vowel counts in single word         P P
  ## Vowel counts in multiple word       P P

Successfully generated html-report to => C:\hoge\reports\html-report\index.html
Specifications: 1 executed      1 passed        0 failed        0 skipped
Scenarios:      2 executed      2 passed        0 failed        0 skipped

Total time taken: 381ms

そして、プロジェクト内にreportsというフォルダが作成され、その中にHTMLのレポートが出力されます。

gauge-report-sample.png

エラーが発生した場合

以下のようなエラーがでた場合、おそらくはgetgaugeというモジュールを取得できていません。前項の、requirements.txtを使ったインストールを行ってください。

(ここまで略)
subprocess.CalledProcessError: Command '['C:\\hoge\\Python\\Python37\\python.exe -m pip install getgauge==0.3.6 --user']' returned non-zero exit status 1.
Traceback (most recent call last):
File "start.py", line 8, in <module>
import grpc
ModuleNotFoundError: No module named 'grpc'
Error ----------------------------------

[Gauge]
Failed to start gauge API: Runner with pid 27004 quit unexpectedly(exit status 1).

Get Support ----------------------------
        Docs:          https://docs.gauge.org
        Bugs:          https://github.com/getgauge/gauge/issues
        Chat:          https://gitter.im/getgauge/chat

Your Environment Information -----------
        windows, 1.0.6, 2bc49db
        html-report (4.0.8), python (0.3.6), screenshot (0.0.1)
10
7
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
10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?