def test_sugar_bean(self): """M首页糖豆接口@author:fangyu""" sugarBeanTitleList = [] """首页糖豆接口@author:fangyu""" response = requests.get( sugar_bean_url + 'c-city-consumer/carSearchTag/getSugarBean?cityId=201&terminalId=3' ) status_code = response.status_code if status_code == 200: suageBeanData = json.loads(response.text).get('data') if suageBeanData: for data in suageBeanData: print(data) title = data['title'] sugarBeanTitleList.append(title) sugarBeanTitleListStr = json.dumps(sugarBeanTitleList, ensure_ascii=False) tt_check.assertTrue( True, '当前城市:北京,首页展示的糖豆为:{sugarBeanTitleListStr}'.format( sugarBeanTitleListStr=sugarBeanTitleListStr)) else: tt_check.assertFalse(False, '当前城市:北京,首页糖豆接口返回空') else: print('接口有问题') tt_check.assertFalse( False, '当前城市:北京,首页糖豆接口返回状态为:{status_code}'.format( status_code=status_code))
def test_sugar_bean(self): """App首页糖豆接口@author:fangyu""" sugarBeanTextList = [] response = requests.get( sugar_bean_url + 'get?action=gethomepagenew&v=7.9.0&cid=201&latitude=39.937341&longitude=116.320197&random=1409' ) status_code = response.status_code if status_code == 200: pageLabelList = json.loads( response.text).get('data').get('PageLabelList') if pageLabelList: for label in pageLabelList: print(label) text = label['Text'] sugarBeanTextList.append(text) sugarBeanTextListStr = json.dumps(sugarBeanTextList, ensure_ascii=False) tt_check.assertTrue( True, '当前城市:北京,首页展示的糖豆为:{sugarBeanTextListStr}'.format( sugarBeanTextListStr=sugarBeanTextListStr)) else: tt_check.assertFalse(False, '当前城市:北京,首页糖豆接口返回空') else: tt_check.assertFalse( False, '当前城市:北京,首页糖豆接口返回状态为:{status_code}'.format( status_code=status_code))
def test_common_tool(self): """测试买车列表页 常用工具的展示以及跳转请求是否正常@author:fangyu""" resultList = {} self.driver.get(bugcar_url) ulList = self.driver.find_element( BuyCarLocator.COMMON_TOOLS).find_elements_by_tag_name('li') if ulList: for li in ulList: text = li.find_element_by_tag_name('a').text url = li.find_element_by_tag_name('a').get_attribute('href') resultList[text] = url for url in resultList: r = requests.get(resultList[url]) status = r.status_code if status != 200: tt_check.assertFalse( False, '%s对应的地址:%s,请求ERROR,状态码:%s' % (url, resultList[url], status)) else: tt_check.assertTrue( True, '%s对应的地址:%s,请求OK,状态码:%s' % (url, resultList[url], status)) else: tt_check.assertFalse(False, '列表页常用工具未展示')
def test_hot_serial(self): """买车列表页热门车系,热门品牌@author:fangyu""" serialNameMap = {} serialNameList = [] brandNameMap = {} brandNameList = [] resultList = [] self.driver.get(bugcar_url) hot_serial = self.driver.find_element( BuyCarLocator.HOT_SERIAL).find_elements_by_tag_name('li') if hot_serial: for hs_tab in hot_serial: hs = hs_tab.find_element_by_tag_name('a').text if hs == '热门车系': serial_name = self.driver.find_element( BuyCarLocator.HOT_SERIAL_NAME ).find_elements_by_tag_name('li') for sn in serial_name: snn = sn.find_element_by_tag_name('a').text serialNameList.append(snn) serialNameMap[hs] = serialNameList resultList.append(serialNameMap) elif hs == '热门品牌': brand_name = self.driver.find_element( BuyCarLocator.HOT_BRAND_NAME ).find_elements_by_tag_name('li') for bn in brand_name: bnn = bn.find_element_by_tag_name('a').get_attribute( 'title') brandNameList.append(bnn) brandNameMap[hs] = brandNameList resultList.append(brandNameMap) else: pass result_str = json.dumps(resultList, ensure_ascii=False) if resultList and len(resultList) > 0: tt_check.assertTrue( True, '列表页热门品牌或者热门车系展示正常,展示为{result_str}'.format( result_str=result_str)) else: tt_check.assertFalse(False, '列表页热门品牌或者热门车系数据为空') else: tt_check.assertFalse(False, '列表页热门品牌或者热门车系有数据为空')
def test_page_click(self): """app首页、列表页、详情页点击检查@author:fangyu""" brandText = self.driver.find_element(HomeLoctor.BRAND_KEY).text print(brandText) self.driver.find_element(HomeLoctor.BRAND_KEY).click() classList = self.driver.find_element( HomeLoctor.CAR_LIST_SCREEN_ID).find_elements_by_class_name( 'android.widget.TextView') if classList: classText = classList[0].text print(classText) tt_check.assertEqual( brandText, classText, '首页选中品牌:{brandText},列表页展示品牌:{classText}'.format( brandText=brandText, classText=classText)) carList = self.driver.find_elements(HomeLoctor.CAR_INFO_IDS) if carList: carNameText = carList[0].text print("取到车源列表页第一辆车:{carNameText}".format( carNameText=carNameText)) carList[0].click() print("进入车源详情页") DetailCarNameText = self.driver.find_element( HomeLoctor.DETAIL_CAR_NAME).text print(DetailCarNameText) self.driver.swipeUpDown(0.9, 0.1) qggText = self.driver.find_element( HomeLoctor.QGG_FLOOR_ID).text if qggText: tt_check.assertTrue( True, "全国购店铺名称:{qggText}".format(qggText=qggText)) else: tt_check.assertFalse( False, "车源:{DetailCarNameText} 详情页没有全国购楼层".format( DetailCarNameText=DetailCarNameText)) else: print('没有取到车源列表数据') else: print('首页没有取到品牌')
def test_car_info(self): """验证详情页车源基本信息与选中的车源是否一致@author:fangyu""" self.driver.get(buy_car_url) self.driver.find_element(BuyCarLocator.CAR_LIST_INFO).click() self.driver.switch_to_window() brand_name = self.driver.find_element(BuyCarLocator.CAR_DETAIL_INFO).text print('进入车源:{brand_name} 的详情页'.format(brand_name=brand_name)) city_name = self.driver.find_element(BuyCarLocator.CITY_INFO).text time.sleep(2) if city_name == '郑州' or city_name == '沈阳' or city_name == '东莞': dealer_url = self.driver.find_element(BuyCarLocator.DEALER_INFO).get_attribute('href') print("当前城市:{city_name},对应的店铺地址:{dealer_url}".format(city_name=city_name,dealer_url=dealer_url)) r = requests.get(dealer_url) status = r.status_code if status != 200: tt_check.assertFalse(False, '当前城市为:{city_name},当前店铺地址为:{dealer_url},该店铺的请求状态为:{status}'. format(city_name=city_name, dealer_url=dealer_url, status=status)) else: tt_check.assertFalse(False, '当前城市为:{city_name},当前店铺地址为:{dealer_url},该店铺的请求状态为:{status}'. format(city_name=city_name, dealer_url=dealer_url, status=status)) else: print('ignore')