0

I am trying to find a way to get Robot Framework to grab text between known strings in log files. I'd like to use this to grab variables (like IP addresses) to pass them on through my Testplans.

Example Logs: (Note the varied timestamps, I have no control over these and devs seem to like changing them for some reason.)

[2014-10-11T22:34:00.11] TCPConnect - Connecting to 192.168.21.139 on port 8030.

[2014-10-11 22:34:00.11] TCPConnect - Connecting to devbox01 on port 9718.

[2014-10-11] [22:34:00.11] TCPConnect - Connecting to devbox01.here.local.net on port 8712.

If I use the keyword 'Get Lines Matching Regexp' and the regex:

(?<=.*Connecting to )(.*?)(?= on port .*)

I get:

error: look-behind requires fixed-width pattern

I would expect to get the IP address, hostname and anything else between 'Connecting to ' and ' on port', but this is not the case. I understand this has to to with python 2.6 and apparently 2.7 will include this functionality, however; I am hoping to sort this out within current releases.

Anyone have any ideas?

Community
  • 1
  • 1
Colin
  • 93
  • 1
  • 3
  • 11

1 Answers1

1

I don't think you need to use look-behind here. This should match the given lines:

| | ${lines} | Get lines matching regexp | ${data} | .*Connecting to .* on port.*

Note that this returns whole lines that match -- it has nothing to do with the pattern, it's just how that keyword works. Even if you add capturing or non-capturing groups, you get the whole line that matched. If you want to get just the IP addresses you'll have to do some additional parsing of the lines that are returned.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Yes, there are no keywords in the Builtin or String libraries that do what's needed. Either `Split String` or a python user keyword would be the best options. – Paul Hicks Nov 05 '14 at 23:49