1

I have an application who has text fields (not select, not checkbox or other types) where an user can enter some value, like this:

*ISBN* and *E-Mail* are the label of each input

ISBN and E-Mail are the label of each input.

Now I have to automatically test these inputs according to their label. The question is: how to recognize that, for example, the first input requires an ISBN code? I programmed something like this:

  1. turn the label value to lowercase
  2. check if the label value contains isbn
  3. if so set the field value to a random ISBN code (i.e.: 1234567890), else set it to a random value (default)

For the email field:

  1. turn the label value to lowercase
  2. check if the label value contains e-mail or email or mail
  3. if so set the field value to a random email (i.e.: abcd@abcd.com), else set it to a random value (default)

And so on for each text field I encounter.

Is that reliable? How can I improve the "recognizing part"? I know only the label value and the field value (what is already written in the field by default) for each text input.

HBv6
  • 113
  • 4
  • Is this an HTML form or is it Swing? – Jaydee Jun 19 '12 at 15:31
  • It's an Android app. The image is just an example to explain better what I have to do. – HBv6 Jun 19 '12 at 15:32
  • No. Just no. Don't do it. I once spent weeks undoing exactly this (big project, multi-language, 100+ dialogs). Some fields even stored their status in their background colour! – RedSonja Dec 19 '17 at 08:26

2 Answers2

3

As for the correctness of your feature, it simply is not. In fact, it cannot be.

Trivial counter-example: Someone creates the label "Do not enter E-mail or ISBN here, but your name:"

The problem is that you should not have to guess which textfield is for which purpose, but the text-field itself should contain this information for various reasons.

For example, if you have a textfield for ISBNs, you do not want a keypress for a non-digit-character to even appear (with the possible exception of the - and X characters maybe).

The main problem is how to add this semantic information to the text-fields such that you can access it in the test framework. This of course depends on the specific implementation tools being used. Examples include:

  • HTML: assign a class/id/name-attribute to the input tag (look f.ex. at the source code of the google login page. This is used as the basis of how your browser knows in which text field it should auto-complete your e-mail address)
  • GUI API: If you create an instance of some TextField widget, you can create subclasses for the different semantical purposes, like an EMailTextField, and instantiate that. By reflecting on the dynamic type of the textfields, your tests can then determine what kind of textfield it is, and additionally, the implementation can easily realize semantic-dependant behaviors (like disallowing certain characters to be entered, etc.)
Frank
  • 14,407
  • 3
  • 41
  • 66
0

I'm guessing that you've given the text fields useful names (other than just textfield1 or whatever)

NOTE: I'm coming at this from a winforms point of view. Since you didn't say what framework and/or language you're using to develop this, I'm going to assume that you can name the textfields. I also note that you haven't said which framework you are using to test with, so most answers will be vague and generic

How about just adding none values into the text fields?

If it where me, I'd have named the textfields tfISBN and tfEMail, and would just inject known values directly into their text value.

For instance

tfISBN.text = "1157061346" //KnR C - ISBN10
tfEmail.text = "user@domain.com"
//a different set of data
tfISNB.text = "978-0321751041" //Art of Computer Programming - ISBN13
tfEMail = "donald.knuth@doesnt-have-email.goaway"

Or, of course, since you're testing, you could also check to see if you can populate these text fields with invalid data. Just move down the form/UI (simulate tab stops) and place text into each field and see if the back-end code can handle erroneous values.

Jamie Taylor
  • 480
  • 1
  • 4
  • 12
  • Thanks, I already know how to set the fields value... I just want to know if my "procedure" to recognize the text input is correct and how to improve its reliability. By the way, I'm using JAVA and that's an Android app (added to the tags, thanks). – HBv6 Jun 19 '12 at 15:33
  • If you know the field names, then you can just pull each one out to a string and perform whatever test it is directly on the string value. – Jamie Taylor Jun 19 '12 at 16:56