gwen-interpreter / gwen-web

Web automation engine for Gwen
https://gweninterpreter.org
Apache License 2.0
54 stars 18 forks source link

Large SQL result to capture #32

Closed gtsihitas closed 7 years ago

gtsihitas commented 7 years ago

Hi

This is my last issue

I am capturing a large result from an SQL query that is thousands of characters long. It is a base64 code that I am attempting to capture in isolation so then I can apply the base64 decode DSL

If you could help this would be great...

George

bjuric commented 7 years ago

If the result is a base 64 encoded string, then it should decode using the dsl. If it is failing, do you have the error?

gtsihitas commented 7 years ago

There is no error...the script actually passes when I run

Given the xml content is defined by system process "ant.bat execute_sql_script_with_params -Dsqlfile=data/get_xml.sql -Dtarget.env=${target.env}" And I base64 decode the xml content as decoded xml

Although it will try to decode everything returned from the ant/sql script and not the encoded string in isolation. So the value captured in "decoded xml" is a slight mash up

This is a subset of the returned string "]Y\u0011Õ?Y\u0011\r\u000E\u0015\u0011ÎZÖ???\u0016?ÍL\u0014ÕÍ^?\u0012\u0012?VLÔ?\u0018??^?\u001"

bjuric commented 7 years ago

You will need to formulate a regex group capture to extract the encoded portion from the result like below..

And I capture the text in the xml content by regex "<your-regex>" as encoded

The encoded value will then be bound to the encoded attribute and you can then decode it..

And I base64 decode encoded as decoded

The decoded value will then be bound to the decoded attribute.

gtsihitas commented 7 years ago

Thanks Branko

And yes this is exactly what I'm trying to do. The trouble I'm having is to generate the regex which will extract the encoded portion of the message, that's the challenge. Once I figure that out then it's problem solved :)

bjuric commented 7 years ago

I'll add a new DSL for reading values from a file. If you change your script to output the encoded string to a file, you can then use that to read the value in.

gtsihitas commented 7 years ago

Hi Branko

I cannot write the output to a file as there are carriage returns in the string every 1024 chars, so I cannot feed it through. The encoded message in the DB can be thousands of characters long. When I read in the SQL result into a variable...it will contain carriage returns. This prevents me from writing to a file using

I execute system process "ant.bat create_dynamic_xml_file -Dtemplate.file="${my xml template file}" -Dtarget.file="${my xml file}" -Dxml.response="${the xml response}""

-Dxml.response="${the xml response}"" <<- will not accept a string with carriage returns

bjuric commented 7 years ago

Hi George,

I've added support for reading the contents of files into attributes in snapshot build: 1.10.1-1-g51c674d-SNAPSHOT available in repo: https://oss.sonatype.org/content/repositories/snapshots

Regarding outputting the large string value, you will need to find a way to extract the record from the DB and write it to a file. Once you get it out to a file, you can then use the following new DSL to read the contents of the file into an attribute named the encoded content:

And the encoded content is defined by file "path/to/file.txt"

Then you can decode it as follows:

And I base 64 decode the encoded content as the decoded content

The decoded string will then be available in the the decoded content attribute

Let me know how this goes.

gtsihitas commented 7 years ago

Thanks for that Branko

Yes first thing would be putting the output into a file

Will let you know when we get to this point and then I'll give your DSL a go

George

bjuric commented 7 years ago

We've added support for SQL Data Bindings to make accessing and working with data from databases much easier :)