|
本帖最后由 lazybone3936 于 2012-1-12 18:49 编辑
由于工作需要搭建了testlink作为测试用例管理工具
发现无法导入xls格式的文件,只支持xml
google之后发现,网上有卖xls转换为xml的工具,有点蛋疼
去官网论坛找了以后发现,国外已经有牛人给出了修改后的tcImport.php文件
本着资源共享的原则,无私了一把,服务广大苦逼的测试!!!{:4_83:}
废话不多,直接进入正题
1.对于导入的xls文件有格式要求,需要是
create an Excel file with 4 columns:
- Test Case Name
- Summary
- Actions
- Expected Results
2.修改代码:
文件路径..\testlink\lib\testcases\tcImport.php文件中
增加一个function
修改完后,重启apach2,你会发现导入测试用例的下拉框多出一个xls选项
------------------------------------------------
function create_xml_tcspec_from_xls($xls_filename,$xml_filename)
{
define('FIRST_DATA_ROW',2);
define('IDX_COL_NAME',1);
define('IDX_COL_SUMMARY',2);
define('IDX_COL_ACTIONS',3);
define('IDX_COL_EXPRESULTS',4);
$xls_handle = new Spreadsheet_Excel_Reader();
$xls_handle->setOutputEncoding(config_get('charset'));
$xls_handle->read($xls_filename);
$xls_rows = $xls_handle->sheets[0]['cells'];
$xls_row_qty = sizeof($xls_rows);
if($xls_row_qty < FIRST_DATA_ROW)
{
return; // >>>----> bye!
}
$xmlFileHandle = fopen($xml_filename, 'w') or die("can't open file");
fwrite($xmlFileHandle,"<testcases>\n");
for($idx = FIRST_DATA_ROW; $idx <= $xls_row_qty; $idx++ )
{
$name = htmlspecialchars($xls_rows[$idx][IDX_COL_NAME]);
// $summary = htmlspecialchars(iconv("CP1252","UTF-8",$xls_rows[$idx][IDX_COL_SUMMARY]));
// 20090117 - contribution - BUGID 1992 // 20090402 - BUGID 1519
// $summary = str_replace('…',"...",$xls_rows[$idx][IDX_COL_SUMMARY]);
$summary = convert_special_char($xls_rows[$idx][IDX_COL_SUMMARY]);
$summary = nl2p(htmlspecialchars($summary));
// 20090117 - BUGID 1991,1992 // 20090402 - BUGID 1519
// $steps = str_replace('…',"...",$xls_rows[$idx][IDX_COL_ACTIONS]);
//$steps = convert_special_char($xls_rows[$idx][IDX_COL_ACTIONS]);
//$steps = nl2p(htmlspecialchars($steps));
//fwrite($xmlFileHandle,"<steps><![CDATA[".$steps."]]></steps>\n");
$step_number = 1;
$actions = convert_special_char($xls_rows[$idx][IDX_COL_ACTIONS]);
$actions = nl2p(htmlspecialchars($actions));
// 20090117 - BUGID 1991,1992 // 20090402 - BUGID 1519
// $expresults = str_replace('…',"...",$xls_rows[$idx][IDX_COL_EXPRESULTS]);
$expresults = convert_special_char($xls_rows[$idx][IDX_COL_EXPRESULTS]);
$expresults = nl2p(htmlspecialchars($expresults));
//fwrite($xmlFileHandle,"<expectedresults><![CDATA[".$expresults."]]></expectedresults>\n");
fwrite($xmlFileHandle,"<testcase name=" . '"' . $name. '"'.">\n");
fwrite($xmlFileHandle,"<summary><![CDATA[" . $summary . "]]></summary>\n");
//generate xml data for step
fwrite($xmlFileHandle,"<steps>\n");
fwrite($xmlFileHandle,"<step>\n");
fwrite($xmlFileHandle,"<step_number>" . $step_number . "</step_number>\n");
fwrite($xmlFileHandle,"<actions><![CDATA[" . $actions . "]]></actions>\n");
fwrite($xmlFileHandle,"<expectedresults><![CDATA[" . $expresults . "]]></expectedresults>\n");
fwrite($xmlFileHandle,"</step>\n");
fwrite($xmlFileHandle,"</steps>\n");
fwrite($xmlFileHandle,"</testcase>\n");
}
fwrite($xmlFileHandle,"</testcases>\n");
fclose($xmlFileHandle);
} |
|