📜  Selenium IDE命令

📅  最后修改于: 2020-11-06 01:46:13             🧑  作者: Mango

Selenium IDE-命令(英语)

Selenium命令(也称为“ Selenese”)是在Selenium IDE中运行测试的命令集。使用selenese,可以执行如下活动:

  • 根据HTML标记测试UI元素的存在。
  • 测试特定内容。
  • 测试断开的链接。
  • 测试输入字段,选择列表选项,提交表单和表格数据等。
  • 测试窗口大小,鼠标选项,警报,Ajax功能,弹出窗口,事件处理和许多其他Web应用程序功能。

一串Selenium命令(selenium)一起被称为测试脚本。

selenium命令的类型

Selenium命令基本上分为三类:

  1. Actions
  2. Accessors
  3. Assertions

1.Actions

Actions是通常控制应用程序状态的selenium命令。执行动作会生成事件,例如单击此链接,选择该选项,键入此框等。如果某个动作失败或存在错误,则会停止执行当前测试。

一些最常用的“动作”命令包括:

Command/Syntax Description
open (url) It launches the desired URL in the specified browser and it accepts both relative and absolute URLs.
type (locator,value) It sets the value of an input field, similar to user typing action.
typeKeys (locator,value) This command simulates keystroke events on the specified element.
click (locator) This command enables clicks on a link, button, checkbox or radio button.
clickAt (locator,coordString) This command enables clicks on an element with the help of locator and co-ordinates
doubleClick (locator) This command enables double clicks on a webelement based on the specified element.
focus (locator) It moves the focus to the specified element
highlight (locator) It changes the background color of the specified element to yellow to highlight is useful for debugging purposes.
close() This command simulates the user clicking the “close” button in the title bar of a popup window or tab.
store (expression,variableName) This command specifies the name of a variable in which the result is to be stored and expression is the value to store
waitForCondition (script,timeout) This command executes the specified JavaScript snippet repeatedly until it evaluates to “true”.

2.Accessors

Accessors是Selenium命令,用于检查应用程序的状态并将结果存储在变量中。它们还用于自动生成断言。

一些最常用的访问器命令包括:

Command/Syntax Description
storeTitle (variableName) This command gets the title of the current page.
storeText (locator, variableName) This command gets the text of an element..
storeValue (locator,variableName) This command gets the (whitespace-trimmed) value of an input field.
storeTable (tableCellAddress, variableName) This command gets the text from a cell of a table.
storeLocation (variableName) This command gets the absolute URL of the current page.
storeElementIndex (locator, variableName) This command gets the relative index of an element to its parent (starting from 0).
storeBodyText (variableName) This command gets the entire text of the page.
storeAllButtons (variableName) It returns the IDs of all buttons on the page.
storeAllFields (variableName) It returns the IDs of all input fields on the page.
storeAllLinks (variableName) It returns the IDs of all links on the page.

2.Assertions

Assertions是使测试人员能够验证应用程序状态的命令。断言通常用于断言,验证和等待三种模式。

一些最常用的断言命令是:

Command/Syntax Description
verifySelected(selectLocator, optionLocator) This command verifies that the selected option of a drop-down satisfies the optionSpecifier.
verifyAlert (pattern) This command verifies the alert text; used with accessorstoreAlert.
verifyAllButtons (pattern) This command verifies the button which is used withaccessorstoreAllButtons.
verifyAllLinks (pattern) This command verifies all links; used with the accessorstoreAllLinks.
verifyBodyText(pattern) This command verifies the body text; used with the accessorstoreBodyText.
verifyAttribute(attributeLocator, pattern) This command verifies an attribute of an element; used with the accessorstoreAttribute.
waitForErrorOnNext (message) This command enables Waits for error; used with the accessorassertErrorOnNext.
waitForAlert (pattern) This command enables waits for the alert; used with the accessorstoreAlert.
verifyAllWindowIds (pattern) This command verifies the window id; used with the accessorstoreAllWindowIds.