消除识别测试对象过程中的二义性情形(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.ltesting.net