Forum Discussion
Hi,
a) I am not sure that FormData is "JavaScript object" but not something provided by the browser (https://developer.mozilla.org/en-US/docs/Web/API/FormData);
b) I am not sure that
var requestBody = new FormData(Sys.Desktop.Picture());
will work. According to the samples, you should first save .Desktop.Picture() to the file and use something like
formData.append('image', <FullFileName>);
then;
c) If you don't need to use different files every time (and I am pretty sure that you don't), you may capture request that sends some small file using Fiddler or the tool like it and use captured data for the form content.
- TestKeks7 years agoOccasional Contributor
Hi AlexKaras,
regarding a) and b) you may be right in principle.
But either way, since the FormData object is not supported by TestComplete, the method formData.append() cannot work either. Because even if I try to initiate the FormData object empty ...
var requestBody = new FormData();
... I get the same error.
I did not quite understand what you mean by c). Maybe I should have mentioned that I need the routine for some web tests that have to run on CrossBrowserTesting devices. I wanted to avoid opening another browser tab for such actions in parallel to the tested web application. And of course, I can't access desktop applications on these devices at all - if that's necessary for such additional tools. Otherwise could you please outline the use of Fiddler in this context a little closer?
Thank you and best regards
- AlexKaras7 years agoChampion Level 3
Hi,
> since the FormData object is not supported by TestComplete
Depending on the scripting language of your test project, you may look for some third-party library/component that will provide such functionality and use it. However, there may be problems with deploying required components to the CrossBrowserTesting environment.
> could you please outline the use of Fiddler in this context a little closer?
The suggestion is based on the assumption that you don't need to send some specific file in your test but it is acceptable if the same file is sent every time.
If this assumption is correct, then you may use Fiddler or any other request-capturing tool to capture the request that sends some small (for performance considerations) file. The captured request will provide you with the already properly encoded body part. So you may store it in some file or as a constant string in test code and use in the test.
- TestKeks7 years agoOccasional Contributor
Hi,
> Depending on the scripting language of your test project, you may look for some third-party library/component that will provide such functionality and use it. However, there may be problems with deploying required components to the CrossBrowserTesting environment.
That's exactly my problem.
Fiddler will then also be excluded as an option.
That's why, in the meantime, I have taken a closer look at the syntax required for the multipart/form-data content type in order to assemble the string for myself, that has to be transmitted.
But therefore I also need an approach to read the byte code of the binary graphic file and append it to my output variable. I assumed that the second code example at https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqbinaryfile/index.html could help me with this:
function ReadByteFromFile() { var Path = "C:\\MyFiles\\Desktop.jpg"; // Opens the specified file for reading var myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead); Log.Message("File by bytes:"); // Reads bytes from the file and posts them to the test log while(! myFile.IsEndOfFile()) { s = myFile.ReadByte(); Log.Message(s); }
// Closes the file
myFile.Close();
}Unfortunately, however, this does not result in the byte code but in a purely numerical chain (I suspect ASCII code?).
But how can I access the unaltered byte code, which I need? I do not find any further details on this in the TestComplete documentation.
Many thanks and best regards
Related Content
Recent Discussions
- 19 minutes ago
- 6 hours ago