RobotFramework + SeleniumLibrary + Appiumにて、Genymotion上のChromeを使ってテストする

以前、AndroidChromeを使うテストをRobot Frameworkで書いてみました。
RobotFramework + SeleniumLibraryにて、Android実機上のChromeを使ってテストする - メモ的な思考的な

この時は実機上のChromeを使っていました。

今回は、Androidエミュレータの一種であるGenymotion上のChromeを使って、テストしてみます。

 
目次

 

環境

  • Mac OS X 10.11.6
  • Python 3.6.2
  • RobotFramework 3.0.2
  • SeleniumLibrary 3.0.0b1
  • Node.js 8.4.0
  • Xcode 8.2.1
  • Appium 1.7.1
  • Genymotion 2.10.0

 
上記の環境はすべて構築済とします。

なお、Appiumのインストールは、以下の記事で行ったものを流用しています。
RobotFramework + SeleniumLibrary + Appiumで、iOSシミュレータ上のSafariブラウザでテストする - メモ的な思考的な

 

環境構築

Genymotion上に仮想デバイスを作成

今回は Google Nexus5 - 5.1.0 - API22 - 1080x1920 をセットアップします。

セットアップ終了後、仮想デバイスを起動したままにしておきます。

 

OpenGAppsのChromeをインストール

今回はGenymotoinoのサイトでも紹介されている通り、 OpenGApps を使ってChromeをインストールします。
Genymotion 2.10 – Google Play Services and Play Store Are There!

Google Playを使うにはVariantは nano で良いのですが、Chromeは含まれていません。

そのため、以下の内容でダウンロードします。

Platform Android Variant
x86 5.1 full

 
zipファイルのダウンロードが終わったら、そのzipファイルをGenymotionへとドラッグ&ドロップします。

しばらくすると仮想デバイスへのインストールが終わります。

インストール後、仮想デバイスを再起動すると、Chromeがインストールされています。

 

Robot Frameworkのテストコード実装

実機上でテストしたものと同じソースコードとなります。

*** Settings ***

Library  SeleniumLibrary


*** Keywords ***
GoogleでPythonを検索してスクリーンショットを撮り、結果を出力する
    # 以下のコードをRobot Framework風にした
    # http://qiita.com/orangain/items/db4594113c04e8801aad

    # 以下を参考に、Chromeのオプションを追加して、Chromeを起動する
    # https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started---android
    ${options} =  evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys
    call method  ${options}  add_experimental_option  androidPackage  com.android.chrome
    create webdriver  Chrome  chrome_options=${options}

    # Googleのトップ画面を開く
    go to  https://www.google.co.jp/

    # タイトルにGoogleが含まれていることを確認する
    ${page_title} =  get title
    should contain  ${page_title}  Google

    # 検索後を入力してEnter
    input text  name=q  Python
    # Robot FrameworkではEnterキーは\\13になる
    # https://github.com/robotframework/Selenium2Library/issues/4
    press key  name=q  \\13

    # Ajax遷移のため、適当に2秒待つ
    sleep  2sec

    # タイトルにPythonが含まれていることを確認する
    ${result_title} =  get title
    should contain  ${result_title}  Python

    # スクリーンショットを撮る
    capture page screenshot  filename=result_google_python_android.png

    # ログを見やすくするために改行を入れる
    log to console  ${SPACE}

    # 検索結果を表示する
    @{web_elements} =  get webelements  css=h3 > a
    :for  ${web_element}  in  @{web_elements}
    \  ${text} =  get text  ${web_element}
    \  log to console  ${text}
    \  ${href} =  call method  ${web_element}  get_attribute  href
    \  log to console  ${href}

    # ブラウザを終了する
    close browser


*** TestCases ***

GoogleでPythonを検索するテスト
    GoogleでPythonを検索してスクリーンショットを撮り、結果を出力する

 

テスト実行

Genymotionの仮想デバイスを起動

シャットダウンしているとテストできないため、起動しておきます。

 

Appiumを起動

ターミナルより起動します。

$ appium
[Appium] Welcome to Appium v1.7.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

 

テストを実行

ターミナルより実行します。

$ robot android_chrome.robot 
================
Android Chrome         
================
GoogleでPythonを検索するテスト                                         
Python - ウィキペディア
https://ja.m.wikipedia.org/wiki/Python
Python基礎講座(1 Pythonとは) - Qiita
http://qiita.com/Usek/items/ff4d87745dfc5d9b85a4
Pythonとは - python.jp
https://www.python.jp/about/
Top - python.jp
https://www.python.jp/
【入門者必見】Pythonとは?言語の特徴やシェア、仕事市場を徹底解説 | 侍エンジニア塾ブログ | プログラミング入門者向け学習情報サイト
http://www.sejuku.net/blog/7720
Python 3を使うべきでない場合(なんてない) | プログラミング | POSTD
http://postd.cc/case-python-3/
Pythonに咬まれるな : 注意すべきセキュリティリスクのリスト | プログラミング | POSTD
http://postd.cc/a-bite-of-python/
GoogleでPythonを検索するテスト    | PASS |

テストがパスしました。

また、スクリーンショットも撮影されています。

f:id:thinkAmi:20170928214013p:plain:w400

 

ソースコード

GitHubに上げました。 selenium_appium_sample/android_chrome.robot ファイルが今回のテストファイルです。
thinkAmi-sandbox/RobotFramework-sample: Robot Framewrok samples