如何解决将行分配给单个TestCA的问题

2024-10-01 22:42:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样一个问题。我在这里处理的是一系列测试用例,其中mainreader.py文件中的一个脚本总是一行一行地分配一个用户名和密码。不幸的是,我不知道怎么做。每个TC调用mainreader时,应从新行中获取2个变量。 到目前为止,我在这个脚本中只有一个常规调用,但我不知道如何做

manireader.py:

    import csv


with open ('aisg_users.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=';')
    line_count = 0
    for row in csv_reader:
        if line_count == 0:
            aisg_username = row[0]
            aisg_password = row[1]
            print(aisg_username)
            print(aisg_password)
            line_count += 1
    else:
        exit()
        print("Not FOUND")

有人解决过这样的问题吗

picture of plan


Tags: 文件csvpy脚本countlineusername测试用例
2条回答

在下图中,我为每个凭证指定了唯一的标题名,因此在我的自定义函数中,我将传递唯一的标题名,该标题名将标识行号,而行号+1是我的用户凭证位置

enter image description here

public static Hashtable < String, String > getData(String testName, String sheetName, Xls_Reader xls) {
int testCaseStartIndex = 0;
for (int rNum = 1; rNum <= xls.getRowCount(sheetName); rNum++) {
    if (testName.equals(xls.getCellData(sheetName, 0, rNum))) {
        testCaseStartIndex = rNum;
        break;
    }
}

int colStartIndex = testCaseStartIndex + 1;
int cols = 1;
while (!xls.getCellData(sheetName, cols, colStartIndex).equals("")) {
    cols++;
}

int dataStartIndex = testCaseStartIndex + 2;
int rows = 0;
while (!xls.getCellData(sheetName, 1, (dataStartIndex + rows)).equals("")) {
    rows++;
}
Hashtable < String, String > table = null;
for (int rNum = dataStartIndex; rNum < (dataStartIndex + rows); rNum++) {
    table = new Hashtable < String, String > ();
    for (int cNum = 0; cNum < cols; cNum++) {
        table.put(xls.getCellData(sheetName, cNum, colStartIndex), xls.getCellData(sheetName, cNum, rNum));
    }
}
return table;
}

相关问题 更多 >

    热门问题