SilkTest's replacement for the Exists() method 软件测试
Posted by Stan Taylor on March 31, 2010
I've recently started a new SilkTest project testing a web application, using SilkTest's new open agent and the 4Test scripting language. This post covers an aspect of what I've learned.
In the SilkTest 'classic' agent, you used the 'Exists()' method to test whether an object exists in the application under test, e.g.,:
if (Page.Object1.Object2.Object3.Exists())
// do something...
With the open agent's dynamic object recognition, the Find() method is what you need to use, but it took me some research to figure out how to do an if statement with the find() method. Here's a test:
if (Desktop.Find("//BrowserApplication//BrowserWindow//INPUT[@id='sysname']",{5, false}) != NULL)
// do something
You'll notice that I added an optional argument: {5,null}. These two values constitute a FINDOPTIONS data type record. The first one is the timeout. The second value is the important one for our purposes: it "determines whether the Find method throws an E_WINDOW_NOT_FOUND exception if no object is found or NULL is returned if no object is found. "
So, you set that value to FALSE and then test to see whether or not the Find() method returns NULL. If not null, the object exists.
--------------------------------------------------------------------------------
Comments
The following can be tried:
[-] window BrowserChild AUTPage1
[ ] tag "Jingle Bells"
[ ] locator "//BrowserApplication//BrowserWindow[@caption='Jingle Bells']"
[ ]
[-] DomElement HomePageImage
[ ] locator "//IMG[@title='You are on Home page.']"
[ ]
[ ]
[-] void TestObjExists ()
[ ]
[-] if AUTPage1.HomePageImage.Exists()
[ ] Print ("You got lucky & are on Home page.")
[-] else
[ ] LogWarning ("Sorry, you missed the bus.")
Posted by: STU | April 5, 2010 02:03 PM
文章来源于领测软件测试网 https://www.ltesting.net/