LoginSignup
15
13

More than 5 years have passed since last update.

Selenium IDE で作成した HTML 形式のテストケースを Windows のコマンドラインから実行する

Posted at

Selenium IDE で作成したテストケースを保存すると HTML 形式で保存されます。これを Windows のコマンドラインから実行する方法を調べました。

Selenium Server をダウンロードする

まずは下記から selenium-server-standalone-x.x.x.jar の最新版をダウンロードします。今日の時点では最新は selenium-server-standalone-2.39.0.jar でした。ダウンロードしたら今回は仮にデスクトップに置いておきます。

テストスイートを保存する

下記は Selenium IDE で作成した http://qiita.com のタイトルを検査する簡単なテストケースを含むテストスイートです。テストケースを assertTitle.html 、テストスイートを SampleTestSuite.html としてデスクトップに保存しておいたとします。

SampleTestSuite.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
  <title>Test Suite</title>
</head>
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td><a href="assertTitle.html">assertTitle</a></td></tr>
</tbody></table>
</body>
</html>
assertTitle.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://www.google.co.jp/" />
<title>assertTitle</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">assertTitle</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>/</td>
    <td></td>
</tr>
<tr>
    <td>assertTitle</td>
    <td>Qiita - プログラマの技術情報共有サービス</td>
    <td></td>
</tr>
</tbody></table>
</body>
</html>

コマンドを実行する

コマンドプロンプトのカレントディレクトリをデスクトップにしてから下記のコマンドを実行します。

java -jar selenium-server-standalone-2.39.0.jar -htmlSuite "*firefox" "http://qiita.com" "SampleTestSuite.html" "results.html"

すると Firefox が勝手に立ち上がり、テストを実行してくれます。そしてその結果は最後の引数で指定している results.html に HTML 形式で保存されます。ただ、results.html を開くとテストは成功しているものの日本語が文字化けしていました。何らかの対応が必要になりそうです。

Test suite results.png

15
13
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
15
13