selenium自動化測試之測試結果驗證

來源:互聯網
上載者:User

標籤:cond   else   ref   expec   案例分析   進入   自動化測試架構   結果   測試結果   

1.實際測試過程中,常常要對比實際結果與期望結果是否一致。
2.如果實際結果與期望結果不一致則被認為bug

selenium廣泛應用於B/S架構,如何通過selenium來驗證測試結果的正確性呢。

  • 案例分析:以百度為例,一起來看看如何驗證測試結果的正確性。
    • 點擊百度首頁的“hao123”後;
    • 跳轉至"hao123"頁面
    • 驗證:是否跳轉至“hao123”頁面
  • 如何通過selenium實現該情境呢?
#******************# 擷取驗證資訊,操作某頁面後,確認進入的是期望結果#******************from selenium import webdriverfrom time import sleepdriver = webdriver.Firefox()driver.get("http://www.baidu.com")print("===========The baidu Page===============")First_Title = driver.titleprint("The first page title is:%s" % First_Title)print("===========The hao123 Page===============")driver.find_element_by_xpath("//a[@name=‘tj_trhao123‘]").click()Second_Title = driver.titleprint("The Second page title is:%s" % Second_Title)Expect_Title = "hao123_上網從這裡開始"if Second_Title == Expect_Title:    print(True)else:    print(False)driver.quit()
  • selenium通過driver.title檢查頁面的title;
  • 判斷實際頁面的title值是否與期望值相同;
  • 從而得出測試結果。
如果你想系統學習selenium,可以通過如途徑哦.....

推廣下我的部落格專欄,目前選定了一個主題《從零學Selenium自動化測試架構》請添加連結描述,讓我們從代碼擼起,一步步實現Web自動化測試架構

該專題會從零帶你搭建一個可用的自動化測試架構(基於python+selenium)

前提:你要掌握了python與selenium基礎哦。要不你看不懂的。

selenium自動化測試之測試結果驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.