2016-12-21 69 views
1

我正在從soapui運行硒python測試來讀取文件。當我從命令行運行代碼時,似乎一切正常。但是,當我從soapui運行它似乎無法找到該文件。從soapui運行硒python測試來讀取文件

這是我的代碼。我相信我需要指定完整路徑,但有沒有辦法定義一個路徑,所以我不必在每次調用此函數時都硬拷貝完整路徑。

file_name = XMLAuto_al_log.txt 
with open(file_name) as f: 
      with open(outputFileName, 'w') as f1: 
       for line in f: 
        if searchText in line: 
         line = line.rstrip() 
         object_id = line.split('=')[2] 
         f1.write(object_id + '\n') 

回答

1

這個怎麼樣?

import os.path 

directory = ("C:/my/directory/") 
file_name = ("XMLAuto_al_log.txt") 

path = os.path.join(directory + file_name)