自动化测试(五)

一.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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值