Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Requires Platform 4.2.2+以上が必要Test Script


テストスクリプト API

Nexaweb Platform 4.2.2

...

には、自動機能テストの記述に使用できる Test Script API

...

が含まれています。Test Script API

...

  • 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

...

は、Nexaweb アプリケーションの UI コンポーネントをスクリプト可能なオブジェクトとして公開するので、自動機能テストの構築が簡素化されます。Test Script API には次の機能があります。
  • コンポーネントを識別する
  • マウスのクリック操作や座標に依存せずに、コンポーネントを操作する
  • コンポーネントから意味のある値を容易に取得する
  • 記録を使用せずに、有用なテスト スクリプトを記述する
このドキュメントでは、Mercury の Quick Test Professional (QTP)

...

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.

Image Removed
The following script demonstrates how to obtain the Test Script Object from the QTP Wrapper object named "Some Label".

...

を使用した、Test Script API の使用方法を示していますが、この API に他の製品を使用することもできます。

はじめに

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

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

In addition, you can perform the following tasks with a single API call.

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

...

languagehtml/xml
linenumberstrue

...

メソッドを使用すると、このスクリプトを実行するためにボタン オブジェクトをオブジェクト リポジトリに追加する必要はありません。ただし、スクリプトでは QTP メソッドの JavaApplet() を使用してアプレットを検出し、.Object を使用してアプレット オブジェクトにアクセスするため、リポジトリにアプレットを追加する必要があります。

Test Script API の使用:

テスト スクリプト オブジェクトを取得したら、それを使用して基本 UI コンポーネントのコンテンツを操作およびテストできます。

Test Script API には、次の複合コンポーネント用のテスト スクリプト オブジェクトが含まれています。

  • コンボボックス
  • リストボックス
  • テーブル
  • ツリー
  • ツリーテーブル
また、1 回の API 呼び出しで次のタスクを実行できます。
  • コンボボックス内のアイテムの選択
  • テーブル内のセルの編集
  • リストボックスのアイテムの取得
  • テキストフィールドへの文字列の入力
  • ドラッグ&ドロップによるオブジェクトの移動
Test Script API の詳細については、DevCenter の 「API および XML リファレンス」の [Test 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
true
Code Block
languagejava
linenumbers
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

...