Skip to main content
Skip table of contents

Scripting Language Principles

覚えておくべき基本原則がいくつかある:

  • 1行のコードには1つのコマンドが含まれる

  • コマンドは以下から構成される:

    • アクション - Type、Pressなど

    • プロシージャのヘッダ - "Procedure "キーワードを使用する。

    • プロシージャ呼び出し - "<procName> <param>" を使用する。

    • コメント - 先頭の "#"を使用

  • 言語は通常、大文字と小文字を区別しない。

  • コマンドは、次の構造 "<keyword> <argument> <params>" によって識別される。

  • コマンドのパラメータは、どのような順番でも指定できます。

ユーザーは、コードウィザードとプロパティダイアログによって、スクリプトの原則を理解することができます。

スクリプト言語の構造を示すために、簡単なテストスクリプトの例を考えてみましょう。これは、電卓アプリケーションを開き、5+5の和を計算します。これは、スクリーンショットを保存する以外、動作検証もテスト結果の報告も実装していない非常に単純なスクリプトであることに注意してください。

WindowsスクリプトとLinuxスクリプトの細かな違いに注意してください。電卓アプリケーションの名前と、実行ボックスを開くホットキーが違うだけです。クロスプラットフォームのテストスクリプトを作成するために、このようなシステムに依存するコードを分離する方法を、次のトピックの1つで紹介します。

calculator.tpr (Windows 版)

calculator.tpr(Linux/Gnome版)

JS
# Generic procedure to start an application on Windows. 
# We take advantage of the Windows+r key to open the Run box. 
procedure startApp { 
  Press Windows+r wait= 3s 
  Typeline "{1}" wait= 4s
} 

# Start calculator, type "5+5" followed by Enter and take a screenshot.
startApp calc 
Typeline "5+5" wait= 2s 
Screenshot calculator_result.jpg desc= "Result of 5+5"

JS
# Generic procedure to start an application on Linux/GNOME. 
# We take advantage of the Alt+F2 key to open the Run box. 
procedure startApp { 
  Press Alt+F2 wait= 3s 
  Typeline "{1}" wait= 4s
} 

# Start calculator, type "5+5" followed by Enter and take a screenshot.
startApp gnome-calculator 
Typeline "5+5" wait= 2s 
Screenshot calculator_result.jpg desc= "Result of 5+5"

この言語は以下の原則に基づいている:

  • テストスクリプトはプレーンテキストファイルです。各行には、コマンド(Press、Typeline、Screenshot、...)、プロシージャーヘッダー("procedure "キーワードで始まる)、プロシージャーコール("startApp <param>")、またはコメント("#"で始まる)を含めることができます。例にはありませんが、if/else文やfor文が含まれていることもあります。

  • コマンドは最初の単語(青)で識別され、その後に引数(緑)と「%26lt;param%26gt;="%26lt;value%26gt;"」という形式のパラメータリスト(黒太字)が続くのが普通である(常にそうであるとは限らない)。

  • 大文字と小文字は区別されない。コマンドとそのパラメータは、大文字と小文字を自由に組み合わせて指定することができる。しかし、この例のプロシージャー名 "startApp "は大文字と小文字を区別する。

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.