QTP: How do I match (or parametrize) line breaks in multiline edit controls?

烂漫一生 提交于 2019-12-24 10:37:35

问题


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:

  1. 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.
  2. It does not matter if the value is in the datatable (being a datatable parameter for the checkpoint) or inserted into the checkpoint directly.
  3. Support says this is because the third-party Formula1 component used to implement the data table editor in QTP cannot use newline characters.
  4. (3) cannot be true because then (2) would not be true.
  5. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!