def errcode_Test(self): error = 0 url = "http://10.2.25.24:8180/appautocomplete/search?source=offline&action=autocomplete&keyword=keyword_value" for keyword in loadkeyword.load_keyword_from_AppTestCase(): keyword = str(keyword) keyword_quote = urllib.quote(keyword) url = url.replace("keyword_value",keyword_quote) if http.getresponse_url_python(url)["head"]["errcode"] != 0: print keyword, http.getresponse_url_python(url)["head"]["errcode"] assert http.getresponse_url_python(url)["head"]["errcode"] == 0
def web_page_districthotellist(self): try: error = 0 url = "http://10.2.25.24:8180/appautocomplete/search?source=offline&action=autocomplete&keyword=keyword_value" browser = webdriver.Firefox() for keyword in loadkeyword.load_keyword_from_AppTestCase(): keyword = str(keyword) keyword_quote = urllib.quote(keyword) urlnew = url.replace("keyword_value",keyword_quote) content = http.getresponse_url_python(urlnew) for m in range(len(content["data"])): a = http.get_key_vlue(urlnew,m,"type") if a == "districthotellist": b = content["data"][m]["url"] c = content["data"][m]["word"] d = content["data"][m]["districtname"] browser.get(b) # Load page time.sleep(5) if d+"酒店" in browser.title: infovalue = "districthotellist测试,"+"测试过的关键字为"+keyword+"结果正确" log.info(infovalue) else: error = error+1 infovalue = "districthotellist测试,"+"测试过的关键字为:"+keyword+"结果错误,"+"word="+c[:-3]+"网页title="+browser.title log.info(infovalue) print "districthotellist测试错误",keyword,c,d,browser.title except Exception,e: log.error(e)
def nearby_hotle_price_no_null_Test(self): error = 0 url = ['http://10.8.91.244:8180/appautocomplete/search?keyword=%e9%99%84%e8%bf%91&action=autocomplete&source=globalapp65&lon=121.35801673&lat=31.22016018&districtid=2&type=fortest', 'http://10.8.91.244:8180/appautocomplete/search?keyword=%e9%99%84%e8%bf%91&action=autocomplete&source=globalapp65&lon=120.545916&lat=31.315913&districtid=100066&type=fortest', 'http://10.8.91.244:8180/appautocomplete/search?keyword=%e9%99%84%e8%bf%91&action=autocomplete&source=globalapp65&lon=120.984205&lat=31.393074&districtid=77&type=fortest', 'http://10.8.91.244:8180/appautocomplete/search?keyword=%e9%99%84%e8%bf%91&action=autocomplete&source=globalapp65&lon=114.055626&lat=22.316061&districtid=38&type=fortest', 'http://10.8.91.244:8180/appautocomplete/search?keyword=%e9%99%84%e8%bf%91&action=autocomplete&source=globalapp65&lon=121.090235&lat=24.17594&districtid=100076&type=fortest', 'http://10.8.91.244:8180/appautocomplete/search?keyword=%e9%99%84%e8%bf%91&action=autocomplete&source=globalapp65&lon=2.294481&lat=48.85837&districtid=100024&type=fortest', 'http://10.8.91.244:8180/appautocomplete/search?keyword=%e9%99%84%e8%bf%91&action=autocomplete&source=globalapp65&lon=2.294481&lat=48.85837&districtid=308&type=fortest'] for n in range(len(url)): content = http.getresponse_url_python(url[n]) for m in range(len(content["data"])): try: a = http.get_key_vlue(url[n],m,"price") if a == "null": error = error+1 print url[n] except Exception: 1 == 1 assert error == 0
from common.trd.httpbase import http from common.ctrip import logger import time log = logger.logger() keyword_num = 0 word_num = 0 error_url = 0 try: for keyword in loadkeyword.load_keyword_from_AppTestCase(): keyword_num = keyword_num+1 reload(sys) sys.setdefaultencoding('utf-8') keyword = str(keyword) keyword_quote = urllib.quote(keyword) url1 = "http://10.8.119.199:8180/appautocomplete/search?keyword=keywordvalue&action=autocomplete&source=globalonline" url1 = url1.replace("keywordvalue",keyword_quote) try: result1 = http.getresponse_url_python(url1) except: pass for n in result1["data"]: time.sleep(1) result1 = http.getresponse_url(url1) if http.getresponse_status(n["url"]) != 200: print http.getresponse_status(n["url"]),keyword,n["word"],n["url"] except: pass