Want to verify character count of textbox - selenium

I am trying to validate the character count of a text field using TestNG, & I am not getting how to do so.
Here's my code what I have done, where upper limit is 50:-
I know I am doing something wrong but unable to understand what.

You are inserting a text of length 51. If you wanted to insert a text of length 50, change the <= to <. Then your first if i.e if (n==50) would pass.
However, if what you are trying to validate whether your textfield can autotruncate a higher length string to 50, then, it might be that it is not behaving correctly since the char length is obviously not 50 so either it is truncating more or it is not truncating less, in which case it is a valid failure and should be taken up as a bug to the dev owner.

Related

RAND() not consistently generating the right length value

I've got the following code in place with the idea being that I need a 30 character random number generated each time the stored procedure is called and the odd thing is that in most cases it works as intended but in other seemingly random cases it will only generate a 28 character random number.
'\\xxx-servername\folder\'+
CAST(CAST((RAND()*1000000000000000000000000000000) as decimal(30))as varchar(30)) +
RAM.AccountNumber+HRMRN.PrefixMedicalRecordNumber+'ESTIMATE N00001'+
REPLACE(CONVERT(VARCHAR(12),ISNULL(HRM.Birthdate,HRM.BirthdateComputed),111),'/','')+HRM.Sex+
REPLACE(CONVERT(VARCHAR(12),GetDate(),111),'/','')+LEFT(REPLACE(CONVERT(VARCHAR(12),GetDate(),108),':',''),4)+'.PDF' as [CPFileName]
Hope maybe someone can offer some advice because I'm at a loss...
I suspect that your system is automatically removing leading zeros. You can either re-insert those zeros yourself, or else construct your number using something like:
number <- ""
number.append(randomDigit(1,9))
repeat 29 times
number.append(randomDigit(0,9))
end repeat
That guarantees that you do not get a leading zero.

Is format ####0.000000 different to 0.000000?

I am working on some legacy code at the moment and have come across the following:
FooString = String.Format("{0:####0.000000}", FooDouble)
My question is, is the format string here, ####0.000000 any different from simply 0.000000?
I'm trying to generalize the return type of the function that sets FooDouble and so checking to make sure I don't break existing functionality hence trying to work out what the # add to it here.
I've run a couple tests in a toy program and couldn't see how the result was any different but maybe there's something I'm missing?
From MSDN
The "#" custom format specifier serves as a digit-placeholder symbol.
If the value that is being formatted has a digit in the position where
the "#" symbol appears in the format string, that digit is copied to
the result string. Otherwise, nothing is stored in that position in
the result string.
Note that this specifier never displays a zero that
is not a significant digit, even if zero is the only digit in the
string. It will display zero only if it is a significant digit in the
number that is being displayed.
Because you use one 0 before decimal separator 0.0 - both formats should return same result.

Negative dollars and iTextSharp

I am trying to assign a form field in a PDF through iTextSharp that has a negative dollar amount. The value is a simple string that starts with '-$'. Every time I add the value to the form using SetField, anything after the negative sing is lost. Positive dollar amounts are fine, only negative values are lost.
I am adding the value as such:
form.SetField(fieldName, fieldValue);
form is of type AcroFields, fieldName and fieldValue are both strings. I have traced down to the point where the string is being passed to SetFields, and its right there. I have also tried replacing '$' with the Unicode value to no avail. Am I supposed to escape the dollar sign? And if so, does anyone know what the escape character is?
I fixed the issue though I do not totally understand the cause. The field was defined as a multi-line text box even though it was being used as a single line. I unchecked the option for the box to be multi-line and the issue went away.

Handling measurement units in NSTextField

I am creating a test application to calculate the area of a rectangle.This application uses NSTextField control to get the length and breadth of rectangle.
The user is expected to enter a string value which will include units of length as well (Sample Values 2.5 inches, 1500 mm).
I want NSTextField to convert the value in centimeters (cm) automatically so that it displays the converted value (in cm) as soon as the text field looses focus.
For Eg:
User Enters length as: 1500 mm
As soon as user goes to next text field to enter breadth, the length field displays
Displayed Value: 150 cm
How can we achieve this?
I think you want to use the delegate method, controlTextDidEndEditing:, which is sent to your text field's delegate when the editing is finished. Once you get the string from the field editor, you'll need to parse it somehow to find the units (how you parse it depends on what all you need to find). If you have a small number of things you're hunting for, like cm, mm, m, then you could probably just use rangeOfString: and test for 0 length to find out what units were entered. BTW, you should do your math correctly too -- 1500mm = 150 cm
I would consider a different approach, using a UIPicker to display the available units, and have them enter the number separately.
Otherwise, you'll have to do all this parsing. Don't see the point of parsing. Plus, if they make a mistake spelling the units, or use different ways of indicating it, then you would have to account for that as well. Depends on your application, but if the user has to type the units out anyway, it might be more convenient for them to use a UIPicker.

inserting number into oracle sql - using jython

I have this insert command where iam trying to insert a number to be taken from loop
i=0
for line in column:
myStmt.executeQuery("INSERT INTO REVERSE_COL
( TABLE_NAME,COL_NAME,POS) values
(,'test','"+column[i]+"','"+i+"'")
i=i+1
POS IS NUMBER DATATYPE
but it works if i hard code as 1
i=0
for line in column:
myStmt.executeQuery("INSERT INTO REVERSE_COL
( TABLE_NAME,COL_NAME,POS) values
(,'test','"+column[i]+"',1")
I have tried only i , +i+ and other method but its not working any suggestion how to solve this .
Thanks everyone .
I have no jython experience, but I will still try to offer my personal approach and advice. Take from it what you will.
The first thing that I would look into, and perhaps this is something someone else knows offhand, is the way that a number is concatenated to the string. I'm speaking from a C++ background here, but a number i may well be converted to the ASCII character representing that value, and not necessarily the character that you intend.
For example, if i is 9, it may be placing a TAB into the string and not the number 9, which would be an ASCII value 57.
Again, I'm not telling you this IS the answer...but it's the first thing that pops into my mind. Good luck!