Selenium 简明教程
Selenium IDE - Accessors Commands
Selenium IDE 包括三种类型的命令,即 * Actions* 、访问器和 * Assertions* 。访问器命令用于检查应用程序状态,然后将结果存储在变量中。
Selenium IDE consists of three kinds of commands known as the Actions, Accessors, and Assertions. An accessor command is used to check the application state and then store the outcome in a variable.
How to get the Accessors Command?
我们可以通过在 Command 字段中输入 store 来获取 Selenium IDE 中的访问器命令。输入后,所有与商店相关的命令都可以供选择。
We can get hold of the Accesor commands in Selenium IDE, by entering the store within the Command field. Once entered, all the commands related to the store will be available for selection.
Example 1
让我们以以下页面为例,我们在 First Name: 标签旁边输入文本 Selenium ,在 Last Name: 标签旁边输入 Tutorialspoint 。此外,我们将使用 Selenium IDE 获取文本 Selenium - Automation Practice Form ,借助访问器命令。
Let us take an example of the below page, where we would enter the text Selenium beside the First Name: label and Tutorialspoint beside Last Name: label. Also, we would obtain the text Selenium - Automation Practice Form using the Selenium IDE taking the help of the Accessors commands.
要遵循的步骤如下所示 -
The steps to be followed are listed below −
Step 1 − 重复链接 * Selenium IDE Store Variables* 中所述的步骤 1 到 4。
Step 1 − Repeat the Steps 1 to 4 as described in the link Selenium IDE Store Variables.
Step 2 − 工作空间现已在 Selenium IDE 中准备好。
Step 2 − The workspace is now ready in the Selenium IDE.
Step 3 − 在命令字段中输入 open,在目标字段中输入 * 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 − 在命令字段中输入 store,在目标字段中输入 Selenium,在值字段中输入 i。请注意,Selenium 是我们要使用变量 i 输入的值。
Step 4 − Enter store in the Command field, Selenium in the Target field, and i in the Value field. Please note, Selenium is the value we would like to enter using the variable i.
Step 5 − 在命令字段中输入 type,在目标字段中输入 id=firstname,在值字段中输入 ${i}。请注意,id=firstname 是输入框的定位器值,而 ${i} 用于引用我们使用变量 i 要输入的变量值。
Step 5 − Enter type in the Command field, id=firstname in the Target field, and ${i} in the Value field. Please note, id=firstname is the locator value of the input box and ${i} is used to refer to the variable value we would enter using the variable i.
Step 6 − 在命令字段中输入 store,在目标字段中输入 Tutorialspoint,在值字段中输入 j。请注意,Tutorialspoint 是我们要使用变量 j 输入的值。
Step 6 − Enter store in the Command field, Tutorialspoint in the Target field, and j in the Value field. Please note, Tutorialspoint is a value we would like to enter using the variable j.
Step 7 − 在命令字段中输入 type,在目标字段中输入 id=lastname,在值字段中输入 ${j}。请注意,id=lastname 是输入框的定位器值,而 ${j} 用于引用我们要使用变量 j 输入的变量值。
Step 7 − Enter type in the Command field, id=lastname in the Target field, and ${j} in the Value field. Please note, id=lastname is the locator value of the input box and ${j} is used to refer to the variable value we would enter using the variable j.
Step 8 − 在命令字段中输入 store Text,在目标字段中输入 css=div > h1,在值字段中输入 k。请注意,css=div > h1 是我们要获取的文本的定位器值,而 k 用于引用我们要存储获取到的文本的变量值。
Step 8 − Enter store Text in the Command field, css=div > h1 in the Target field, and k in the Value field. Please note, css=div > h1 is the locator value of the text that we would obtain and k is used to refer to the variable value where we would store the text obtained.
Step 9 − 在命令字段中输入 echo,在目标字段中输入 ${k}。请注意,这将打印我们在步骤 10 中访问的文本到 Selenium IDE 中的“日志”下面的网页上。
Step 9 − Enter echo in the Command field, ${k} in the Target field. Please note, this would print the text we accessed in Step10 on the web page under the Log in Selenium IDE.
Step 10 − 在命令字段中输入 store value,在目标字段中输入 id=firstname,在值字段中输入 l。请注意,id=firstname 是输入框的定位器值,而 l 用于引用我们要用来获取输入框中输入的值的变量。
Step 10 − Enter store value in the Command field, id=firstname in the Target field, and l in the Value field. Please note, id=firstname is the locator value of the input box and l is used to refer to the variable we would use to obtain the value entered in the input box.
Step 11 − 在命令字段中输入 echo,在目标字段中输入 ${l}。请注意,这将打印在步骤 7 中输入的值到 Selenium IDE 中的“日志”下面的网页上。
Step 11 − Enter echo in the Command field, ${l} in the Target field. Please note, this would print the value entered in Step7 on the web page under the Log in Selenium IDE.
Step 12 − 在命令字段中输入 close 来关闭浏览器窗口。
Step 12 − Enter close in the Command field to close the browser window.
Step 13 − 单击左窗格中出现的三个点,然后选择“重命名”选项。
Step 13 − Click on the three dots appearing at the left pane, then select the Rename option.
Step 14 − 在“重命名测试用例”字段下输入一个名称,例如 TestCase2,然后单击“重命名”。输入的名称将出现在 Selenium IDE 的左侧。
Step 14 − Enter a name, say TestCase2 under the Rename Test case field, then click on Rename. The entered name would appear on the left of Selenium IDE.
Step 15 − 单击顶部所有测试的运行并等待测试执行完成。在我们的示例中我们会看到执行次数:1 次,失败次数:0 次和一个绿色的条形表示测试已成功运行,没有发生任何故障。而且,日志下显示了消息 TestCase2 已成功完成。
Step 15 − 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 TestCase2 completed successfully appeared under the Log.
在以上的示例中,我们获得了 Selenium - Automation Practice Form 中显示在网页上的文本,并且还检索了 First Name: 标签旁边输入框中输入的值-日志中的 Selenium 。此外,我们在 TestCase2 最上方的测试用例名称旁获得了一个绿色的勾号,表示已通过测试。
In the example above, we obtained the text Selenium - Automation Practice Form which appeared on the web page, and also retrieved the value entered in the input box beside the First Name: label - Selenium under the Log. Besides, we got a green tick beside the test case name - TestCase2 at the top, signifying a passed test.
因此,在 Selenium IDE 中,我们将在测试步骤级别获取有关测试结果的信息,并且仅当所有步骤都成功执行时,我们才将在测试用例级别获得 PASS。
Thus, in Selenium IDE, we would get the information about the test results both at the test step level and only if all the steps would be executed successfully, we would get a PASS at the test case level as well.
此外,我们推断出某个步骤中使用的变量可以在其他步骤中通过语法:${ <variable name> }进一步访问。在步骤 6、7、8、9、10、11、12 和 13 中,我们在测试中遵循了此方法。此外,我们使用了 store 和 store 相关的命令,如 store Text、store Value 等来存储变量。echo 命令用于在日志选项卡下打印这些值。
Moreover, we would infer that variables used in one step can be accessed further in other steps using the syntax: ${<variable name>}. In the Steps 6, 7, 8, 9, 10, 11, 12, and 13, we followed this approach in our test. Also, we had used store and store related commands like store Text, store Value, and so on to store the variables. The echo command was used to print those values under the Log tab.
Example 2
让我们看另一个示例页面,在这里我们将捕获页面标题 Selenium Practice - 通过 Accessors 命令采用单选按钮。
Let us take another example of the below page, where we would capture the page title Selenium Practice - Radio Button taking the help of the Accessors commands.
捕获浏览器标题的步骤如下 −
The steps to capture the browser title are listed below −
Step 1 − 按照上一个示例中的步骤 1 到 4。
Step 1 − Follow steps 1 to 4 from the previous example.
Step 2 − 在“Command”字段输入“Open”,在“Target”字段输入 * Selenium Automation Practice Form* ,以启动应用程序。
Step 2 − Enter open in the Command field, and Selenium Automation Practice Form in the Target field, to launch the application.
Step 3 − 在命令字段中输入 store title,在值字段中输入 pageTitle。请注意,pageTitle 是用于捕获启动的页面标题的变量。
Step 3 − Enter store title in the Command field, and pageTitle in the Value field. Please note, pageTitle is variable to capture the title of the page launched.
Step 4 − 在命令字段中输入 echo,在目标字段中输入 ${pageTitle}。请注意,这将打印在步骤 3 中获得的文本,然后在 Selenium IDE 的日志中进行打印。
Step 4 − Enter echo in the Command field, ${pageTitle} in the Target field. Please note, this would print the text we obtained in Step3 under the Log in Selenium IDE.
Step 5 − 按照上一个示例中的步骤 14 到 17。
Step 5 − Follow steps 14 to 17 from the previous example.
在以上的示例中,我们获得了日志中的页面标题 Selenium Practice - Radio Button 。此外,我们在 Test6 最上方的测试用例名称旁获得了一个绿色的勾号,表示已通过测试。
In the example above, we obtained the page title Selenium Practice - Radio Button under the Log. Besides, we got a green tick beside the test case name - Test6 at the top, signifying a passed test.
此外,我们推断出某个步骤中使用的变量可以在其他步骤中通过语法:${ <variable name> }进一步访问。在步骤 2 和 3 中,我们按照以下方法使用 store title 命令获取页面内容。echo 命令用于在日志选项卡下打印该值。
Moreover, we would infer that variables used in one step can be accessed further in other step using the syntax: ${<variable name>}. In the Steps 2, and 3, we followed this approach in our test along with the store title command to get the page. The echo command was used to print that value under the Log tab.
Conclusion
这总结了我们对 Selenium IDE Accessors 命令教程的全面讲解。我们已经开始介绍如何在 Selenium IDE 中访问 Accessor 命令,并逐步介绍了不同的 Accessor 命令,如 store、store text、store title 等,并说明了如何将它们与 Selenium 一起使用。这让你深入了解了 Selenium IDE 中的 Accessors 命令。最好继续练习你所学到的知识,并探索其他与 Selenium 相关的知识,以加深你的理解,拓展你的视野。
This concludes our comprehensive take on the tutorial on Selenium IDE Accessors Commands. We’ve started with describing how to access Accessor commands in Selenium IDE, and walked through the different Accessor commands like store, store text, store title, and so on and illustrated how to use them along with Selenium. This equips you with in-depth knowledge of the Accessors 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.