def doRequest(self, url, reqargs, requestMethod): respData = None #开始HTTP请求 try: resp = self.client.dorequest(url, reqargs, \ methodname=requestMethod) if self.url.find('login') > -1: #如果是一个登陆的url self.initInfoBeforeTest['cookie'] = self.client.getCookie(resp.info()) if isinstance(resp, str): respData = resp else: respData = resp.read() Log.debugvar('respData is ', respData) except HTTPError, e: respData = '{"error":"' + str(e) + '"}'
def test(self): Log.debug('start test: ' + self.clas) try: self.getUrl() #self.fixtureExecResult = self.getFixture() self.args = {} paramlist = self.getParamlist() self.addParams(paramlist) self.setLoginInfo(self.client) self.addPreResultToParams( ) #从上次请求产生的response中取得需要保存的参数信息,并保存到本次请求的参数列表中 Log.debug('testCaseId:', self.testCaseId) respData = '' try: #默认为post请求 if not hasattr(self, 'requestMethod') and not self.requestMethod: self.requestMethod = 'post' if 'filepath' in self.args: self.requestMethod = 'upload' filepath = self.args['filepath'] Log.debug("filepath:", filepath.decode('utf-8').encode('gb2312')) self.args = filepath.decode('utf-8').encode('gb2312') # self.args = filepath.decode('utf-8').encode('gb2312') self.client.referer = "http://pre.moojnn.com/datasource.html" #若果请求的路径信息中含有动态变量,则从参数列表中读取 self.setDynamicUrlPath() #开始HTTP请求 resp = self.client.dorequest(self.url, self.args, \ methodname=self.requestMethod) if isinstance(resp, str): respData = resp else: respData = resp.read() Log.debugvar('respData is ', respData) except HTTPError, e: respData = '{"error":"' + str(e) + '"}' except Exception, e: respData = '{"error":"' + str(e) + '"}'