2
2

More than 3 years have passed since last update.

headlessブラウザを利用したcui環境での結合テストの自動化(Selenium IDE+UAとProxy指定有)

Posted at

目標

以下の要件を満たす環境を構築しました。
- cui環境での実行(JenkinsなどのCI環境で定期実行を目指したいため)
- User Agent指定可
- Proxy指定可

環境構築手順

1. Chromeの拡張機能である「Selenium IDE」をインストールします。

2. Selenium IDEを起動し、適当にテストケースを作成します。この時作成するテストケースはモバイルページを検証するようなテストケースにします。

3. 適当なファイル名(例:sample.ide)でテストケースを保存します。

4. 以下のモジュールをインストールします。
・selenium-side-runner
・chromedriver

$ brew install node
$ npm install -g selenium-side-runner
$ npm install -g chromedriver

5. selenium-side-runnerのオプションに、Chromeの起動オプションを指定し、テストケースを実行します。

  • 実行するコマンド例
selenium-side-runner -c "goog:chromeOptions.args=[--headless,--nogpu,--proxy-server=http://proxy-host:8080,--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1] browserName=chrome" sample.side
  • 指定したChromeの起動オプションについて
オプション 説明
--headless Chromeをヘッドレスモードで起動します
--nogpu GPUの利用をOFF
--proxy-server プロキシサーバを指定(例:http://proxy-host:8080)
--user-agent UAを指定(例:Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1)

公式マニュアルに記載のProxy指定方法では上手くProxyを指定できなかったため、今回はChromeの起動オプションにProxyを指定して要件を実現しました。

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