Selenium + python的自動化架構搭建

來源:互聯網
上載者:User

標籤:google搜尋   windows   瀏覽器   python   chrome   

selenium是一個web自動化測試工具,和其它的自動化工具相比來說其最主要的特色是跨平台、跨瀏覽器。
支援windows、linux、MAC,支援ie、ff、safari、opera、chrome等。
此外還有一個特色是支援分布式測試案例的執行,可以把測試案例分布到不同的測試機器的執行,相當於分發機的功能。

關於selenium的原理、架構、使用等可以參考其官網的資料,這裡記錄如何搭建一個使用python的selenium測試案例開發環境。其實用python
來開發selenium的方法有2種:一是去selenium官網下載python版的selenium引擎;還有一種沒有操作過,這裡就不列出來了,有興趣的朋友可以自行查閱資料


這裡記錄的是第一種搭建方式:

1.安裝python2.7x32或者x64版本

2.安裝pip工具
3.直接使用pip安裝selenium,命令為:pip install -U selenium

如果測試成功會看到開啟瀏覽器後進行google搜尋。另外selenium分版本1和版本2,這裡安裝是版本2的selenium。650) this.width=650;" src="https://code.csdn.net/assets/ico_fork.svg" alt="派生到My Code片" width="12" height="12" />

  

#-*-coding:utf-8-*-    from selenium import webdriver  from selenium.common.exceptions import TimeoutException  from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0  import time    # Create a new instance of the browser driver  driver = webdriver.Chrome()  ##可以替換為IE(), FireFox(),但前提是配置了各自瀏覽器的Driver,Firefox在我自己使用中如果瀏覽器和驅動不相容,瀏覽器在啟動和退出是會報停止工作,此處注意    # go to the google home page  driver.get("http://www.google.com")    # find the element that‘s name attribute is q (the google search box)  inputElement = driver.find_element_by_name("q")    # type in the search  inputElement.send_keys("Cheese!")    # submit the form. (although google automatically searches now without submitting)  inputElement.submit()    # the page is ajaxy so the title is originally this:  print driver.title    try:      # we have to wait for the page to refresh, the last thing that seems to be updated is the title      WebDriverWait(driver, 10).until(lambda driver : driver.title.lower().startswith("cheese!"))        # You should see "cheese! - Google Search"      print driver.title    finally:      driver.quit()    #==================================


本文出自 “ganshizhe.bokee.com” 部落格,請務必保留此出處http://328538.blog.51cto.com/318538/1660371

Selenium + python的自動化架構搭建

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.