0
0

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 1 year has passed since last update.

robot framework use multi devices tipcs

Posted at

Background

robotframework + appium で モバイルのテストを行う場合、複数端末を取り扱うすることがある。その時、デバイスを切り替えを簡単に行える工夫があると、開発・テストに効率が良い。
その時の工夫をメモとして残す

yml

今回は、設定ファイルとしてyamlを使用する。
robotframeworkでyamlを読み込むライブラリを設定する

pip3 install pyyaml

尚、robot framework + appium 構築手順はこちらを参照
https://qiita.com/emurin/items/230e080bf3bd9a9f19d2

sorce code sample

setting.yml

yml fileに以下のように複数のデバイス情報を定義する

# setting.yml

device:
  iPhone01:
    udid: XXXXXXXX-XXXXXXXXXXXXXXXX
    platformVersion: '16'
    deviceName: iPhone13
    platformName: iOS
  iPhone02:
    udid: XXXXXXXX-XXXXXXXXXXXXXXXX
    platformVersion: '15'
    deviceName: iPhone12
    platformName: iOS
  iPhone03:
    udid: XXXXXXXX-XXXXXXXXXXXXXXXX
    platformVersion: '16'
    deviceName: iPhone11
    platformName: iOS

この例では、3つのiPhoneを定義している。
最低限、appiumへ渡すcapabilitiesとして以下を定義する

  • udid
  • platformVersion
  • deviceName
  • platformName

main.robot

以下にmain codeを示す。
単純に、アプリを起動するだけのscriptである。

*** Settings ***

Library    openpyxl
Library    AppiumLibrary
Library    Process
Library    OperatingSystem
Library    yaml
Library    String

# ↓ 上記作成したsetting.ymlを読み出す
Variables    ../data/setting.yml

*** Variables ***
${APPIUM_SERVER}    http://localhost:4723   # appium server
${DEVICE_NO}    iPhone01  # default device
${app}  /Users/xxxxx/app/xxxxx.ipa     # テスト対象のiOS appのipa
${automationName}  XCUITest   # iOS APPの場合

*** Keywords ***

# APPを起動する処理
Launch_App
    Open Application    ${APPIUM_SERVER}
    ...    platformName=${device.${DEVICE_NO}.platformName}
    ...    app=${app}
    ...    automationName=${automationName}
    ...    udid=${device.${DEVICE_NO}.udid}
    ...    deviceName=${device.${DEVICE_NO}.deviceName}
    ...    platformVersion=${device.${DEVICE_NO}.platformVersion}

*** Test Cases ***

Show Settings
    Read Data From Yaml File

Open Mobile APP
    Launch_App

工夫点は、${device.${DEVICE_NO}.platformName}でdeviceのcapabilities情報を使用している点である。

実行

デバイスを切り替えるとき、以下のargumentを用いる。

variable : これを用いることで、Variablesの値を実行時に引数で指定することができる。

robot --variable DEVICE_NO:iPhone03 --pythonpath . --outputdir=./results/ testsuit/main.robot

上記のように、DEVICE_NOの値、iPhone01 ~ iPhone03 と簡単にデバイスを切り替えることができる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?