LoginSignup
1
1

More than 5 years have passed since last update.

<メモ> ServiceNow ATF でテストステップを自作する

Last updated at Posted at 2018-11-09

テストステップを自作する

1. 前提

最近ServiceNowをやりはじめた初心者

ServiceNow Kingstonバージョン

Automated Test Frameworkでのテスト作成時
ステップ「フィールド値の設定」

2. やりたいこと

以下のようなフィールドがある。

  • String型
  • 選択肢が設定されている
  • 選択肢がクライアントスクリプトなどで動的に設定されている

このフィールドに値を設定したいが、値の入力欄がリストによる選択形式になっている。当然、動的に追加される選択肢は表示されない。こまった。なんとかして値を設定したい。

3. やってみる

こちらをみる

You can only create configurations for steps that run on the Server. You cannot create configurations for steps that run on the browser.

ブラウザでスクリプトを実行するテストステップは自作できない、とある。たしかに sys_atf_step_config の新規作成フォームの Step environment フィールドでは「UI」が選べない。

4. UIのテストは諦めた

4.1. 標準機能でのレコード作成or更新ではできないのか

できない

Record Insert や Record Update なるテストステップがあるが、同じように値の入力欄がリストによる選択形式で表示されてしまう。

Input Variables (入力変数) である field_values が、それぞれのフィールドの設定をよみといて、値の入力欄をテキストボックスやリストによる選択形式にしてくれているようにみえる。

field_valuesの定義を見ると、ServiceNowの利用者には参照できない
element_mapping_provider=com.glide.automated_testing_framework.ATFVariableElementMapper

4.2. じゃあ自分で作れないのか

サーバーでスクリプトを実行することができるなら、GlideRecord-APIが使える。

以下のようにしてレコードを作成することができた。

(function executeStep(inputs, outputs, stepResult, timeout) {
    var nr = new GlideRecord(inputs.u_table);
    nr.initialize();
    nr.samplecol = inputs.u_samplecol;
    var nrid = nr.insert();
    if (nrid) {
        stepResult.setSuccess();
        stepResult.setOutputMessage("あなたはレコードの作成に成功した。samplecolの値は「" + nr.samplecol +"」だ。");

        outputs.u_samplecol_reference = nrid;
    } else {
        stepResult.setFailed();
        stepResult.setOutputMessage("あなたはレコードの作成に失敗した。");
    }


}(inputs, outputs, stepResult, timeout));

UIのテストステップも自作できるようにしてほしい。。。

おしまい

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