import unittest from framework2.logger import Logger from testsuites.base_testcase import BaseTestCase from pageobjects.city_login import CityPage from pageobjects.city_xuncha_page import City_xuncha_page logger = Logger(logger="BasePage").getlog() class Xuncha_Search(BaseTestCase): def test_xuncha_search(self): # 先登录 login_page = CityPage(self.driver) login_page.login1('18210034706', "123456") home_page2 = City_xuncha_page(self.driver) home_page2.xunCha() home_page2.xiangQing() home_page2.search_xunchaPeople('11') home_page2.add_xuncha_record() # try: # xuncha=xuncha_page.add_xuncha_record('ccccc') # self.assertEqual(xuncha, '18210034706', msg=xuncha) # logger.info('实际值与期望值一致') # print("实际值与期望值一致") # except: # logger.error('实际值与期望值不一致') # print("实际值与期望值不一致")
from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from framework2.logger import Logger import time import os.path # create a Logger instance logger = Logger(logger='BasePage').getlog() class BasePage(object): def __init__(self, driver): self.driver = driver def back(self): self.driver.back() logger.info('Click back on current page') def forward(self): self.driver.forward() logger.info('Click forward on current page') def open_url(self, url): self.driver.get(url) def quit_browser(self): self.driver.quit() def close(self): try: self.driver.close()
#浏览器的引擎 import sys, os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import os.path from configparser import ConfigParser #有效读取配置文件数据 from selenium import webdriver from framework2.logger import Logger #日志文件 logger = Logger(logger="BrowserEngline").getlog() class BrowserEngline(object): dir = os.path.dirname(os.path.abspath(".")) #调用os.path模块 相对路径获取方法 chrome_driver_path = dir + "/tools/chromedriver.exe" #安装相应的驱动器 firefox_driver_path = dir + "/tools/geckodriver.exe" ie_driver_path = dir + "/tools/IEDriverServer.exe" def open_browser(self): '''在配置文件下找到浏览器,选择浏览器,获得查找内容地址,设置窗口最大化,并且等待10秒,每一个过程都用logger记录''' config = ConfigParser() #有效读取配置文件数据 file_path = os.path.dirname( os.path.abspath(".")) + "/config/config.ini" #用相对路径找到配置文件 config.read(file_path) #读取配置文件内容 browser = config.get("browserType", "browserName") logger.info("You had select %s browser" % browser) #你已经挑选了哪个浏览器 url = config.get("testServer", "url") #地址h0 # self.driver.implicitly_wait(5) logger.info("The test sever url is:%s" % url) #用日志记录一下获得的地址 if browser == "Firefox": self.driver = webdriver.Firefox(
import xlrd import os.path from framework2.logger import Logger logger=Logger("logger=Util").getlog() class Util: path=os.path.dirname(os.path.abspath(".")) print(path) ex_path=os.path.join(path,"data\example.xlsx") print(ex_path) @classmethod def read_excel(self,excel_path,sheet_name="sheet"): """将Execl表格中的数据读取出来: 思路:先读行,再读列,以列表字典方式进行数据存储 如:[{'username':'******','password':'******'},{'username':'******','password':'******'}] """ workbook=xlrd.open_workbook(excel_path) #打开workbook sheet=workbook.sheet_by_name(sheet_name) #得到表名 # 获取第一行作为key值 keys=sheet.row_values(0) #得到行 row=sheet.nrows #得到列 col=sheet.ncols if row<1: # logger.error("行数小于1") pass else: list1=[] for i in range(1,row): dic={} values=sheet.row_values(i) #得到每一行的值