How testpage and record works

1st Doubt:-

There is one field for which I set value like this

Testpagename.openedit();

Testpagename.fieldname.setvalue(10);

Testpagename.close();

Now in ui when I modify the value then it ask for confirmation but when I try using the code then it doesn’t ask the confirmation. I tried using the following code:-

Testpagename.openedit();

Testpagename.fieldname.setvalue(12);

Testpagename.close();

2nd Doubt:-

On ui if I assign same value then it gives me error but I can’t handle that error. My code is :-

Testpagename.openedit();

Testpagename.fieldname.setvalue(12);

Testpagename.close();

Recordname.init();

Recordname.validate(fieldname, 12);

Recordname.insert(true);

It gives an error but when u try to handle that error then it says no error found inside asserterror statement.