インターフェースデータパッケージを取得するPythonインターフェーステスト

  はじめに

  以前私は、インターフェイスのキーワードカプセル化に関する記事を共有しました。これは、インターフェイステストデータの定数取得方法を、キーワードと呼ばれるExcelの最初の行フィールドであるExcelにカプセル化します。インターフェーステストのキーワードを取得したので、キーワードに対応する値をどのように取得しますか?たとえば、前にカプセル化したメソッドでは、インターフェイスキーワードのurlを取得できますが、Excelには複数のインターフェイスデータがあり、各インターフェイスデータは異なるurl値に対応しています。各インターフェイスデータのURLを1行ずつ取得することはできないため、すべてのメソッドがクラスにカプセル化され、必要なキーワードデータはクラスからメソッドを呼び出して取得できます。

  カプセル化

  何をすべきかを知って、以下は実装です、コードは次のとおりです:

__author__ = 'Leo' 

from public.operate_excel import Operate_Excel 
from basic_method import testcases_keyword 

class getData(object):
    def __init __(self):
        self.op_excel = Operate_Excel()

    def get_case_nums(self):
        "" ""获取测试使用例条数 "" " 
        return self.op_excel.get_sheet_nrows()

    def get_is_header(self、row):
        " ""是否携带请求头 "" " 
        col = int(testcases_keyword.get_case_header())
        header = self.op_excel.get_sheet_cell(row、col)
        ifヘッダーはNoneではありません:
            ヘッダーを返し
        ますelse:
            print( "没有header!") 
            戻りなし
    def get_is_run(self、row): 
        "" "是否运行" ""
        col = int(testcases_keyword.get_case_is_execute())
        is_run = self.op_excel.get_sheet_cell(row、col)
        if is_run == 'yes':
            flag = True 
        else:
            flag = False 
        return flag 

    def get_url (self、row):
        "" "获取url" "" 
        col = int(testcases_keyword.get_case_interface_url())
        url = self.op_excel.get_sheet_cell(row、col)
        return url 

    def get_method(self、row):
        "" "获取请求方法 "" " 
        col = int(testcases_keyword.get_case_method())
        method = self.op_excel.get_sheet_cell(row、col) 
        returnメソッド
 
    def get_data(self、row):
        "" "获取请求
        データデータ" "" 
        col = int(testcases_keyword.get_case_payload())data = self.op_excel.get_sheet_cell(row、col)
        return data 

    def get_excepted_result(self、row):
        "" "获取预期结果" "" 
        col = int(testcases_keyword.get_case_expected_result())
        excepted_result = self.op_excel.get_sheet_cell(row、col)
        if excepted_result == '':
            return None 
        else:
            return 

    excepted_result def get_actual_result(self、row、value):
        "" "完了结果 "" " 
        col = int(testcases_keyword。get_case_actual_result())
        actual_result = self.op_excel.get_sheet_cell(row、col)
        self.op_excel.write_to_excel(row、col、value)


if __name__ == ' 
    __main__ ':get_data = getData()
    print(get_data.get_is_run(1))
    print(get_data。 get_url(1))

演算結果:

 

 結果の比較:

 

 

 

  まとめ

  上記のカプセル化されたメソッドは、基本的にプロジェクトインターフェーステストの要件を満たします。もちろん、実際のプロジェクトに応じて追加される特別なケースがさらにあります。自動テストとテスト開発に関心がある場合は、テストオープンコミュニケーショングループQQ:696400122に参加できます。思慮深い農家になるには、過去を見逃さず、未来を恐れないでください!

 

おすすめ

転載: www.cnblogs.com/liudinglong/p/12749273.html