消除識別測試對象過程中的二義性情形(2)

發表于:2011-12-13來源:未知作者:娃娃點擊數: 標簽:
點擊 Test Object 然后在主窗口的菜單上點擊 Insert Object(s) 以打開向導對話框。 使用 Object Finder 來強調主框架,然后選中它。 選擇 Include all available objects o

  點擊 Test Object 然后在主窗口的菜單上點擊 Insert Object(s) 以打開向導對話框。

  使用 Object Finder 來強調主框架,然后選中它。

  選擇 Include all available objects on this window 然后點擊 Finish 。

  如圖 4 所示,現在您可以看到添加至對象映射的主框架的更多子節點。

  重點:

  盡管您選擇了“include all”選項,該選項并沒有 包含主框架的所有子節點。該對象映射只能幫助您知道 Place Order 按鈕的位置。

  圖 4. 對象影響更加具體的層級結構

添加的測試對象擁有多個附屬對象

  您可以使用另外一種工具,來找到主框架的所有子節點。實際上,您剛剛已經使用了它。它就是 Insert Object(s) 向導對話框(圖 4)。使用這個向導,您就可以看到所有的 可映射對象。按照以下的步驟來定位 Place Order 按鈕。

  在主窗口中選擇 Test Object >Insert Object(s) 以重新打開向導對話框(圖 5)。

  對于 Selection Method,選擇 Test Object Browser 。

  找到 Place Order 按鈕,根據上面生成的測試對象映射給出的層級關系中的暗示進行操作。

  圖 5. 測試對象瀏覽器

對象映射中按鈕的確切位置

  根據 Test Object Browser,您可以在測試對象映射中看到許多的對象。對象瀏覽器中的對象的順序,與測試對象映射中的順序不同。但是,測試對象映射僅僅給了您一點暗示,以幫助您在對象瀏覽器中找到當前的對象。通過再一次按照前面介紹的步驟進行操作,您可以輕松找到文件夾的圖形節點。然后您可以找到從圖形節點到按鈕節點的確切路徑(見于圖 6)。

  圖 6. 從圖形到 Place Order 按鈕的路徑

對象映射中從圖片到 Place Order 的路徑

  如圖 6 所示,從圖形節點到按鈕節點的路徑如下所述。注意子類的索引在這里非常重要。

  首先,將三個層次移動到父層次上。

  然后移動主框架的 FIFTH 。

  使用 API 來執行導航操作

  現在您已經知道,怎樣找到兩個測試對象之間的路徑。在本部分中,您將會學到怎樣使用 API 來自動定位帶有給定路徑的目標測試對象。這項任務所需的 API 在列表 2 進行了總結。

  列表 2. 定位測試對象所需的 API

				/**
* This method returns an array of references to the object's mappable children.
* The references to the objects should be released by calling he unregister method.
* If the object has no mappable children, a 0-length array will be returned.
**/
TestObject[] testObject.getMappableChildren();

/**
* This method returns a reference to the parent object that appears in the object map.
* The references to the objects should be released by calling he unregister method.
**/
TestObject testObject.getMappableParent();

/**
* This method returns the topmost mappable parent object that appears in the object map.
* The references to the objects should be released by calling he unregister method.
**/
TestObject testObject.getTopMappableParent();

  至于簡單性,我們并不使用 unregister 方法來注銷迭代的測試對象。ObjectFinder 類是含有所有導航操作的輔助類。圖 7 中的 UML 顯示了這些類之間的關系。注意出于穩定性考慮,TestObjectNotLocatedException 必須源自于 RuntimeException 。

  圖 7. 類與 UML 之間的關系

類 ObjectFinder 是外觀類

  考慮一下路徑范例,列表 3 向您展示了怎樣書寫代碼以找到 Place Order 按鈕:

  列表 3. 找到 Place Order 按鈕的對象

				// This method is used to find the button Place Order
public GuiTestObject PlaceOrder() throws TestObjectNotLocatedException{
	// The path we specified to find the button from the album image
	// First move up 3 times, then move down to the fifth child
	String pathString = "P3;C5";
	Path path = null;
	try{
		path = new Path(pathString);
	}catch(IllegalPathStringException illegalpath){
		logError(illegalpath.getMessage());
	}
	
	// Assume that the imageAlbum() is already found
	return new GuiTestObject(ObjectFinder.locateTestObject(imageAlbum(), path));
}

  首先我們指定一個路徑字符串,它描述了從圖標到 Place Order 按鈕的路徑。然后我們使用 ObjectFinder 類來定位我們想要的目標測試對象。

  更好測試對象識別的建議

  我們已經看到了,怎樣以各種方法來找到一個測試對象。我們可以使用默認的方法來找到測試對象。我們還可以使用 find() 方法來找到匹配屬性/值的測試對象。而且我們可以定位帶有給定對象及路徑的測試對象。在本段中,我們將會討論怎樣選擇正確的方法,以及怎樣組織 Rational Functional Tester 對象的源代碼。

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97