2
2

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.

robotframework + seleniumlibrary 導入

Posted at

モチベーション

Qiitaの記事は「将来の自分に役に立つこと」よりも「過去の自分に役に立つこと」を記載するのがよい、ということを聞き、robotframework + seleniumlibrary 導入時に自分がやったことをまとめておく。

環境や前提条件

windows10
PowerShell
python3.7

手順

python install

Python 3.7 (64-bit)

  1. https://www.python.org/downloads/ の「Download Python 3.7.2」ボタンをクリック
  2. python-3.7.2-amd64-webinstall.exe がDownloadされる
  3. python-3.7.2-amd64-webinstall.exe をダブルクリック
  4. 以下省略
  5. Powershellからコマンドラインでinstallバージョンを確認
> python -V
Python 3.7.2

robotframework + seleniumlibrary install

Powershellからコマンドラインでinstall

> pip install robotframework-seleniumlibrary==3.3.1

robotコマンドでrobot frameworkを起動してみると、少なくとも引数一つ必要だけど一つもないよと怒られる。

> robot
[ ERROR ] Expected at least 1 argument, got 0.

Try --help for usage information.

web driver(chrome) install

http://chromedriver.chromium.org/downloads から ChromeDriver 2.45(ファイル名はchromedriver.exe) をダウンロード。
2.45 は「Supports Chrome v70-72」なのでChromeのバージョンを確認して適したdriverをダウンロードしましょう。
ひとまずC:\robot というフォルダにchromedriver.exeは置きました。

簡単な例を動かしてみる

test.robotというgoogleにアクセスするだけのテストを作成。

test.robot
*** Settings ***
Documentation     Simple example using SeleniumLibrary.
Library           SeleniumLibrary

*** Variables ***
${LOGIN URL}      https://www.google.co.jp/
${BROWSER}        Chrome

*** Test Cases ***
Valid Login
    Open Browser To Login Page
    [Teardown]    Close Browser

*** Keywords ***
Open Browser To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}
    Title Should Be    Google

テスト実行
コマンド実行pathにweb driverがあるので動きます。

PS C:\robot> robot .\test.robot
==============================================================================
Test :: Simple example using SeleniumLibrary.
==============================================================================
Valid Login
DevTools listening on ws://127.0.0.1:52052/devtools/browser/e1098142-dc9c-4b12-a75e-63a0ba65d175
Valid Login                                                           | PASS |
------------------------------------------------------------------------------
Test :: Simple example using SeleniumLibrary.                         | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  C:\robot\output.xml
Log:     C:\robot\log.html
Report:  C:\robot\report.html

もし、ドライバーが無い状態でテスト実行すると、chromedriverがPATHの中にないよと教えてくれます。

PS C:\robot> robot .\test.robot
==============================================================================
Test :: Simple example using SeleniumLibrary.
==============================================================================
Valid Login                                                           | FAIL |
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
------------------------------------------------------------------------------
Test :: Simple example using SeleniumLibrary.                         | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output:  C:\robot\output.xml
Log:     C:\robot\log.html
Report:  C:\robot\report.html

log.htmlを開き赤色になっている項目を確認すれば、エラーの要因がわかります。
image.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?