Selenium 简明教程
Selenium IDE - Actions Commands
Selenium IDE中的所有命令称为Selenese命令。借助 * Selenese Commands* ,我们在Web应用程序上执行每项活动。Selenese命令分为三类−
All commands in Selenium IDE are known as the Selenese commands. With the help of the Selenese Commands we perform every activity on a web application. Selenese commands are of three types −
Basic Actions Commands
下面列出了各种类型的动作命令−
The various types of action commands are listed below −
-
click(locator) − This command is used to click on a link, button, checkbox or radio button.
-
check(locator) − This command is used to check a radio button or checkbox.
-
uncheck(locator) − This command is used to uncheck a radio button or checkbox.
-
choose cancel on next confirmation − This command is used to deal with the next confirmation alert. It will cancel it.
-
choose cancel on next prompt − This command is used to deal with the next alert prompt . It will cancel it.
-
choose ok on next confirmation − This command is used to deal with the next confirmation alert. It will accept it.
-
click At(locator, coordinateString) − This command is used to click on a link, button, checkbox or radio button at a specific location.
-
close − This command is used to close the current window.
-
debugger − This command is used to pause test execution for debugging tests.
-
double click(locator) − This command is used to double click on a link, button, checkbox or radio button.
-
double click at(locator) − This command is used to double click on a link, button, checkbox or radio button at a specific location.
-
drag and drop to object(source locator, destination locator) − This command is used to drag an element from the source locator to the destination locator.
-
echo(message) − This command is used to print the message. It is most commonly used for debugging purposes.
-
edit content(locator, value) − This command is used to enter the value of an editable web element.
-
execute script(script, variable name) − This command is used to execute a JavaScript command within the window or frame in focus.
-
execute async script(script, variable name) − This command is used to execute an async JavaScript command within the window or frame in focus.
-
mouse down(locator) − This command is used to simulate pressing the left mouse button by user(without release).
-
mouse down at(locator, coordinateString) − This command is used to simulate pressing the left mouse button by user(without release) at a specific location.
-
mouse move at(locator, coordinateString) − This command is used to simulate pressing the mouse button by the user at a specific location.
-
mouse out(locator) − This command is used to simulate moving the pointer of the mouse away by user.
-
mouse over(locator) − This command is used to simulate mouse hovering on an element identified by the locator.
-
mouse up(locator) − This command is used to simulate release of the mouse button.
-
mouse up at(locator, , coordinateString) − This command is used to simulate release of mouse button at a specific location.
-
open(url) − This command is used to open a url and wait for the page to load.
-
pause(wait time) − This command is used to stop the execution for some time.
-
remove selection(locator, option) − This command is used to deselect an option in a multi-select dropdown.
-
run(test case) − This command is used to run a test case.
-
select(locator, option) − This command is used to select an option in a dropdown.
-
select frame(locator) − This command is used to select a frame within the window in focus.
-
select window(window handle) − This command is used to select a popup window with the help of the window handle id.
-
set window size(resolution) − This command is used to specify the window size of the browser along with the browser interface.
-
type(locator) − This command is used to enter text in an input box.
Example
我们以以下页面的示例,在其中我们将使用操作命令打开、键入和关闭来启动应用程序和在 Selenium 附近的输入框中输入文本 Name: 。
Let us take an example of the below page, where we would launch the application and enter text Selenium in the input box near Name: using the action commands open, type, and close.
要遵循的步骤如下所示 -
The steps to be followed are listed below −
Step 1 - 按 * Selenium IDE Store Variables* 中所述执行步骤 1 到 4。
Step 1 − Go through the Steps 1 to 4 as described in the link Selenium IDE Store Variables.
Step 2 - 工作空间现在已在 Selenium IDE 中准备就绪。
Step 2 − The workspace is ready in the Selenium IDE now.
Step 3 - 在命令字段中输入打开,在目标字段中输入 * Selenium Automation Practice Form* ,以启动应用程序。
Step 3 − Enter open in the Command field, and Selenium Automation Practice Form in the Target field, to launch the application.
Step 4 - 在命令字段中输入类型,在目标字段中输入 id=name,在值字段中输入 Selenium。请注意,id=name 是输入框的位置值,Selenium 是要输入的值。
Step 4 − Enter type in the Command field, id=name in the Target field, and Selenium in the Value field. Please note, id=name is the locator value of the input box and Selenium is the value to be entered.
Step 5 − 输入 close,在命令字段中关闭浏览器窗口。
Step 5 − Enter close in the Command field to close the browser window.
Step 6 - 单击左窗格中出现的三个点,然后选择重命名选项。
Step 6 − Click on the three dots appearing at the left pane, then select the Rename option.
Step 7 - 在“重命名测试用例”字段下输入一个名称,比如 Test7,然后单击“重命名”。输入的名称将出现在 Selenium IDE 的左侧。
Step 7 − Enter a name, say Test7 under the Rename Test case field, then click on Rename. The entered name would appear on the left of Selenium IDE.
Step 8 - 从顶部单击“运行所有测试”,并等待测试执行完成。在我们的示例中,我们会看到运行次数:1,失败次数:0,以及绿色条表示测试在没有任何失败的情况下成功运行。此外,在日志下面出现消息“Test7 已成功完成”。
Step 8 − Click on the Run all tests from the top, and wait for the test execution to complete. In our example, we would see Runs: 1, Failures: 0, and a green bar denoting the test ran successfully without any failures. Also, the message Test7 completed successfully appeared under the Log.
在上面的示例中,我们使用 First Name: 标签旁边具有 id 定位器的输入框中的文本 Selenium 。此外,在顶部测试用例名称 - Test7 旁边有一个绿色勾选标记,表示已通过测试。所有这些都使用打开、输入和关闭等动作命令成功执行。
In the example above, we entered the text Selenium in the input box using the id locator beside the First Name: label which appeared under the Log. Besides, we got a green tick beside the test case name - Test7 at the top, signifying a passed test. All these were performed successfully using the actions commands like open, type, and close.
Conclusion
这就结束了我们对 Selenium IDE 动作命令教程的全面介绍。我们首先描述了各种动作命令以及如何与 Selenium 一起使用动作命令的示例。这使你具备了对 Selenium IDE 中的动作命令的深入了解。明智的做法是继续练习你所学的内容并探索与 Selenium 相关的其他内容,以加深你的理解并扩展你的视野。
This concludes our comprehensive take on the tutorial on Selenium IDE Actions Commands. We’ve started with describing various actions commands and an example to walk through how to use the actions commands along with Selenium. This equips you with in-depth knowledge of the actions commands in Selenium IDE. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.