SPONSORS:






User Tag List

Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    Sep 1999
    Location
    Austin, Texas
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reading and Writing CSV files

    I would like to store test data in CSV files,
    so that they can be generated by other programs and edited in excell. I am cobbling together some silktest code to do this, but was wondering whether anyone already has code to do this.

    I am familiar with FileReadValue and FileWriteValue. They are useful for storing data in silktest-specific formats, but i need something more general.

    I looked through the download library here at QA Forums (which is quite handy), but did not notice anything of this sort. Did i miss something?

    Bret
    Bret Pettichord
    Book - www.testinglessons.com
    Hotlist - www.testinghotlist.com
    Consulting - www.pettichord.com

  2. #2
    Senior Member
    Join Date
    Jun 2000
    Location
    Chicago, IL USA
    Posts
    383
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Reading and Writing CSV files

    I think that you want to use FileReadLine()to read your data into a string, and then use GetField() to extract the fields from the CSV format.
    Then write with FileWriteLine().


    [This message has been edited by RobKapteyn (edited 10-12-2000).]
    Rob Kapteyn, CSTE
    RobKapteyn@gmail.com

  3. #3
    Member
    Join Date
    Dec 1999
    Location
    Seattle, WA
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Reading and Writing CSV files

    yup, reading the CSV directly by opening a handle to file then readline then getfield works great, except that a true CSV will also include quotes for items that contain the comma (and getfield will break) -- if your data is relatively straightforward this is not a worry.

    the other option here is that there is an ODBC driver for CSV, Excel directly, and also Access, and SilkTest now includes dbTester as part of the std pkg so you can open handle to the named data source and fetch it with SQL queries.

    finally, as an alt to option 1, if you have data with commas, etc., you could just use a more solid delmitter, e.g. the vertical bar or tilde.

    ------------------
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>It doesn't matter if I go to heaven or to hell, I have friends in both places.<HR></BLOCKQUOTE>
    <BLOCKQUOTE]<font size=1 face=Verdana, Arial, Helvetica]quote:</font]<HR]It doesn't matter if I go to heaven or to hell, I have friends in both places.<HR]</BLOCKQUOTE]

  4. #4
    Member
    Join Date
    Sep 1999
    Location
    Austin, Texas
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Reading and Writing CSV files

    Thanks Rob and Matt.

    I wrote up some code that works with simple CSV's. But i need it to work with embedded commas now, and it isn't smart enough for that. I think i will look into the ODBC idea.
    Bret Pettichord
    Book - www.testinglessons.com
    Hotlist - www.testinghotlist.com
    Consulting - www.pettichord.com

  5. #5
    Senior Member
    Join Date
    Sep 1999
    Location
    San Jose,CA,USA
    Posts
    340
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Reading and Writing CSV files

    Bret

    Another alternative might be the dictionary or associative array class. You can find this in the download section
    under Segue resources in betasoft. I find dictionaries are great for setup data across tests as well as data driven tests.
    When you need to change refernced values(just like tags) off specific keys indexes (just like logical identifiers)
    all you need do is change the data in one global file that is accessible from a common network. This is great for changing
    urls, ports, and data values for setting up test frames.

    I don't really 100% know what your goals are but editing flat files is so much easier than excel spreadsheets,
    where the value you are looking for is in a column to the far right. Certainly this technique is
    less frightening for junior members than a data base (even a simple access DB).

    You can store stuff like this in a flat file and read it to a dictionary via:
    adict.InitFromFile("\\ServerName\PublicNetworkSubf older\MajorTestData.txt")

    Then pick off the values stored against keys like so:
    browser.LoadPage (adict.GetValue("srvr_page_ops")) // to refer to a changing url off a non changing key

    and run it on any machine in your org. Where the file can contain keys which index strings, lists, numbers
    or even other dictionaries. The download has a very helpfull example script with flat files & values showing it's use.

    In the example above the file \\ServerName\PublicNetworkSubfolder\MajorTestData. txt could contain::
    <code>

    // Projects to dynamically update to
    {'sys_projs',{'422','500','510','Concerto','bin',' Library','Classes','spa'}}

    // key system tables
    {'sys_dbs',{'BOMEFFECT','Outsourcing', 'PCW','Wo_boms','SYSTEM_TEST'}}
    // key pages for org to test with
    {"srvr_page_ops","http://yada.yada.com/apps/MyApplications"}
    {"srvr_page_int","http://yada.wada.com/ems/apps/MyApplications"}
    </code>

    BTW if this is off the mark please disregaurd .. but personally dictionaries can be a very effective
    tool for maintining, and data driving tests. Check it OUT!

    [This message has been edited by rick_weth (edited 10-31-2000).]
    Smoke me a kipper, I'll be back for breakfast!
    Sincerely
    Richard Weth
    Sr. QA Engineer

  6. #6
    Member
    Join Date
    Sep 1999
    Location
    Austin, Texas
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Reading and Writing CSV files

    Well, i got the ODBC driver for CSV files configured and, using James Soderborg's article, was able to access data from it pretty easily.

    Rich, thanks for the suggestion regarding your dictionary library. As you know, i have had occassion to use this library before on other projects.

    On this project, i need to read in some test data that is generated by a different program. So i needed a data format that was standard and easy to specify. This is why i used CSV. My rudimentary CSV parsing in SilkTest broke when we started having embedded commas in our data. This is what prompted me to use the ODBC driver.

    The problem with the dictionary class is that it use's SilkTest's data format. I am not aware of clear specification of it that i could give the other programmer. We work in separate locations. My experience has been that it is better to use simple interfaces, even if that complicates processing. It is too easy for one or the other party to misinterpret complicated interfaces. I still had to do some complicated parsing of the data inside the CSV fields as well. It is really too bad that Silk doesn't have support for regular expression parsing. I suppose that this could be built using the Extension Kit and regular expression parsing libraries in C. Has anyone done this?


    ------------------
    Bret Pettichord
    b.pettichord@computer.org
    http://www.io.com/~wazmo
    Bret Pettichord
    Book - www.testinglessons.com
    Hotlist - www.testinghotlist.com
    Consulting - www.pettichord.com

  7. #7
    Junior Member
    Join Date
    May 2001
    Location
    New Jersey, US
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Reading and Writing CSV files

    Hi!

    Have you guys tried saving the File in Unicode Text format?

    This way you can use the FileReadValue...
    functions.

    You can also save it as Text (Tab Delimited) however if your data contains commas it will be enclosed in ""

    If you have found that using a Unicode Text file doesn't work for you, please let me know.

    Thanks,

    -maa

    ------------------

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 05:35 AM.

Copyright BetaSoft Inc.