Dealing with character limit on a field
Question ID: 107350
0
0

I’m testing an app that has a character length limit. We get our test data from another group and sometimes the data values for our input table go over the character limits and can cause issues since the app doesn’t flag the field until later on in the test. Is there a good way to handle this in my script?

Marked as spam
Posted by (Questions: 227, Answers: 22)
Asked on January 19, 2017 3:47 pm
92 views
Answers (2)
0
Private answer

You could use the Left function in VBScript to limit the characters. You could do something like this:

input_value = DataTable(dtGlobalSheet, ''Input_Item1'')

'Check to see if the length of the value exceeds field limit
'In this example, we'll say the field length is 10 characters

str_length=Len(input_value)
If str_length>10 Then
'It's longer than 10, so we'll shorten it
input_value = Left(input_value, 10)
MsgBox input_value
End If

'You would then continue with the input on the field as normal:

Browser(''Internet Explorer'').Page(''Inventory'').WebEdit(''Item Name:'').Set input_value
....etc.

Marked as spam
Posted by (Questions: 2, Answers: 477)
Answered on January 19, 2017 3:49 pm
0
Private answer

Actually, you could probably also just shorten the code and not use the If/Then statement if you want and use the Left command to reformat the string:

input_value = DataTable(dtGlobalSheet, ''Input_Item1'')

input_value = Left(input_value,10)

Using the If/Then statement won't hurt the script if you wanted to further enhance it maybe to make a note that the input length was too long through a Reporter.ReportEvent statement, but you may prefer less code and the above example would also suffice.

Marked as spam
Posted by (Questions: 2, Answers: 477)
Answered on January 19, 2017 3:53 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top