最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python分類測試代碼實(shí)例匯總

 更新時(shí)間:2020年07月23日 10:05:53   作者:bashliuhe  
這篇文章主要介紹了Python分類測試代碼實(shí)例匯總,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

1.自動(dòng)化測試?yán)锩娴臏y試用例設(shè)計(jì)的一些方法

解耦、可以獨(dú)立運(yùn)行、需要靈活切換

設(shè)計(jì)思路: 腳本功能分析(分步驟)和模塊化分層(拆分為多模塊)

project

login_order.py #登錄下單測試用例
category.py #菜單分類測試用例

all_test.py #主入口

login_order.py

# -*- coding: UTF-8 -*-
import unittest
import time
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains


class LoginOrderTestCase(unittest.TestCase):
  def setUp(self):
    print("測試開始")
    self.driver = webdriver.Firefox()
    self.driver.implicitly_wait(20)
    self.base_url = "https://xdclass.net"
    self.driver.get(self.base_url)

  def tearDown(self):
    print("單個(gè)測試用例結(jié)束")
    pass
    #單個(gè)測試用例結(jié)束
  
  def test_login_order(self):
    u"登錄測試用例"
    driver = self.driver
    #登錄框
    login_ele = driver.find_element_by_css_selector("#login")
    ActionChains(driver).click(login_ele).perform()

    sleep(2)
    #查找輸入框,輸入賬號(hào),輸入框要提前清理里面的數(shù)據(jù)
    driver.find_element_by_id("phone").clear()
    driver.find_element_by_id("phone").send_keys("13113777338")
    #查找密碼輸入框,輸入密碼
    driver.find_element_by_id("pwd").clear()
    driver.find_element_by_id("pwd").send_keys("123456789")

    #拿到登錄按鈕
    login_btn_ele = driver.find_element_by_css_selector("button.login")
    #觸發(fā)點(diǎn)擊事件,登錄
    login_btn_ele.click()
    #判斷登陸是否成功,邏輯-》鼠標(biāo)移到上面,判斷彈窗字符
    #獲取鼠標(biāo)上移的元素
    user_info_ele = driver.find_element_by_css_selector(".user_head_portrait")
    sleep(1)
    #hover觸發(fā)
    ActionChains(driver).move_to_element(user_info_ele).perform()
    sleep(1)
    #獲取用戶名稱元素
    user_name_ele = driver.find_element_by_css_selector(".img_name > span:nth-child(2)")
    print("===測試結(jié)果==")
    print(user_name_ele.text)

    name = user_name_ele.text
    #self.assertEqual(name, u"二當(dāng)家小D",msg="登錄失敗")

    video_ele = driver.find_element_by_css_selector("div.hotcourses:nth-child(3) > div:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(1) > a:nth-child(1) > div:nth-child(1) > img:nth-child(1)")
    video_ele.click()
    sleep(2)

    buy_btn_ele = driver.find_element_by_css_selector(".learn_btn > a:nth-child(1)")

    buy_btn_ele.click()
    print("進(jìn)入下單頁面")
    
if __name__ == '__main__':
    unittest.main()

category.py

# -*- coding: UTF-8 -*-
import unittest
import time
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains

class CategoryTestCase(unittest.TestCase):
  def setUp(self):
    print("測試開始")
    self.driver = webdriver.Firefox()
    self.driver.implicitly_wait(20)
    self.base_url = "https://xdclass.net"
    self.driver.get(self.base_url)


  def tearDown(self):
    print("測試結(jié)束")
    #單個(gè)測試用例結(jié)束
    self.driver.quit()

  def test_menu(self):
    u"彈出菜單測試用例"
    driver = self.driver
    #跳轉(zhuǎn)網(wǎng)頁
    sleep(1)

    #定位到鼠標(biāo)移動(dòng)到上面的元素
    menu_ele = driver.find_element_by_css_selector("#banner_left_ul > a:nth-child(1) > li:nth-child(1) > span:nth-child(1)")

    #對(duì)定位到的元素執(zhí)行鼠標(biāo)移動(dòng)到上面的操作
    ActionChains(driver).move_to_element(menu_ele).perform()
    sleep(2)
    #選中子菜單
    sub_meun_ele = driver.find_element_by_css_selector("#des > li:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > a:nth-child(1)")

    sub_meun_ele.click()
    sleep(2)


if __name__ == '__main__':
  unittest.main()

all_test.py

# -*- coding: UTF-8 -*-
import unittest
import HTMLTestRunner
import login_order ,category
import time

#創(chuàng)建測試集合  
def create_suite():
  print("測試開始")
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(login_order.LoginOrderTestCase))
  suite.addTest(unittest.makeSuite(category.CategoryTestCase))
  return suite
   

if __name__ == '__main__':
  suite = create_suite()

  #文件名中加了當(dāng)前時(shí)間,為了每次生成不同的測試報(bào)告
  file_prefix = time.strftime("%Y-%m-%d %H_%M_%S", time.localtime())

  #創(chuàng)建測試報(bào)告,此時(shí)這個(gè)文件還是空文件 wb 以二進(jìn)制格式打開一個(gè)文件,只用于寫入,如果文件存在則覆蓋,不存在則創(chuàng)建
  fp = open("./"+file_prefix+"_result.html","wb")
  
  # stream定義一個(gè)測試報(bào)告寫入的文件,title就是標(biāo)題,description就是描述
  runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"小D課堂 測試報(bào)告",description=u"測試用例執(zhí)行情況",verbosity=2)
  runner.run(suite)
  fp.close()

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python從內(nèi)存地址上加載python對(duì)象過程詳解

    python從內(nèi)存地址上加載python對(duì)象過程詳解

    這篇文章主要介紹了python從內(nèi)存地址上加載pythn對(duì)象過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • Python實(shí)現(xiàn)基于Excel數(shù)據(jù)繪制棋盤圖

    Python實(shí)現(xiàn)基于Excel數(shù)據(jù)繪制棋盤圖

    這篇文章主要為大家介紹了如何根據(jù)可視化的需要,利用Python將Excel中的數(shù)據(jù)用棋盤圖的樣式來展示,文中的示例代碼簡潔易懂,需要的可以參考一下
    2023-07-07
  • Python?ModuleNotFoundError:?No?module?named?‘xxx‘可能的解決方案大全

    Python?ModuleNotFoundError:?No?module?named?‘xxx‘可能的解決方

    本文主要介紹了Python?ModuleNotFoundError:?No?module?named?‘xxx‘可能的解決方案大全,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧Chat?Gpt<BR>
    2023-07-07
  • Python使用urllib2獲取網(wǎng)絡(luò)資源實(shí)例講解

    Python使用urllib2獲取網(wǎng)絡(luò)資源實(shí)例講解

    urllib2是Python的一個(gè)獲取URLs(Uniform Resource Locators)的組件。他以u(píng)rlopen函數(shù)的形式提供了一個(gè)非常簡單的接口,下面我們用實(shí)例講解他的使用方法
    2013-12-12
  • python Gunicorn服務(wù)器使用方法詳解

    python Gunicorn服務(wù)器使用方法詳解

    這篇文章主要介紹了python Gunicorn服務(wù)器使用方法詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • python DataFrame獲取行數(shù)、列數(shù)、索引及第幾行第幾列的值方法

    python DataFrame獲取行數(shù)、列數(shù)、索引及第幾行第幾列的值方法

    下面小編就為大家分享一篇python DataFrame獲取行數(shù)、列數(shù)、索引及第幾行第幾列的值方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • Pytorch實(shí)現(xiàn)WGAN用于動(dòng)漫頭像生成

    Pytorch實(shí)現(xiàn)WGAN用于動(dòng)漫頭像生成

    這篇文章主要介紹了Pytorch實(shí)現(xiàn)WGAN用于動(dòng)漫頭像生成,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Python導(dǎo)入模塊包原理及相關(guān)注意事項(xiàng)

    Python導(dǎo)入模塊包原理及相關(guān)注意事項(xiàng)

    這篇文章主要介紹了Python導(dǎo)入模塊包原理及相關(guān)注意事項(xiàng),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03
  • Python Subprocess模塊原理及實(shí)例

    Python Subprocess模塊原理及實(shí)例

    這篇文章主要介紹了Python Subprocess模塊原理及實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08
  • python序列解包應(yīng)用示例詳解

    python序列解包應(yīng)用示例詳解

    這篇文章主要為大家介紹了python序列解包應(yīng)用場景示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-10-10

最新評(píng)論

黄骅市| 冀州市| 铜梁县| 任丘市| 玛纳斯县| 卫辉市| 宝鸡市| 盐源县| 六枝特区| 元氏县| 冕宁县| 武夷山市| 永康市| 彭山县| 金溪县| 泸水县| 新巴尔虎左旗| 延庆县| 河源市| 汝州市| 清徐县| 杭州市| 贺州市| 红安县| 昌黎县| 花莲县| 长白| 南阳市| 池州市| 仪陇县| 海兴县| 多伦县| 唐海县| 和田市| 康乐县| 天气| 景宁| 鄢陵县| 施秉县| 凤台县| 卓资县|