问题
Consider this script:
SystemUtil.Run "notepad.exe"
With Window("Notepad")
.WinEditor("Edit").Type "A"
.WinEditor("Edit").Type micReturn
.WinEditor("Edit").Type "B"
.WinEditor("Edit").Check CheckPoint("Edit")
End With
The "Edit" checkpoint simply checks if the "Edit" WinEdit contains "A", CR, LF, "B". (This is exactly what the editor contains, you can verify by looking at GetROProperty ("Text")
, it returns a string of length 4 with ASCII 65, 13, 10, 66, which is exactly what I'd expect.) I can easily create such a checkpoint after recording the script and inserting the checkpoint via active screen click-o-magic.
But now suppose I want to parametrize the expected string.
Since I cannot enter line breaks in a data table cell, I would convert the expected string to a regular expression, for example "A\cM\cJB"
for above example. No matter if I put that regex into a data table or not, it does not match. Why?
Or is there any other way to parametrize an expected string containing a line break?
Also see Question QTP: How do I get the "complex value" edit control in the checkpoint property edit dialog?.
回答1:
Facts:
- Newline characters in the
checkpoint's expected value are not
supported. While this seems
obvious, in fact all regex tokens
for newline, including
\cM
and\cJ
, are not handled in the expected way. - It does not matter if the value is in the datatable (being a datatable parameter for the checkpoint) or inserted into the checkpoint directly.
- Support says this is because the third-party Formula1 component used to implement the data table editor in QTP cannot use newline characters.
- (3) cannot be true because then (2) would not be true.
Support suggests to put a formula into the data table which delivers the wanted string, for example '
="A"+Chr(13)+Chr(10)+Chr("B")
'.I think that is quite delighting.
So once again, i answered my own question, but not to earn the respect points (will I earn any?), but to share the "solution", or workaround, with everybody.
The QTP version used was 10.00.
来源:https://stackoverflow.com/questions/5554287/qtp-how-do-i-match-or-parametrize-line-breaks-in-multiline-edit-controls