LoginSignup
7
6

More than 5 years have passed since last update.

しれっと書いてみます。

SeleniumIDEの機能の中でもあまり触れられることがない
UI-Element と Rollup 。

今回は その UI-Element について。

これはロケーションの指定をシナリオケースから分離する仕組みです。
ロケーションにラベルを付けて、シナリオケースにはラベルで定義しておき
画面の構成がかわっても、シナリオケースには手を入れる必要がなくなる、と。
で、ロケーションに使用するラベル定義は 別ファイルに JSON形式で定義します。

使うには、それぞれをファイルに定義しておき、オプションで指定した後
seleniumIDEを再起動すればOK。

これを使うメリットは、テストケースからテスト対象ページ内の要素の定義を分離できるところです。
これは、同一ページに対し複数のテストケースを適用する場合以下のメリットがあります

  • そのテストケースの保守コストを下げることができる
  • 別ファイルにしておくことでページ定義とテストケース設計を平行にできる

逆にページ内の要素が少ない場合は、別ファイルで定義する手間が無駄になりそうですが、画面内の要素が少なくても、これを導入するメリットがある機能がありそうなのです。

リファレンスについているサンプルがこれです。

map.addElement('searchPages', {
    name: 'result'
    , description: 'link to a result page'
    , args: [
        {
            name: 'index'
            , description: 'the index of the search result'
            , defaultValues: range(1, 21)
        }
        , {
            name: 'type'
            , description: 'the type of result page'
            , defaultValues: [ 'summary', 'detail' ]
        }
    ]
    , getLocator: function(args) {
        var index = args['index'];
        var type = args['type'];
        return "//div[@class='result'][" + index + "]"
            + "/descendant::a[@class='" + type + "']";
    }
});

ポイントは args と getLocator ですね。
要素を静的にxPathで定義するのではなく 関数を定義することにより getLocatorメソッドを定義しています。
これに引数として args を定義しています。

map.addElement('searchPages', {
   name: 'result'
   , description: 'link to a result page'
   , args: [{
     name: 'index'
   , description: 'the index of the search result'
   , defaultValues: range(1, 21)
  }
, {
     name: 'type'
   , description: 'the type of result page'
   , defaultValues: [ 'summary', 'detail' ]
  }
]
, getLocator: function(args) {
    var index = args['index'];
    var type = args['type'];
    return "//div[@class='result'][" + index + "]" + "/descendant::a[@class='" + type + "']";
  }
});

これを使う場合

<td>click</td>
<td>UI=searchPages::result(index=1,type=summary)</td>
<td></td>

と、パラメータを指定することにより、ロケーションを指定することができます。

例のように検索結果に付いたテキストリンクを動的に指定することができる訳です

情報源

あとがき

メンテナンス性を向上させるテクニックですが、IDEでのスクリプトを巨大化させると結局はメンテナンスの負荷は大きくなってしまうので、これだけに頼らず他の方法と組み合わせて管理するのが現実的ですね。

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