|
Post by Tibabs on Jan 2, 2019 14:39:48 GMT
Hi,
10 years ago I've used another macro software (autohotkey) but yesterday I've discovered mmm that looks pretty good and easyer to use.
My purpose is to automate form feeding in a webpage. In order to do this, I have csv files containing data to populate the forms. I do not found how to read csv file, set values into variables or array of variables and feel the differents fields. Is there a limitation of variables ? I have around 100 data per lines ! I though that I could it thanks to the CONTAIN* comment as shown on the help files ... but it doesn't works.
*Something like that could be Ok ... but not !!! What's wrong ? I catch the %LINE% but not the variables ? 1 | FOR | EACH | LINE IN | C:\data.txt | DO 2 | IF | STRING VARIABLE | %LINE% | CONTAINS | _%integer1%_%string1%_ | MSGBOX %integer1% , %string1% 3 | FOR | NEXT
with a file data.txt like this ... of course it would be ";" separators instead of "_" separators _1_data1_ _2_data2_
_3_data3_
Could you give me the key for the solution. Thanks in advance.
Regards
|
|
|
Post by Johnc on Jan 2, 2019 23:19:24 GMT
With my limited knowledge in MMM, I am not sure it was designed to parse csv/txt files. To parse a csv file, I would use AWK/gawk to do so. With gawk, you can easily turn the csv file from: _1_data1_ _2_data2_ _3_data3_ into the following format: STRING1::data1 STRING2::data2 STRING3::data3 save this file into input.txt and then use the MMM INPUT FROM FILE ACTION to read the data into the corresponding variables. e.g. 1 | RUN ACTION | INPUT FROM FILE | VARIABLES::REFRESH::C:\Macro\RX\INPUT.txt see this link for more info: www.turnssoft.com/conditions.html#inputfromfile
|
|
|
Post by Tibabs on Jan 2, 2019 23:47:41 GMT
Damned, ;-)
I agree with the awk or something similar, but in fact the file for one test only sounds like this :
Line #1 => 1;Name1;NickName1;Address1;Phone1;Sport1;Color1; ..... (100 variables) Line #2 => 2;Name2;NickName2;Address2;Phone2;Sport2;Color2; ..... Line #3 => 3;Name3;NickName3;Address3;Phone3;Sport3;Color3; .....
and so on for 200 lines at least !!!!
My purpose is to automate tests, it's why I need to have 1 csv per test containing 200 lines (test#1 creating 200 lines, test#2 updating 200 lines, test#3 deleting 200 lines...) I can't imagine to have 200 differents files for only one test ! First level it's more complicated, second level you can't have a global view of your test !!
Another idea ?
|
|
|
Post by Steve on Jan 2, 2019 23:57:09 GMT
Hi, John is on the money. MMM nativity does not have functionality to split strings based on delimiters or other expression like AWK. Whilst it can read data in from a file to a variable it need strict formatting. I propose for this you are going to need to run some sort of script on the cvs file (Powershell or the like) to format the data into an 'input.txt' file reading for MMM to read in. Then add the data you require into variables: 1 | RUN ACTION | INPUT FROM FILE | VARIABLES::REFRESH::C:\Macro\RX\INPUT.txt see this link for more info: www.turnssoft.com/conditions.html#inputfromfile
|
|
|
Post by Tibabs on Jan 3, 2019 0:24:49 GMT
I concede ;-(
So, I will try to code a generic solution. Anyway even if I'm a newbie, I found it could be a good enhancement of the soft, cause MMM is a perfect prospect for test automatisation. On the other hand, I can understand it does'nt belongs to his DNA.
NB : If somebody have an allready experimented solution in DOS (without gawk that seems not to be a standard command) ... I'm OK to test it.
Regards.
|
|
|
Post by Johnc on Jan 3, 2019 1:52:15 GMT
Well u can still keep it simple and use the 1 big file format to maintain the global view. Just use an awk script to parse the big file and split it into 200 or more smaller MMM friendly data files for you automatically and store them under E:\docs. You don't even need to look at any output data file! Consider them temporary files! See: www.theunixschool.com/2012/06/awk-10-examples-to-split-file-into.htmlThen use MMM to load the 200+ files one by one and run tests as follows: 1 | FOR | EACH | FILE IN | E:\docs | DO 2 | RUN ACTION | INPUT FROM FILE | VARIABLES::NO_REFRESH::%FILE% 3 do your tests ... 99 | FOR | NEXT
|
|
|
Post by Tibabs on Jan 4, 2019 3:32:20 GMT
Hi,
I succeed into a gawk program but I'm limited with the number of String variables. How can I exceed the limit of 4 (%String4%) or create special variables (%NAME% ...).
NB : The awk program is BEGIN { FS=";" } { for (i=1; i<=NF; i++) printf "STRING%d::%s\n", i, $(i) }
Regards
|
|
|
Post by Johnc on Jan 4, 2019 11:09:51 GMT
|
|
tibabs
Junior Member
Posts: 13
|
Post by tibabs on Jan 5, 2019 12:59:15 GMT
Hi,
Here is the solution I have found. I hope it could help people.
Call: Csv2Parms.bat input.csv 1 4 output.txt
Csv2Parms.bat : gawk.exe -f csv2Var.awk -v min=%2 -v max=%3 %1 > %4
csv2Var.awk : BEGIN { FS=";" } { if (min == "" || min == 0) { min = 1 } if (max == "" || max == 0) { max = NF } for (i=min; i<=max; i++) printf "STRING%d::%s\n", (i-min+1), $(i) }
|
|
tibabs
Junior Member
Posts: 13
|
Post by tibabs on Jan 5, 2019 13:02:42 GMT
And after I loop something like that
27 | RUN ACTION | RUN VIA CMD /C | Csv2Parms.bat input.csv 1 4 output.txt 28 | RUN ACTION | INPUT FROM FILE | VARIABLES::NO_REFRESH::output.txt ... 27 | RUN ACTION | RUN VIA CMD /C | Csv2Parms.bat input.csv 5 9 output.txt 28 | RUN ACTION | INPUT FROM FILE | VARIABLES::NO_REFRESH::output.txt ... ans so on
|
|