Ask a Question

RESTful API testing requires base64 parm - btoa() is unknown function

eflyerman
Occasional Contributor

RESTful API testing requires base64 parm - btoa() is unknown function

How can I encode a binary file to base64 for the API parm?

 

I found https://support.smartbear.com/viewarticle/42195/ but it requires dotnet and the desktop license for TC.  We are only using the web testing so the example fails.

 

Is there anyway to access the native javascript window.btoa() function within javascript test scripts?

 

Eddie

3 REPLIES 3
AlexKaras
Champion Level 3

Hi Eddie,

 

Assuming that your project is either JScript- or JavaScript-based, this link might help: https://scotch.io/tutorials/how-to-encode-and-decode-strings-with-base64-in-javascript

 

Also https://support.smartbear.com/testcomplete/docs/app-testing/web/general/common-tasks/javascript.html might be relevant as well.

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
eflyerman
Occasional Contributor

I resolved it by doing something similar but different to the example on scotch.io.  VERY slow.

 

The TC project is running pure javascript.  We're not even opening a browser, just httprequests to exercise the API.  There is no page object to use as in the documentation link you provided.

 

We may have to open up a browser just to have  a page object to use to improve the speed. 

 

Thanks,

Hi,

 

> Is there anyway to access the native javascript window.btoa() function

As per w3schools (https://www.w3schools.com/jsref/obj_window.asp), window is not a native JavaScript object, but an object that "represents an open window in a browser".

Also note that as per https://www.w3schools.com/jsref/met_win_btoa.asp, btoa() is not supported in IE browser.

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
cancel
Showing results for 
Search instead for 
Did you mean: