Base64 bit binary conversion

3,883 views
Skip to first unread message

Savita Patil

unread,
Sep 23, 2009, 7:43:23 AM9/23/09
to robotframework-users
Hi,

I am using Robot Framework for my project and want to convert one
string to Base64 bit binary format.
How do I do that?

Regards,
Savita

Janne Härkönen

unread,
Sep 23, 2009, 8:00:38 AM9/23/09
to savita.s...@gmail.com, robotframework-users
On Wed, Sep 23, 2009 at 2:43 PM, Savita Patil
<savita.s...@gmail.com> wrote:
>
> Hi,
>
> I am using Robot Framework for my project and want to convert one
> string to Base64 bit binary format.
> How do I do that?
>
Hello,

Probably the easiest way it to define your own test library [1], for
example in Python and use Python's base64 module [2].

This is a minimal test library to achieve the encoding:


import base64

def base64encode(input):
return bae64.encode(input)


The keyword may then be used like this:

| Test | ${encoded} = | Base 64 Encode | my input string... |

Hopefully this helps and do no hesitate to ask for further clarification.

[1] http://robotframework.googlecode.com/svn/tags/robotframework-2.1.1/doc/userguide/RobotFrameworkUserGuide.html#creating-test-libraries
[2] http://docs.python.org/library/base64.html


best regards,
__janne

Tset Noitamotua

unread,
Jun 22, 2016, 10:59:07 AM6/22/16
to robotframework-users, savita.s...@gmail.com
I want to revive this old post cause I have an issue related to it.

Trying to base64 encode a binary file while getting the error `Variable '$g' not found.` The error occurs only if byte string contains a '$' sing. My robot code looks something like this:
${binary} | Get Binary File | test.jpg
${file}= | Evaluate | base64.b64encode('${binary}') | modules=base64

What can I do to avoid this error?

The robot log:



Cheers
Tset

Kevin O.

unread,
Jun 22, 2016, 11:44:25 AM6/22/16
to robotframework-users, savita.s...@gmail.com
If you are using RF >= 2.9, you can use the new syntax for evaluating. This will cause the value of the RF variable to be used directly and avoid any issues with data inside a string literal.
    ${file}= | Evaluate | base64.b64encode($binary) | modules=base64

Tset Noitamotua

unread,
Jun 23, 2016, 2:12:28 AM6/23/16
to robotframework-users, savita.s...@gmail.com
Works!!!!!     Thanks a lot, Kevin!

Haha, I skimmed by you mentioned section before but didn´t noticed the slight difference of the new syntax for evaluation.

For everybody who might run into the same issue, in short: leave away the quotes and the curly braces around your variable!

OLD syntax         NEW syntax

("${binary}")         ($binary)

NOTE: this applies to keywords like `Evaluate`, `Should Be True` and `Run Keyword If`
For details check out section "Evaluating expressions" of the BuildIn Library documentation [1]



Cheers
Tset

Pekka Klärck

unread,
Jun 23, 2016, 4:38:16 AM6/23/16
to ombre42, robotframework-users, Savita Patil
2016-06-22 18:44 GMT+03:00 Kevin O. <korm...@gmail.com>:
>
> If you are using RF >= 2.9, you can use the new syntax for evaluating. This will cause the value of the RF variable to be used directly and avoid any issues with data inside a string literal.
> ${file}= | Evaluate | base64.b64encode($binary) | modules=base64
>
> http://robotframework.org/robotframework/latest/libraries/BuiltIn.html - see Evaluating expressions in the intro

The above works and the new evaluation syntax is pretty handy in
general. Using a dedicated keyword would obviously be a lot clearer,
especially if this functionality is needed more often. Should we
consider adding `Base64 Encode` and `Base64 Decode` into Robot's
standard libraries? Would there be enough similar keywords for a
dedicated library or could the simply be added to the existing String
library?

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
Reply all
Reply to author
Forward
0 new messages