{
    "componentChunkName": "component---src-templates-blog-post-jsx",
    "path": "/post/how-to-run-testcase-of-selenium-ide-in-cli/",
    "result": {"data":{"site":{"siteMetadata":{"title":"WEB EGG","author":"Leko - CTO at Yuimedi"}},"markdownRemark":{"id":"36f10bb5-3d2f-585a-83f7-7f8e83b98cb9","excerpt":"この記事は12/21 クローラー／Web スクレイピングの記事です。 最近、自社システムのシナリオテストの実施方法周りの調査をやっているのですが、 GUI からテストコードの原型を作成できる テストコードを編集しても GUI で編集できる可逆性が有る CI…","html":"<p>この記事は<a href=\"http://qiita.com/advent-calendar/2016/crawler\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">12/21 クローラー／Web スクレイピング</a>の記事です。</p>\n<p>最近、自社システムのシナリオテストの実施方法周りの調査をやっているのですが、</p>\n<ul>\n<li>GUI からテストコードの原型を作成できる</li>\n<li>テストコードを編集しても GUI で編集できる可逆性が有る</li>\n<li>CI のためにヘッドレスで実行できる</li>\n<li>環境構築が簡単</li>\n</ul>\n<p>な手法を調べており、<a href=\"https://github.com/vmi/selenese-runner-java\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">selenese-runner</a>というツールと Selenium が提供している Selenium Hub というツールを利用したらいいんじゃないか、という結論になりました。<br>\nこの方法なら専門的な技能がなるべく少なくて済むんじゃないか。</p>\n<p>と思っている方法を紹介します。</p>\n<!--more-->\n<h2 id=\"selenium-ide\" style=\"position:relative;\"><a href=\"#selenium-ide\" aria-label=\"selenium ide permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Selenium IDE</h2>\n<p><a href=\"https://addons.mozilla.org/ja/firefox/addon/selenium-ide/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Firefox のアドオン</a>として配布されています。<br>\nブラウザでの操作をマクロとして記録する機能があります。<br>\nまた、IDE 上で記録したマクロを編集したりアサーションを追記したりできます。<br>\n補完とドキュメントが付いているので、Selenium の機能を熟知していなくても、補完で命名を補いってドキュメントで知識を補いながら書けます。<br>\nIDE からステップ実行もできるので、１手順ずつ動作確認していくことも可能です。</p>\n<p>Selenium IDE の詳しい使い方については色んな方が記事書いてくださっていますので割愛します。</p>\n<blockquote>\n<p>— <a href=\"http://qiita.com/naoqoo2/items/90d382cd9370d3526509\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">5 分でわかる Selenium IDE の使い方 – Qiita</a><br>\n— <a href=\"http://qiita.com/oh_rusty_nail/items/c59d4345d5372213128f\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">これだけはおさえておきたい！Selenium IDE のコマンド – Qiita</a><br>\n— <a href=\"http://www.qript.co.jp/blog/technique/1691/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Selenium IDE で Web ページのテストを自動化しよう！｜社員ブログ｜株式会社 Qript</a></p>\n</blockquote>\n<h2 id=\"ide-上でアサーションを書き加える\" style=\"position:relative;\"><a href=\"#ide-%E4%B8%8A%E3%81%A7%E3%82%A2%E3%82%B5%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92%E6%9B%B8%E3%81%8D%E5%8A%A0%E3%81%88%E3%82%8B\" aria-label=\"ide 上でアサーションを書き加える permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>IDE 上でアサーションを書き加える</h2>\n<p>アサーションを書くのはややプログラマ的な視点が必要になるかもしれませんが、<br>\nCSS セレクタと HTML タグが分かればある程度のテストなら書けるので、<br>\nフロントのマークアッパーとかも十分戦力として計上可能な範囲の専門性だと思います。</p>\n<h2 id=\"html-ファイルとして保存\" style=\"position:relative;\"><a href=\"#html-%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%A8%E3%81%97%E3%81%A6%E4%BF%9D%E5%AD%98\" aria-label=\"html ファイルとして保存 permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>HTML ファイルとして保存</h2>\n<p>エクスポート機能を使わずにファイルとして保存すると、HTML ファイル（selenese という形式らしい）が吐き出されます。<br>\nselenese という形式は結構冗長な HTML です。かなしい。<br>\nただし、ここで重要なのが <strong>可逆性があること</strong> です。<br>\nselenese の形式を崩さなければ、 <strong>テキストエディタ等で編集した後でも再度 Selenium IDE で開き直すことが可能</strong> です。</p>\n<p>エクスポート機能を利用すると、様々な形式のコードへエクスポートが可能です。<br>\n<strong>ただし、selenese という形式以外にエクスポートすると、Selenium IDE で開けなくなります。非可逆です。</strong><br>\nで、selenese という形式は結構冗長な HTML です。かなしい。</p>\n<p>可逆性を失うと「エディタが扱えて selenese 形式の HTML が理解できる」エンジニアが必要になってしまうと思います。<br>\nでないとメンテナンスできなくなっちゃうので、できれば IDE で何度でも編集できる形にしておきたい。<br>\nということでエクスポートは selenese 形式一択だと現状考えています。</p>\n<h2 id=\"selenese-runner-で実行する\" style=\"position:relative;\"><a href=\"#selenese-runner-%E3%81%A7%E5%AE%9F%E8%A1%8C%E3%81%99%E3%82%8B\" aria-label=\"selenese runner で実行する permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>selenese-runner で実行する</h2>\n<p>お待ちかねの CLI 化+ヘッドレス化です。</p>\n<h3 id=\"selenese-runner-とは\" style=\"position:relative;\"><a href=\"#selenese-runner-%E3%81%A8%E3%81%AF\" aria-label=\"selenese runner とは permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>selenese-runner とは</h3>\n<p><a href=\"https://github.com/vmi/selenese-runner-java\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">selenese-runner</a>自体の使い方については<a href=\"https://vmi.jp/software/selenium/StudyingSelenium-01/SeleneseRunner-20140118.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">ご本人が公開されているスライド</a>が参考になると思います。</p>\n<p>この便利ツールを使用して、selenese 形式の HTML をコマンドラインから実行できます。</p>\n<h3 id=\"selenese-runner-をホストで動かす\" style=\"position:relative;\"><a href=\"#selenese-runner-%E3%82%92%E3%83%9B%E3%82%B9%E3%83%88%E3%81%A7%E5%8B%95%E3%81%8B%E3%81%99\" aria-label=\"selenese runner をホストで動かす permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>selenese-runner をホストで動かす</h3>\n<p>selenese-runner 単体をホスト側実行するとブラウザが起動し、HTML の内容が実行されます。</p>\n<p><img src=\"/66e15f21dd004700fa340451ea1588a9/selenese-runner.gif\" alt=\"selenese-runner\"></p>\n<p>どうでしょう。いい感じです。</p>\n<h3 id=\"ヘッドレス環境で-selenese-runner-を動作させる\" style=\"position:relative;\"><a href=\"#%E3%83%98%E3%83%83%E3%83%89%E3%83%AC%E3%82%B9%E7%92%B0%E5%A2%83%E3%81%A7-selenese-runner-%E3%82%92%E5%8B%95%E4%BD%9C%E3%81%95%E3%81%9B%E3%82%8B\" aria-label=\"ヘッドレス環境で selenese runner を動作させる permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>ヘッドレス環境で selenese-runner を動作させる</h3>\n<p>cron 等で定期実行したり、CI を回したりするには、GUI のない Linux サーバで実行する必要があると思います。<br>\nということで、その動作環境も作ってみました。</p>\n<blockquote>\n<p><a href=\"https://github.com/Leko/example-selenese-runner-with-hub\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">GitHub – Leko/example-selenese-runner-with-hub: Example of scenario testing used by selenese-runner with Selenium Hub</a></p>\n</blockquote>\n<p>動作させると、</p>\n<p><img src=\"/5463dad8fca34957ade948d6c3bcd669/compose-selenese-runner.gif\" alt=\"compose-selenese-runner\"></p>\n<p>こんな感じです。いかがでしょうか。<br>\nこれなら GUI 不要なので、cron でも CI でも exec でもいい感じにもらえばいいと思います。</p>\n<h3 id=\"コンテナの構成\" style=\"position:relative;\"><a href=\"#%E3%82%B3%E3%83%B3%E3%83%86%E3%83%8A%E3%81%AE%E6%A7%8B%E6%88%90\" aria-label=\"コンテナの構成 permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>コンテナの構成</h3>\n<p>![](<a href=\"https://g.gravizo.com/g\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://g.gravizo.com/g</a>?\n%20digraph%20G%20%7B%0A%20%20%20graph%20%5B%0A%20%20%20%20%20rankdir%20%3D%20LR%0A%20%20%20%5D%3B%0A%0A%20%20%20selenese%3B%0A%20%20%20hub%20%5Blabel%3D%22selenium%2Fhub%22%5D%3B%0A%20%20%20chrome%20%5Blabel%3D%22selenium%2Fnode-chrome%22%5D%3B%0A%20%20%20firefox%20%5Blabel%3D%22selenium%2Fnode-firefox%22%5D%3B%0A%0A%20%20%20selenese%20-%3E%20hub%20%5Blabel%3D%22%2Fwd%2Fhub%22%5D%3B%0A%20%20%20chrome%20-%3E%20hub%20%5Blabel%3D%22Connect%22%5D%3B%0A%20%20%20firefox%20-%3E%20hub%20%5Blabel%3D%22Connect%22%5D%3B%0A%20%20%20hub%20-%3E%20chrome%20%5Blabel%3D%22Execute%22%5D%3B%0A%20%20%20hub%20-%3E%20firefox%20%5Blabel%3D%22Execute%22%5D%3B%0A%20%7D%0A\n)</p>\n<p>こんな感じです。<br>\n設定ファイルの中で selenese コンテナはドライバを<code>remote</code>、<code>remote-url</code>に hub コンテナの URL を指定してあります。<br>\nその指定をすると selenese-runner 側が Selenium hub にテスト実行依頼を投げます。<br>\n依頼を受け取った hub は、接続済みの chrome か firefox を起動しテストを実行します。</p>\n<p>Selenium hub 使ったことなかったので理解するまでが難しかったですが、実際に動かしてみたら簡単に理解できました。<br>\nSelenium hub 自体については公式リポジトリとこちらの記事が参考になりました。</p>\n<blockquote>\n<p>— <a href=\"https://github.com/SeleniumHQ/docker-selenium\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">GitHub – SeleniumHQ/docker-selenium: Docker images for Selenium Standalone Server</a><br>\n— <a href=\"http://www.techscore.com/blog/2015/05/10/selenium-grid/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">» Selenium Grid で複数の実機ブラウザで自動テスト TECHSCORE BLOG</a></p>\n</blockquote>\n<h3 id=\"日本語サポート\" style=\"position:relative;\"><a href=\"#%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%82%B5%E3%83%9D%E3%83%BC%E3%83%88\" aria-label=\"日本語サポート permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>日本語サポート</h3>\n<p>Selenium はデフォルトでは日本語などのマルチバイト文字をサポートしていません。<br>\nなのでスクショを撮る時に □□□ みたいな感じに化けるのですが、せっかくスクショ撮るようにしたなら日本語対応したいな、ということでしておきました。<br>\n<code>selenium/hub</code>側に日本語対応を入れるのかと思っていましたが、<code>node-chrome</code>と<code>node-firefox</code>コンテナの方に入れる必要がありました。<br>\n詳しくは Ubuntu のドキュメントと公開したリポジトリの Dockerfile を御覧ください。</p>\n<blockquote>\n<p>— <a href=\"https://www.ubuntulinux.jp/japanese\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Ubuntu の日本語環境 | Ubuntu Japanese Team</a></p>\n</blockquote>\n<p>ちなみに、<a href=\"https://github.com/SeleniumHQ/docker-selenium/pull/339\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">中国語のタグ</a>の PR に対して、</p>\n<blockquote>\n<p>however not sure if those containers could accept such locale support for general cases</p>\n</blockquote>\n<p>と回答しているので公式のタグとしては登場しなさそうです。</p>\n<h2 id=\"まとめ\" style=\"position:relative;\"><a href=\"#%E3%81%BE%E3%81%A8%E3%82%81\" aria-label=\"まとめ permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>まとめ</h2>\n<p>これをベースに自分たちなりのアレンジで運用してもらえれば、<br>\nスクレイピングもシナリオテストもいい感じに回っていくかな、と思います。</p>","timeToRead":8,"frontmatter":{"title":"Selenium IDEで作ったテストをCLI環境で動かしてみる","tags":["CI","Selenium"],"date":"December 20, 2016","featuredImage":null}}},"pageContext":{"slug":"/how-to-run-testcase-of-selenium-ide-in-cli/","previous":{"fields":{"slug":"/use-chatwork-like-slack/"},"frontmatter":{"title":"ChatWorkだってSlackしたい！！","tags":["Advent Calendar","Chrome extension","JavaScript"]}},"next":{"fields":{"slug":"/should-use-delete-option-to-delete-git-branch-or-tag/"},"frontmatter":{"title":"リモートのタグを一括削除するときは–deleteを使おうと思った話","tags":["Git"]}}}},
    "staticQueryHashes": ["2585454260","2954598359"]}