Home > Articles > Programming

This chapter is from the book

Using getTestData to Extract Data from a Text Field

The first example of using getTestData() is one that might not initially seem interesting. You can use getTestData() to retrieve data from text fields. To do so, pass getTestData() an argument of “text;” it returns the text as ITestDataText, which is the simplest subinterface in the ITestData family to work with. It’s simple because you need to know only one method to get the data into a usable string: getText(). As an example, look at these two text fields:

If you fire up and point the Inspector (see the “Viewing an Object’s Properties” section in this chapter) at each of these objects, you can see that in the case of the HTML text field, you need to get the value property. In the case of the Java Swing field, you need to get the text property. If you use getTestData(), in both cases, you pass an argument of text. This is useful if you want to create a generic method that retrieves text (expressed as a single string) from any type of test object. Listing 3.8 shows both a Java and VB.NET example of using getTestData().

Listing 3.8. Getting data from a text field

ITestDataText iData = (ITestDataText)textField().getTestData( "text" );
String value = iData.getText();
Dim iData as ItestDataText  = textField().getTestData( "text" )
dim value as String = iData.getText()

Notice that in Java, you must explicitly cast to ITestDataText.

  • + Share This
  • 🔖 Save To Your Account