Selenium自動化測試之Selenium IDE

簡介

Selenium IDE 是實現Web自動化的一種便捷工具,本質上它是一種瀏覽器插件。該插件支援Chrome和Firefox瀏覽器,擁有錄製、編寫及回放操作等功能,能夠快速實現Web的自動化測試

使用場景

  1. Selenium IDE本身的定位並不是用於複雜的自動化場景,而是用於一些對效率擁有極高要求的簡易場景
  2. 用於發現BUG,重現BUG,提高溝通效率
  3. 提高用例執行效率,提高回歸效率
  4. 錄製功能可以導出程式碼,節省自動程式碼編寫時間

安裝:

  • 打開火狐瀏覽器,搜索火狐插件

  • 點擊選中進入後進行安裝

基本操作

 點擊圖標進入

 

 

 錄製與回放

 

 

  1.  點擊第一個選項我們錄製一個新的項目
  2. 輸入項目名稱
  3. 輸入需要錄製的網址
  4. 跳轉頁面後在錄製狀態下進行頁面操作
  5. 操作結束後暫停錄製,狀態顯示如下
  6. 點擊按鈕進行回放

     注意:上圖右上角保存按鈕可以用來保存錄製腳本

  7. 可以導出腳本,節約編寫用例的時間
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

class TestFirsttest():
  def setup_method(self, method):
    self.driver = webdriver.Firefox()
    self.vars = {}
  
  def teardown_method(self, method):
    self.driver.quit()
  
  def test_firsttest(self):
    self.driver.get("//www.baidu.com/")
    self.driver.set_window_size(1146, 693)
    self.driver.find_element(By.ID, "kw").click()
    self.driver.find_element(By.ID, "kw").send_keys("helloworld")
    self.driver.find_element(By.ID, "su").click()
  

 

測試套件

  • 在同一個項目中,可以同時管理多條測試用例。在Selenium IDE的測試視圖中單擊「+」按鈕,可以新增測試用例,也可以右擊一條測試用例,在上下文菜單中選擇Duplicate(複製)選項進行複製
  • 如果每個模組都有幾十條測試用例,那麼這些用例在對應的面板下將非常難以維護,以至於根本無法分辨各個用例歸屬於哪個模組。Selenium IDE提供了一種名為「測試套件」(Test Suite)的功能來管理測試用例