Requires Platform 4.2.2+以上が必要Test Script
テストスクリプト API
Nexaweb Platform 4.2.2
...
...
...
- Identify components
- Interact with components without relying on mouse clicks and coordinates
- Easily retrieve meaningful values from components
- Write a useful test script without using record
...
- コンポーネントを識別する
- マウスのクリック操作や座標に依存せずに、コンポーネントを操作する
- コンポーネントから意味のある値を容易に取得する
- 記録を使用せずに、有用なテスト スクリプトを記述する
...
Getting Started
In Nexaweb 4.2.2 to 4.5.6, because the test script API is built into the unobfuscated test jars, there is no additional setup required to use them.
In Nexaweb 4.5.7 and later, the testscript classes are packaged in the plugin JAR file, PluginTestScript.jar. You can use the testscript classes with both debug (unobfuscated) and non-debug (obfuscated) JARs. You specify which type of JARs to use with the testclasses by editing the <ui-test> parameter in the nexaweb-client.xml configuration file. The <ui-test> parameter is set to true by default for use with debug (unobfuscated) JARs. To use non-debug (obfuscated) JARs, edit the nexaweb-client.xml configuration file to set the <ui-test> parameter to false.
To use the test script API, follow these steps:
1. Locate the PluginTestScript.jar file in your platform\dist\plugins folder.
2. Copy this file to your application's WEB-INF\client\plugins\pre-loaded directory.
How to get a test script object
The test scripts that the QTP record mechanism generates use QTP's object wrapper of the actual UI component (for example, Label or Button). QTP stores the object wrappers in its object repository. By default, QTP names objects in this repository based on their actual class (for example, NRichLabel or NButton). However, you can rename objects in the repository by right clicking on the object name as it appers in the object repository dialog. The name of the object as it appears in the object repository, is the the name that the method inside the QTP script uses to locate the QTP object wrapper.
The following script demonstrates how to obtain the Test Script Object from the QTP Wrapper object named "Some Label".
...
はじめに
Test Script API は、難読化されていないテスト JAR ファイルに構築されるため、このAPIを使用するのに追加の設定を行う必要はありません。「Nexaweb アプリケーションクライアントのコンフィギュレーションファイルの設定」で説明されている手順で、特に <ui-test> エントリを true に設定する手順は不要です。
テストスクリプトオブジェクトを取得する方法
QTP の記録機能によって生成されるテストスクリプトでは、ラベルやボタンなど、実際の UI コンポーネントの QTP オブジェクトラッパーが使用されます。QTP では、オブジェクトラッパーがそのオブジェクトリポジトリ内に保存されます。デフォルトで、このリポジトリ内のオブジェクトには、NRichLabel や NButton など、実際のクラスに基づいて名前が付けられます。ただし、オブジェクトリポジトリダイアログに表示されるオブジェクト名を右クリックして、リポジトリ内 のオブジェクト名を変更できます。オブジェクトリポジトリで表示されるオブジェクトの名前は、QTP オブジェクトラッパーを検索する際にQTP スクリプト内のメソッドによって使用されます。
次のスクリプトは、"Some Label" という名前の QTP ラッパーオブジェクトからテストスクリプトオブジェクトを取得する方法を示します。
Set labelObj = Browser("Welcome To Nexaweb").Page("Welcome
...
To
...
Nexaweb").JavaApplet("DefaultJvmDetector").
...
JavaObject("Some
...
Label").Object.getScriptObject()
Set labelObj =
...
スクリプト内でテストスクリプトオブジェクトを後で使用するために、変数の形で保存します。
Browser("Welcome To Nexaweb")
Browser
...
は、テスト対象のQTP ブラウザオブジェクトの検出に使用される QTP メソッドです。この例のWelcome To Nexawebは、オブジェクトリポジトリで定義されているブラウザオブジェクトの名前を表します。
Page("Welcome To Nexaweb")
Page
...
は、テスト対象のQTP ページオブジェクトの検出に使用される QTP メソッドです。この例のWelcome To Nexawebは、オブジェクトリポジトリで定義されているページオブジェクトの名前を表します。
JavaApplet("DefaultJvmDetector")
JavaApplet
...
は、テスト対象のQTP アプレットオブジェクトの検出に使用される QTP メソッドです。この例のDefaultJvmDetectorは、オブジェクトリポジトリで定義されているアプレットオブジェクトの名前を表します。
JavaObject("Some Label")
JavaObject は、テスト対象のQTP JavaObject
...
ラッパーの検出に使用される QTP メソッドです。この例のSome Labelは、オブジェクトリポジトリで定義されているアプレットオブジェクトの名前を表します。
.Object
...
QTP JavaObject
...
ラッパーの Object プロパティは、Nexaweb の基本 UI コンポーネント (例: ラベル) にアクセスします。
getScriptObject()
...
getScriptObject()
...
メソッドは、Nexaweb の基本 UI コンポーネントに関連付けられているテストスクリプトオブジェクトを返します。Test Script API メソッドは、このテストスクリプトオブジェクトに適用されます。
たとえば、次のスクリプトでは、Test Buttonというテキストのボタンを検出して、このボタンをクリックします。
Set appObj = Browser("Welcome To Nexaweb").Page("Welcome To Nexaweb").JavaApplet("DefaultJvmDetector").Object.getScriptObject()
Set buttonObj = appObj.findObject("\\button[@text='Test Button']" )
buttonObj.click
...
findObject()
...
Using the Test Script API
Once you obtain a test script object, you can then use it to interact with and test the contents of the underlying UI component.
The Test Script API includes test script objects for the following composite components
- ComboBox
- ListBox
- Table
- Tree
- TreeTable
In addition, you can perform the following tasks with a single API call.
- Selecting an item in a combobox
- Editing a cell in a table
- Retrieving the items of a listbox
- Typing a string into a textfield
- Dragging an object and dropping it on another
For more information on the Test Script API, select the Test API tab in the API and XML Reference section of the DevCenter.
Example:
This example tests an application that sets the value of a label based on the value of an item selected from a combobox. The text of the label is set within a MCO call that handles the onCommand() event of the combobox. The test first verifies the intial state of the combobox and the label. It then selects each item of the combobox. After each selection it tests the text of the combobox against the text of the item being selected. It then also tests the text of the label against the value of the item being selected.
The XML UI
...
language | html/xml |
---|---|
linenumbers | true |
...
メソッドを使用すると、このスクリプトを実行するためにボタン オブジェクトをオブジェクト リポジトリに追加する必要はありません。ただし、スクリプトでは QTP メソッドの JavaApplet() を使用してアプレットを検出し、.Object を使用してアプレット オブジェクトにアクセスするため、リポジトリにアプレットを追加する必要があります。
Test Script API の使用:
テスト スクリプト オブジェクトを取得したら、それを使用して基本 UI コンポーネントのコンテンツを操作およびテストできます。
Test Script API には、次の複合コンポーネント用のテスト スクリプト オブジェクトが含まれています。
- コンボボックス
- リストボックス
- テーブル
- ツリー
- ツリーテーブル
- コンボボックス内のアイテムの選択
- テーブル内のセルの編集
- リストボックスのアイテムの取得
- テキストフィールドへの文字列の入力
- ドラッグ&ドロップによるオブジェクトの移動
例:
この例で は、コンボボックスから選択したアイテムの値に基づいて、ラベルの値を設定するアプリケーションをテストします。ラベルのテキストは、コンボボックスの onCommand() イベントを処理する MCO 呼び出し内で設定されます。このテストでは、最初にコンボボックスとラベルの初期状態を確認します。次に、コンボボックスの各アイテムを選択します。選択 が完了すると、コンボボックスのテキストを、選択されているアイテムのテキストと照らし合わせてチェックします。次に、ラベルのテキストを、選択されてい るアイテムの値と照らし合わせてチェックします。
XML UI
Code Block |
---|
<nxml> <mco:declarations xmlns:mco="http://nexaweb.com/mco"> <mco:mco id="eventMco" src="ComboBoxHandler"/> </mco:declarations> <rootPane> <comboBox id ="combobox" text="ComboBox" onCommand="mco://eventMco.handleComboBoxOnCommand( mylabel )"> <listBox> <listItem text="Tree Item 1" value="one"/> <listItem text="Tree Item 2" value="two"/> <listItem text="Tree Item 3" value="three"/> </listBox> </comboBox> <label id = "mylabel" text="Label to Change"/> </rootPane> </nxml> |
...
MCO
Code Block | |
---|---|
language | java | linenumbers | true
import com.nexaweb.client.ClientEvent; import com.nexaweb.client.ClientSession; import com.nexaweb.client.mco.AbstractMco; import com.nexaweb.client.mco.McoContainer; import com.nexaweb.xml.Document; import com.nexaweb.xml.Element; public class ComboBoxHandler extends AbstractMco { public void handleComboBoxOnCommand( Element label ) { ClientSession clientSession = McoContainer.getClientSessionFromMco(this); Document uiDocument = clientSession.getDocumentRegistry().getUiDocument(); ClientEvent clientEvent = clientSession.getEventHandler().getClientEvent(); synchronized ( uiDocument.getDomSynchronizationObject()) { String value = clientEvent.getParameter( "value" ); label.setAttribute( "text", value ); } } } |
...
テスト
Code Block |
---|
...
' |
...
アプレットのスクリプトオブジェクトを取得します。 |
...
Set appObj = Browser("Welcome To Nexaweb"). |
...
Page("Welcome To Nexaweb").JavaApplet("DefaultJvmDetector"). |
...
Object.getScriptObject()
|
...
' |
...
|
...
コンボボックスのスクリプトオブジェクトを取得します。 |
...
Set comboBox = appObj.findObjectById("combobox") ' |
...
ラベルのスクリプトオブジェクトを取得します。 |
...
Set label = appObj.findObjectByid("mylabel") ' |
...
|
...
コンボボックスの初期状態をテストします。 |
...
|
...
text = comboBox.getText()
|
...
if( text <>"ComboBox") then
result = "Expected 'ComboBox' Actual was '" + text + "'"
Reporter.ReportEvent micFail,"ComboBox", result
|
...
Else
|
...
Reporter.ReportEvent micDone,"ComboBox", "Intial Text passed. was 'ComboBox'" End If |
...
' ラベルの初期状態をテストします。 ] text = label.getText() if( text <>"Label to Change") then result = "Expected 'Label to Change' Actual was '" + text + "'" Reporter.ReportEvent micFail,"Label", result Else Reporter.ReportEvent micDone,"Label", |
...
"Intial Text passed. was 'Label to Change'" End If ' |
...
コンボボックスのアイテム数を取得します。 itemCount = comboBox.getItemCount() ' |
...
アイテムのベクトルと戻り値のサイズを取得します。 |
...
|
...
Set itemobjs = comboBox.getItems()
sizeItems = itemobjs.size()
' |
...
戻り値のサイズが正しいことを確認します。 if( itemCount <> sizeItems ) then result = "Expected " +itemCount + |
...
" tiems Actual was '" + sizeItems + "'"
Reporter.ReportEvent micFail,"Label", result
Else
Reporter.ReportEvent micDone,"ComboBox", |
...
|
...
"Number of Items was "+itemCount
End If
' |
...
選択内容を確認し、onStateChange() |
...
イベントが正しく発生したことを確認するために、 |
...
' |
...
各アイテムを選択し、コンボボックスおよびラベルのテキストをテストします。 |
...
For i = 0 to itemCount - 1 ' |
...
アイテムを選択します。 comboBox.selectItemAt( i ) ' |
...
コンボボックスのテキストと、選択されているアイテムのテキストを照らし合わせてチェックします。 |
...
|
...
|
...
|
...
|
...
|
...
tag = "Selected Item #" + CStr(i) + " - ComboBox"
expectedText = itemobjs.elementAt(i).getText()
text = comboBox.getText()
if( text <> expectedText ) then
result = "Expected '" + expectedText + |
...
|
...
"' Actual was '" + text + "'" |
...
Reporter.ReportEvent micFail,tag, result
Else
Reporter.ReportEvent micDone, tag,
|
...
"ComboBox text was '" + expectedText +"'"
End If
' |
...
ラベルのテキストを、選択されているアイテムの値と照らし合わせてチェックします。 |
...
|
...
|
...
|
...
tag = "Selected Item #" + CStr(i) + " - Label" expectedText = itemobjs.elementAt(i).getValue() text = label.getText() if( text <> expectedText) then result = "Expected '" + expectedText + "' Actual was '" + text + |
...
"'" |
...
|
...
|
...
Reporter.ReportEvent micFail,tag, result
Else
Reporter.ReportEvent micDone,tag, |
...
|
...
"Label Text passed. was '" + expectedText +"'" End If Next |
...
|