Selenium IDE 3.6 命令Command詳解
學以致用,個人覺得要學老外的東西,最好的方法就是自己翻譯一遍。因此准備把SIDE官網的一些文檔,按工作所需做些翻譯整理。本文是命令這一塊的提綱,未全部完成,占坑中,查看進度。
Selenium IDE中的命令其實就等同於編程語言中的函數,這是首先要建立的一個概念。
函數是一個小的功能單元,每個函數都有自己目的,實現一個具體的功能,函數有入參、有出參。
要想用SIDE完成日常測試工作中各種場景的需求,就得熟練掌握這些命令,並靈活運用。
而要學會這些命令,前期得多看文檔,看看每個命令的作用是什么、傳什么參數,輸出什么結果。
對於Web領域測試人員來說,Web前端知識的要求還是有點高的,要了解HTML(標簽、id、class、屬性等)、CSS(元素選擇器selector)、Javascript/DOM、XML(xml、節點、元素、屬性、xpath等)
官網地址:https://www.selenium.dev/selenium-ide/docs/en/api/commands
Selenium IDE 目前的版本 3.6 系列,有90多個內置命令。這些可以分為如下幾類:
大類 |
小類 |
命令列表 |
工具類 |
- |
- pause(wait-time):等待多長時間再執行
- set speed(wait-time):設置全局的操作執行速度
- run(test-case):運行測試用例
- echo(message):輸出信息到控制台
- debugger():進入調試環境
|
交互操作 |
窗口 |
- close():關閉當前窗口
- select frame(locator):選中frame
- select window(window-handle):選擇窗口
- set window size(resolution):設置窗口大小
|
頁面 |
- open(url):打開URL
- run script(script):運行一段js腳本
|
表單 |
- add selection(locator, value):select增加選擇項
- check(locator):checkbox/radio勾選
- edit content(locator, variable-name):編輯內容
- remove selection(locator, option):移除多選元素選擇項
- select(locator, option):選擇下拉項
- submit(form-locator):提交表單
- type(locator, value):模擬輸入input字段值
- uncheck(locator):取消勾選
|
彈框 |
- answer on next prompt(answer)
- choose cancel on next confirmation()
- choose cancel on next prompt()
- choose ok on next confirmation()
- webdriver answer on visible prompt(answer)
- webdriver choose cancel on visible confirmation()
- webdriver choose cancel on visible prompt()
- webdriver choose ok on visible confirmation()
|
鼠標 |
- click(locator):單擊元素
- click at(locator, coord string):單擊元素
- double click(locator)
- double click at(locator, coord string)
- drag and drop to object(locator-of-object-to-be-dragged, locator-of-drag-destination-object):拖拽對象
- mouse down(locator):模擬鼠標按鍵按下
- mouse down at(locator, coord-string):根據坐標模擬鼠標按鍵按下
- mouse move at(locator, coord-string)模擬鼠標移動到
- mouse out(locator):模擬鼠標移出
- mouse over(locator):模擬鼠標經過
- mouse up(locator):模擬鼠標按鍵放開
- mouse up at(locator, coord-string):根據坐標模擬鼠標按鍵放開
|
鍵盤 |
- send keys
|
流程控制 |
流程類 |
- do
- if
- else
- else if
- end
- repeat if
- while
- times
|
控制類 |
- wait for element editable
- wait for element not editable
- wait for element not present
- wait for element not visible
- wait for element present
- wait for element visible
|
變量類 |
- store(text, variable-name):將值存儲到變量中
- store attribute(attribute-locator, variable-name):將元素屬性值存儲到變量中
- store text(locator, variable-name):將文本存儲到變量中
- store title(text, variable-name):將標題存儲到變量中
- store value(value, variable-name):將元素value屬性值存儲到變量中
- store window handle(window-handle):存儲窗口操作句柄
- store xpath count(xpath, variable-name):存儲根據xpath方式匹配到的節點數
- execute script(script, variable-name):執行腳本
- execute async script(script, variable-name):執行異步腳本
|
斷言類 |
非阻斷型 |
- verify
- verify checked
- verify editable
- verify element present
- verify element not present
- verify not checked
- verify not editable
- verify not selected value
- verify not text
- verify selected label
- verify selected value
- verify text
- verify title
- verify value
|
阻斷型 |
- assert(variable-name, expected-value):斷言
- assert alert(alert-text):斷言警告框內容
- assert checked(locator):斷言被勾選狀態
- assert confirmation(text):斷言確認框
- assert editable(locator):斷言元素處於可編輯狀態
- assert element present(locator):斷言元素處於存在狀態
- assert element not present(locator):斷言元素不存在
- assert not checked(locator):斷言未被勾選狀態
- assert not editable(locator):斷言元素處於不可編輯狀態
- assert not selected value(locator, text):斷言非應選擇值
- assert not text(locator, text):斷言非預期文本內容
- assert prompt(text):斷言提示框
- assert selected value(select-locator, text):斷言應選擇值
- assert selected label(select-locator, text):斷言應選擇標簽
- assert text(locator, text):斷言文本內容
- assert title(text):斷言頁面標題
- assert value(locator, text):斷言value屬性值
|