variables with Multi line content?

4,795 views
Skip to first unread message

Mark Irvine

unread,
Apr 15, 2010, 7:47:03 AM4/15/10
to robotframework-users
Hello,

I am trying to define a variable that contains a string on multiple lines:

For example, I want to define

===================== =================================
  Variable              Value         
===================== =================================
${VAR_NAME}           Some Text 
                      Text on Line 2
===================== =================================

==================  ===================  ============  ================
 Test Case          Action               Argument      Argument
==================  ===================  ============  ================
Create Temp File    Create File          file.txt      ${VAR_NAME}
==================  ===================  ============  ================

So that the content of the variable will be (including the line break):
Some Text 
Text on Line 2

At the moment I get:
Some Text Text on Line 2

Any ideas?

Thanks, 
Mark

Pekka Klärck

unread,
Apr 15, 2010, 8:08:35 AM4/15/10
to ma...@irvinesonline.org, robotframework-users
2010/4/15 Mark Irvine <ma...@irvinesonline.org>:

> I am trying to define a variable that contains a string on multiple lines

You need to use \n in your data like:

Some Text\nText on Line 2

Because possible whitespace after `\n` is ignored, you can also format
the text like this:

Some Text\n
Text on Line 2

Escaping and handling whitespace is explained pretty thoroughly in the
User Guide:
http://robotframework.googlecode.com/svn/tags/robotframework-2.1.3/doc/userguide/RobotFrameworkUserGuide.html#escaping

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Pekka Klärck

unread,
Apr 15, 2010, 10:02:29 AM4/15/10
to Mark Irvine, robotframework-users
2010/4/15 Mark Irvine <ma...@irvinesonline.org>:
>
> After trying this, I see:

> Some Textn Text on Line 2
>
> In another post I said I am having problems running ReST files directly, so
> I am having to convert these to html with rst2html.py first. When I do that,
> the result is (notice the '\n' is translated to 'n'):
> <tr><td>${VAR_NAME}</td>
> <td>Some Textn
> Text on Line 2</td>
> </tr>
>
> Reading the User guide, I see that RF always converts ReST file to html, so
> even if I can run the file directly I imagine it will still do the
> conversion the same way?
> So I just tried:
> ${VAR_NAME}           Some Text\\n
>                                 Text on Line 2
>
> And that seems to work.

Good catch. RF really converts reST files to HTML internally so you
need to escape reST syntax first. Since \ is an escape character
there, you need to have two of them in your reST source files.

Reply all
Reply to author
Forward
0 new messages