Append to File a text of 10 lines

2,613 views
Skip to first unread message

tim jim

unread,
Jun 27, 2016, 1:51:41 PM6/27/16
to robotframework-users
Hi

I am new to robot framework. I am trying to append a 10 lines of text to a file.

Here is my code


${values} =        Get Elements Texts    ${root}        xpath=example[0]
    ${context}    Set Variable    The Child Element Text is:
   
   
      ${cnt}    set variable    ${0}
    :FOR    ${val}    IN   @{values}
    \    log    '${val}'
    \    ${cnt} =    Evaluate     ${cnt} - 1
    \    Append To File        ${CURDIR}${/}Elements_text.txt     ${context}

This is appending only 1 line. I want to have the same content as much as i want.

Please can anyone help me.

Tx
Tim

Hélio Guilherme

unread,
Jun 27, 2016, 4:11:58 PM6/27/16
to robotframework-users
You are appending ${context} ("The Child Element Text is:"). Maybe you want to append ${val}.
Your loop does not consider ${cnt}, only the ${val] from @{values}. Your Get Elements Texts is being assigned to ${values} (is this really a list of values?).

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

tim jim

unread,
Jun 28, 2016, 12:05:29 AM6/28/16
to robotframework-users
Actullay, @{vaules} is holding a one full list.

But I want it to be seperated by \n . Dont know how to seperate.

@{values} holds =  [u"['\\ntext\\n  \\n    \\n  \\n  \\n    more text\\n\\tmore text1\\n\\tmore text2\\n\\t\\n\\tC://aut//abc//\\n\\t\\n       tes...@oracle.com\\n       tea...@oracle.com\\n      test...@oracle.com\\n       test...@oracle.com\\n    \\n   * * 1 * * \\n  \\t\\n\\t\\tC:\\\\work\\\\qa-abc\\n\\t\\toracle_email_sprs_\\\\d{8}\\\\.(dat|tok)\\n   \\n\\t   \\n\\t\\ttestloi\\n\\t\\tnnnsss\\n\\t\\n\\t\\tacxdig\\n\\t\\t\\n\\t\\t\\n\\t\\n  \\n   \\n  \\n    \\n      Text with bold and italics\\n    \\n  \\n  '][1]"]

I want the list to be split like

text
more text
more text1
more text2
C://aut//abc//
tes...@oracle.com
tes...@oracle.com
test...@oracle.com
test...@oracle.com
 * * 1 * *
et.......

I also want to eliminate \n and \t.

how much ever i try i am seeing all elements text in one string.

@{values} =        Get Elements Texts    ${root}        xpath=destination[0]


Can you please help me how to split and store in a list.

Thanks a lot
Tim.


    

On Monday, June 27, 2016 at 1:11:58 PM UTC-7, Hélio Guilherme wrote:
You are appending ${context} ("The Child Element Text is:"). Maybe you want to append ${val}.
Your loop does not consider ${cnt}, only the ${val] from @{values}. Your Get Elements Texts is being assigned to ${values} (is this really a list of values?).
On Mon, Jun 27, 2016 at 6:51 PM, tim jim <theta...@gmail.com> wrote:
Hi

I am new to robot framework. I am trying to append a 10 lines of text to a file.

Here is my code


${values} =        Get Elements Texts    ${root}        xpath=example[0]
    ${context}    Set Variable    The Child Element Text is:
   
   
      ${cnt}    set variable    ${0}
    :FOR    ${val}    IN   @{values}
    \    log    '${val}'
    \    ${cnt} =    Evaluate     ${cnt} - 1
    \    Append To File        ${CURDIR}${/}Elements_text.txt     ${context}

This is appending only 1 line. I want to have the same content as much as i want.

Please can anyone help me.

Tx
Tim

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

J Wipf

unread,
Jun 28, 2016, 6:31:15 AM6/28/16
to robotframe...@googlegroups.com
I would look into [1] and [2] from the string library.You could use remove string with \\t (and other unneeded portions) to remove it from the whole list Then take each element of the list and split based on \\n and append the split results onto a resultant list. You would need a check to remove empty elements after the split.

:FOR ${item} IN @{list}
\ Remove String #get rid of \\t

:FOR ${item} IN @{list}
\ @{result}= Split String \\n
\ appender kyeword @{result} @{new list}

appender keyword
 
:FOR ${item} IN @{result}
 
\ if ${item}!=${EMPTY} append to ${new list}


tim jim

unread,
Jun 28, 2016, 12:18:08 PM6/28/16
to robotframework-users
HI

I tried the following


${stir} =     Remove String Using Regexp     @{values}      \\n
   
    Log        ${stir}
   
    ${stir1} =     Remove String Using Regexp     ${stir}      \\t
   
    Log        ${stir1}

    @{words} =     Split String     ${stir1}     \\t${SPACE}    
   
   
    Log        ${words}
   
   
   
    :FOR    ${val}    IN   @{words}
    \    log    '${val}'
    \    Append To File        ${CURDIR}${/}split_1.txt    ${val}     \n


The result is as below

20160628 09:07:55.359 :  INFO : ${stir} = text              more text    more text1    more text2        C://aut//abc//           tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       * * 1 * *               C:\EDT\edt...
20160628 09:07:55.361 :  INFO : text              more text    more text1    more text2        C://aut//abc//           tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       * * 1 * *               C://aut//abc//        orcl_email_sprs_\d{8}\.(dat|tok)                  testloi        nnnsss            orcledig                                     Text with bold and italics       
20160628 09:07:55.362 :  INFO : ${stir1} = text              more textmore text1more text2C://aut//abc//       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       * * 1 * *   C://aut//abc//acx...
20160628 09:07:55.364 :  INFO : text              more textmore text1more text2C://aut//abc//       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       * * 1 * *   C://aut//abc//qa-ora_email_sprs_\d{8}\.(dat|tok)      testloinnnsssorcl                 Text with bold and italics       
20160628 09:07:55.365 :  INFO : @{words} = [ text              more textmore text1more text2C://aut//abc//       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       * * 1 * *   C://aut//abc//a...
20160628 09:07:55.367 :  INFO : [u'text              more textmore text1more text2C://aut//abc//       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       * * 1 * *   C:\\EDT\\edt-pullacxne_email_sprs_\\d{8}\\.(dat|tok)      testloinnnsssorcl                 Text with bold and italics        ']
20160628 09:07:55.369 :  INFO : 'text              more textmore text1more text2C://aut//abc//       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       tes...@oracle.com       * * 1 * *   C://aut//abc//qa-ora_email_sprs_\d{8}\.(dat|tok)      testloinnnsssorcl                 Text with bold and italics        '
20160628 09:07:55.371 :  FAIL :
LookupError: unknown encoding:


Please can anyone give a full code for my testcase.

Basically I am not able to split the whole string into a list.

Tx,
Tim
Reply all
Reply to author
Forward
0 new messages