Wednesday, November 12, 2008

Importing tests from CSV into TestLink

Maybe because I'm not using Microsoft's Excel, but rather OpenOffice.org's Calc, I was not having so much luck following the TestLink instructions for creating an XML document of testcase from a spreadsheet that could be imported to TestLink. So, what I did was to create a conversion script that would take my tests that were formatted in a CSV file and then output the correct XML for TestLink. It's probably not as robust as it could be, as it doesn't have a bunch of error checking, but so far it is getting the job done. It allows empty steps and empty expectedresults, but will probably barf if you don't have a name or summary.



Once you convert your CSV file to XML, you can import the tests from the Specification view in TestLink. Ideally, since TestLink is open source, I would have liked to have added code to TestLink to allow it to import CSV from TestLink itself (and contribute it to the project), but I don't know PHP. I know there is a CSV lib in TestLink, but I haven't had the time to hack it yet. So, this is my temporary solution until I get chance to mess with the PHP. Which might be never.

3 comments:

Ranjini said...

But where do u paste this code???

Cynthia Sadler said...

I'm not sure what you mean. Paste the code into a text editor. The code is not run from a browser but from the command line (or DOS prompt). So, assuming you have ruby in your PATH environment variable, go to the directory where you have your CSV file and run:

ruby convert_csv_to_testlink.rb infile.csv outfile.xml

where infile.csv is your test cases exported to CSV format and outfile.xml is what you want the new file to be named. The script expects four fields in each row: name, summary, steps, expected results. If your first field starts
with the literal "name", it assumes it to be header row and it will skip that row. Hope that helps.

The Doctor said...

not working. got an error about initialization of the CSV reader.