之前分享过自己写的 appium 框架,有很多待优化的地方,先从 selenium 开始优化
下载项目:
git clone git@github.com:Louis-me/selenium.git
配置 openurl.yaml
openurl: http://www....com/login
配置用例 yaml
testinfo:
- id: 001
moudle: mok模块
intr: 个人
testcase:
- element_info: //*[@id="login"]/div[1]/div[2]/form/div[1]/input
find_type: by_xpath
operate_type: send_keys
text: test
- element_info: //*[@id="login"]/div[1]/div[2]/form/div[2]/input
find_type: by_xpath
operate_type: send_keys
text: 123456
- element_info: //*[@id="login"]/div[1]/div[2]/form/button[1]
find_type: by_xpath
operate_type: click
check:
- element_info: //*[@id="home"]/a
find_type: by_xpath
- element_info: //*[@id="setting111"]/a
find_type: by_xpath
用例管理
基本上是直接复制
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
from testRunner.runnerBase import TestInterfaceCase
class testSetting(TestInterfaceCase):
def setUp(self, methodName=''):
super(testSetting, self).setUp()
self.bc = webCase.WebCaseBase(driver=self.driver, casename="testSetting")
def tearDown(self):
self.driver.quit()
pass
def test_setting(self):
self.bc.execCase(PATH("../yaml/setting.yaml"))
代码人口
def _report():
workbook = xlsxwriter.Workbook('report.xlsx')
worksheet = workbook.add_worksheet("测试总况")
worksheet2 = workbook.add_worksheet("测试详情")
re = report.OperateReport(wd=workbook)
re.init(worksheet, data=util.DATA)
re.test_detail(worksheet2, data=util.INFO)
re.close()
def runnerCaseWeb():
starttime = datetime.datetime.now()
suite = unittest.TestSuite()
suite.addTest(TestInterfaceCase.parametrize(testLogin)) # 引用测试用例类
suite.addTest(TestInterfaceCase.parametrize(testSetting))#引用测试用例类
unittest.TextTestRunner(verbosity=2).run(suite)
endtime = datetime.datetime.now()
util.DATA["sum_time"] = str((endtime - starttime).seconds) + "秒"
util.DATA["test_date"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
if __name__ == '__main__':
runnerCaseWeb()
_report()
命名行运行:
pyhton testRunner/runner.py
测试报告