29
25

More than 5 years have passed since last update.

新しいSelenium IDEのフロー制御系コマンド if / times / while / do ... repeat if

Last updated at Posted at 2018-12-02

この記事は Selenium/Appium Advent Calendar 2018 の3日目の記事です。

こんにちは!
グルグルしてますか!!
人生ですね!!?!?!?!

Selenium IDEでグルグルできるようになりました

新しいSelenium IDEでは、バージョン3.2.0から「Control Flow」と称するフロー制御系のコマンドが実装されました。すなわちグルグルです。
2018年12月3日現在の最新バージョン3.4.5では、次の4種類が利用できます。

  • if ... else if ... else ... end
  • times ... end
  • do ... repeat if
  • while ... end

この辺のコマンドを使うために、旧バージョンでは SelBlocks などSelenium IDEのプラグインを併用して実現していましたね。
「新しいSelenium IDEでは標準実装にしない?」という提案のissueが2017年から何件か作成された末、ついに2018年8月に標準実装されたバージョンがリリースされました!

Please support Page Objects, Flow Control, Keywords, Multi Search and Replace, Resouce folders, and a CSS/Xpath creator.
https://github.com/SeleniumHQ/selenium-ide/issues/56

Missing features, Flow Control and Store Variables
https://github.com/SeleniumHQ/selenium-ide/issues/101

使い方

公式のマニュアルで使い方を確認できます。
https://docs.seleniumhq.org/selenium-ide/docs/en/introduction/control-flow/
ここでは、日本語でかんたんな使い方を紹介します。

if ... else if ... else ... end

次のif文のような制御ができるようになります。

if (targetフィールドに記載の条件式) {
    ... ... ...
} else if (targetフィールドに記載の条件式) {
    ... ... ...
} else {
    ... ... ...
}

Selenium IDE上では次のような感じです。条件式には store 系コマンドで定義した変数を ${変数名} という形で記載できます。

スクリーンショット 2018-12-03 2.32.00.png

times ... end

次のfor文のような制御ができるようになります。

const times = targetフィールドに記載の数字;
for (let i = 0; i < times; i++) {
    ... ... ...
}

Selenium IDE上では次のような感じです。なお、カウンター変数 i に直接アクセスする手段は今のところ無いようです。

スクリーンショット 2018-12-03 2.36.32.png

while ... end

次のwhile文のような制御ができるようになります。

while (targetフィールドに記載の条件式) {
    ... ... ...
}

Selenium IDE上では次のような感じです。条件式には store 系コマンドで定義した変数を ${変数名} という形で記載できます。

スクリーンショット 2018-12-03 2.42.33.png

do ... repeat if

次のdo ... while文のような制御ができるようになります。

do {
    ... ... ...
} while (targetフィールドに記載の条件式);    

Selenium IDE上では次のような感じです。条件式には store 系コマンドで定義した変数を ${変数名} という形で記載できます。

スクリーンショット 2018-12-03 2.44.44.png

デ、データ駆動テストは? foreachは? ハアハア

2018年5月頃から「ExcelなりCSVなり読み込みたいんですよねえ...」というissueは上がっているのですが、現時点でWebExtensionsベースのプラグインに対して有効なファイル操作APIが用意されていないことを理由に実装が進んでいません。
「何言ってんだオメーぜんぜんできるだろ」という不敵なあなたは、ぜひこちらのissueにご意見をどうぞ!!

Feature question - data driven testing
https://github.com/SeleniumHQ/selenium-ide/issues/183

なお、 execute script でJavaScriptの配列を駆使すればなんとかそれっぽいことができるんじゃないかといろいろ試しましたが、無理でした。
相当トリッキーな書き方をしないとダメみたいですし、それは最早Selenium IDEでやるべきことではないということも言えそうです。

今回はここまで

次回は...誰かー! 誰か来てくれーーー!!!
Selenium/Appium Advent Calendar 2018はまだまだ君の挑戦を待っているぜ!

29
25
2

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
29
25