一.TestCases层分析
TestCases层的作用是管理测试用例与执行用例,相当于测试的总入口。
二,代码实现
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time : 2019/12/30 18:37
# @file : TrainTest.py
# @Software : PyCharm
# @author : MAYH
# @contact : mayh@chnsys.com.cn
# @Version :V1.1.0
"""
文件说明:
"""
import os, sys
import time, unittest, HTMLTestRunner
from PageObject.book_page import BooKPage
from PageObject.order_page import OrderPage
from PageObject.search_page import SearchPage
from Common.excel_data import read_excel
from Common.function import config_url
from selenium import webdriver
from Common.function import project_path
sys.path.append( os.path.split( os.getcwd() )[0] )
class loginTest( unittest.TestCase ):
@classmethod
def setUpClass(cls) -> None:
cls.data = read_excel( project_path() + "Data/testdata.xlsx", 0 )
cls.driver = webdriver.Chrome()
cls.driver.get( config_url() )
cls.driver.maximize_window()
def test02(self):
# self.driver.get( "https://trains.ctrip.com/TrainBooking/SearchTrain.aspx###" )
search = SearchPage( self.driver )
res = search.search_train( self.data.get( 1 )[0], self.data.get( 1 )[1], self.data.get( 1 )[2] )
# 本用例断言是根据当前页面的url判断
self.assertIn( "TrainBooking", res )
def test03(self):
book = BooKPage( self.driver )
res = book.book_btn()
time.sleep( 2 )
# 断言取当前页面页面的Url是否包含“InPutPassengers”
self.assertIn( "InputPassengers", res )
def test04(self):
order = OrderPage( self.driver )
res = order.user_info( "小王" )
# self.assertIn( "RealTimePay", res )
@classmethod
def tearDownClass(cls) -> None:
time.sleep( 5 )
cls.driver.quit()
if __name__ == "__main__":
suitTest = unittest.TestSuite()
suitTest.addTest( loginTest( "test02" ) )
suitTest.addTest( loginTest( "test03" ) )
suitTest.addTest( loginTest( "test04" ) )
# filepath = "c:\\re.html"
# fp = open( filepath, "wb" )
file_name = 'D:\\report_ctrip_tickets.html'
fp = open( file_name, 'wb' )
runner = HTMLTestRunner.HTMLTestRunner( stream=fp,
title="自动化测试报告",
description="测试baog" )
runner.run( suitTest )
fp.close()
三.整体项目代码下载
下载链接:
https://download.csdn.net/download/mayanhang/12277261