使用api导入testlink用例

来源:互联网 发布:java string转int 编辑:程序博客网 时间:2024/06/05 06:02

需求:因为之前把用例都写在了bugfree,现在要导导testlink上,bugfree上用例前提、步骤、结果都是在一块的。。比较尴尬

实现步骤如下:

1、vi /var/www/html/testlink/config.inc.php

修改设置:$tlCfg->exec_cfg->enable_test_automation = ENABLED

2、testlink上生成api key

3、调api(需要知道账户名、projectId、suiteId)

import br.eti.kinoshita.testlinkjavaapi.TestLinkAPI;import br.eti.kinoshita.testlinkjavaapi.constants.ActionOnDuplicate;import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionType;import br.eti.kinoshita.testlinkjavaapi.constants.TestCaseStatus;import br.eti.kinoshita.testlinkjavaapi.constants.TestImportance;import br.eti.kinoshita.testlinkjavaapi.model.TestCase;import br.eti.kinoshita.testlinkjavaapi.model.TestCaseStep;import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException;import jxl.Sheet;import jxl.Workbook;import jxl.read.biff.BiffException;import org.dom4j.Document;import org.dom4j.DocumentHelper;import org.dom4j.Element;import org.dom4j.io.XMLWriter;import org.testng.annotations.DataProvider;import org.testng.annotations.Test;import java.io.*;import java.net.MalformedURLException;import java.net.URL;import java.util.ArrayList;import java.util.List;/** * Created by guoying on 2017/6/12. */public class CreateTestCase {    Sheet sheetToEdit;    static Workbook rwb;    TestLinkAPI api = null;    @DataProvider(name = "data")    public Object[][] getDate() throws IOException, BiffException {        InputStream stream = new FileInputStream("caselist.xls");        rwb = Workbook.getWorkbook(stream);        Object[][] objects = null;        for (int j = 0; j < rwb.getNumberOfSheets(); j++) {            sheetToEdit = rwb.getSheet(j);            System.out.println(sheetToEdit.getName());             objects = new Object[sheetToEdit.getRows()][7];            for (int n = 0; n < sheetToEdit.getRows() - 1; n++) {                String forProjectNo = sheetToEdit.getCell(0, n + 1).getContents().toString();                String forSuiteId = sheetToEdit.getCell(1, n + 1).getContents().toString();                String forYouXianJi = sheetToEdit.getCell(2, n + 1).getContents().toString();                String forTitle = sheetToEdit.getCell(3, n + 1).getContents().toString();                String forStep = sheetToEdit.getCell(4, n + 1).getContents().toString();                String pre = forStep.substring(forStep.indexOf("前置条件"), forStep.indexOf("操作步骤"));                String stepAll = forStep.substring(forStep.indexOf("操作步骤"), forStep.indexOf("预期结果"));                String result = forStep.substring(forStep.indexOf("预期结果"), forStep.length());                objects[n][0] = forProjectNo;                objects[n][1] = forSuiteId;                objects[n][2] = forTitle;                objects[n][3] = pre;                objects[n][4] = stepAll;                objects[n][5] = result;                objects[n][6] = forYouXianJi;            }                    }        return objects;    }    public void init() throws MalformedURLException {        String url = "http://xxx.xxx.xxx.xxx:port/testlink/lib/api/xmlrpc/v1/xmlrpc.php";        String devKey = "b63c521dfc5a249609805df6a07d7c7f";        URL testlinkURL = null;        try     {            testlinkURL = new URL(url);        } catch ( MalformedURLException mue )   {            mue.printStackTrace( System.err );            System.exit(-1);        }        try     {            api = new TestLinkAPI(testlinkURL, devKey);        } catch( TestLinkAPIException te) {            te.printStackTrace( System.err );            System.exit(-1);        }        System.out.println(api.ping());    }    @Test(dataProvider = "data")    public void create(String projectId, String suiteId, String title, String pre, String stepAll, String result, String youXinaJi) throws IOException {        List<TestCaseStep> steps = new ArrayList<TestCaseStep>();        TestCaseStep step = new TestCaseStep();        step.setNumber(1);        step.setExpectedResults(result);        step.setExecutionType(ExecutionType.MANUAL);        step.setActions(stepAll);        steps.add(step);        init();        TestImportance importance = TestImportance.HIGH;        if (youXinaJi.equals("1")){            importance = TestImportance.HIGH;        }else if (youXinaJi.equals("2")){            importance = TestImportance.MEDIUM;        }else if (youXinaJi.equals("3")){            importance = TestImportance.LOW;        }        TestCase tc = api.createTestCase(                title, // testCaseName                Integer.parseInt(suiteId), // testSuiteId                Integer.parseInt(projectId), // testProjectId                "admin", // authorLogin                "No summary", // summary                steps, // steps                pre, // preconditions                TestCaseStatus.REVIEW_IN_PROGRESS, // importance                importance, // execution                ExecutionType.MANUAL, // order                null, // internalId                null, // checkDuplicatedName                null,                ActionOnDuplicate.BLOCK); // actionOnDuplicatedName        System.out.println("Test case with steps created");    }}

api:
http://kinow.github.io/testlink-java-api/sample4.html

原创粉丝点击