Properties cannot only be read using getProperty(), but they can be changed using setProperty():
public void setProperty( String propertyName, Object propertyValue )
Although you most likely will not use setProperty() nearly as often as you use getProperty(), it is a method worth knowing about. SetProperty() takes two arguments: the property to change and the value to change the property to.
The reference example is one that involves setting data field values in test objects (for example, text fields). In general, you should use inputKeys() or inputChars() to enter data into the SUT. With some cases, however, this becomes challenging. One such context is internationalization testing. inputKeys() and inputChars() can enter characters only in the current keyboard’s character set. If the current keyboard is set to English, for example, RFT throws a StringNotInCodePageException if your script attempts to enter any nonEnglish characters.
One potentially viable solution is to use setProperty() instead of inputKeys() to set the field value. The first step is to determine the property you need to set. Manually set a value, and then examine the test object using either the Inspector or the Verification Point and Action Wizard. Search for a property whose value is the data value you entered. If you enter a search term of Pasta Norma in a Google search field and examine the field with the Inspector, you see two properties whose values are Pasta Norma: value and .value. This is not uncommon: It’s possible that the data value is represented by more than one property. It’s a good idea to note all these property names because some might be read-only. If you try to set a property value that’s read-only, Rational Functional Tester throws an exception.
If you had a datapool with different search strings in different character sets, you can manipulate the scripts to perform multiple searches, as shown below.
Using SetProperty() to set data in a test object
Java
while (!dpDone()) {
text_q().setProperty(".value", dpString("SearchItem"));
// Do what we need to do
dpNext();
}
VB.NET
Do until(dpDone())
text_q.SetProperty(".value", dpString("SearchItem"))
' Do what we need to do
dpNext()
loop
Why Is InputKeys() Preferred?
To illustrate why inputKeys() is the preferred method to enter data into objects, test what happens if you set the quantity of CDs to buy in the Classics sample application:
quantityText().setProperty("Text", "4");
You see something odd happen (or, not happen in this case): The total amount is not updated to reflect the new value. The reason for this is that the total amount is updated when the inputKeys event is fired. setProperty() does not cause this event to fire and is therefore not a possible technique to set the quantity field.
Post a Comment