http://www.softwaretestinghelp.com/selenium-ide-script-selenium-tutorial-3/
This tutorial is by far one of the most important tutorials to get a hold on Selenium IDE.
This is the 3rd tutorial in our multi-part Selenium Tutorials series. We started this Selenium online Training series from this tutorialwhere you can find list of all tutorials covered.
In the introductory tutorials, we got a brief idea about Selenium IDE and its features.
Going ahead, we would be exercising and implementing these features in real time by creating our own very first Selenium IDE script. Wewould also peek into the details of recording fundamentals and available types of commands in Selenium IDE. Apart from that we would also have a glance at the modifications which can be incorporated into our Selenium scripts.
Before jumping on to the creation of Selenium IDE script, let us take a moment to introduce elementary information about the application under test (AUT).
As a specimen, we would be using “Gmail” – an email service designed by Google. I believe because of its unbounded popularity, it needs no more introductions. The URL we would be using is “https://accounts.google.com”. I have also created dummy credentials to represent test data.
Creating First Selenium IDE Script
So let us now create our first script using Selenium IDE.
The entire script creation process can be classified into 3 chunks:
Process #1: Recording – Selenium IDE aids the user to record user interactions with the browser and thus the recorded actions as a whole are termed as Selenium IDE script.
Process #2: Playing back – In this section, we execute the recorded script so as to verify and monitor its stability and success rate.
Process #3: Saving – Once we have recorded a stable script, we may want to save it for future runs and regressions.
Let us now see their implementation.
Process #1: Recording a test script
Scenario
- Open “https://accounts.google.com”.
- Assert Title of the application
- Enter a valid username and password and submit the details to login.
- Verify that the user is re-directed to the Home page.
Step 1 – Launch the Firefox and open Selenium IDE from the menu bar.
Step 2 – Enter the address of application under test (“https://accounts.google.com”) inside the Base URL textbox.
Step 3 – By default, the Record button is in ON state. Remember to tune it ON if it is in OFF state so as to enable the recording mode.
Step 4 – Open the application under test (https://accounts.google.com) in the Firefox.
Step 5 – Verify if the application title is correct. To do so, right click anywhere on the page except the hyperlinks or images. The right click opens the Selenium IDE context menu listing few of the commands. To get an entire list, select “Show Available Commands” option. This will open another menu containing rest of the available and applicable commands. Select “assertTitle Sign in – Google Accounts” option to verify the page title.
(Click to view enlarged image)
As soon as we click on “assertTitle Sign in – Google Accounts” option, a test step would be included /appended in the Selenium IDE editor.
Step 6 – Enter a valid username in the “Email” Textbox of Gmail.
Step 7 – Enter a valid password in the “Password” Textbox of Gmail.
The simulation of the same user actions can be seen in the Selenium IDE test editor.
Notice that for the ease of understanding, I have already created test credentials. I would strictly advise the readers to create their own credentials instead of using these.
Step 8 – Click on the “Sign in” button to complete the login process.
User should be re-directed to the home page provided the credentials entered are correct.
Step 9 – At the end, we would end the recording session by tuning the record button into OFF state. Below is the recorded script.
Process #2: Playing back / executing a test script
Now that we have created our first Selenium IDE script, we would want to execute it to see if the script is stable enough. Click on the playback button to execute the script.
Post execution, all the test steps would be color coded in green for the successful run. The same would be evitable from the test case pane.
For unsuccessful execution or test case failure, the failed test step would be highlighted in red. And the test case pane would mark the test case execution as failure.
Process #3: Saving a test script
Once, we have played back the script, now it’s time to save the created test script.
Step 1 – To save the test script, Click on the File menu and select “Save Test Case” option.
Step 2 – The system will prompt us to browse or enter the desired location to save our test case and to provide the test script name. Furnish the test name as “Gmail_Login” and click on the “Save” button.
The test script can be found at the location provided in the above step. Notice that the test script is saved in HTML format.
Using Common features of Selenium IDE
Setting Execution speed
While testing web applications, we come across several scenarios where an action performed may trigger a page load. Thus we must be cognizant enough while dealing such scenarios.
So to avoid failures while playing back these test scenarios, we can set the execution speed to be minimal. Refer the following figure for the same.
Using “Execute this command” option
Selenium IDE allows the user to execute a single test step within the entire test script without executing the entire test script. “Execute this command” is the option which makes this obtainable.
“Execute this command” option can be used at times when we want to debug/see the behavior of a particular test step.
“Execute this command” option can be used in the following four ways:
#1. Using Actions tab from the Menu bar
#2. Using short cut key (“X”)
#3. Right click the test step and select “Execute this command”
#4. Double click the test step
In all the above cases, user is expected to select the test step which he / she want to execute.
Steps to be followed:
Step 1 – Launch the web browser and open the target URL (“https://accounts.google.com”), Select the test step that we desire to execute. Remember to open correct web page to mitigate the chances of failure.
Step 2 – Press “X” to execute the selected test step. Alternatively, one can use other ways too.
Step 3 – Notice that the selected test step is executed. The test step would be color coded in green for success or red for failure. At the same time, the test step would be simulated into an action on the web browser.
Note that the user is responsible to bring the script before executing the test step and Firefox in context. There is a probability of failure if the user has not opened the legitimate web page.
Using Start point
Selenium IDE allows the user to specify a start point within a test script. The start point points to the test step from where we wish to start the test script execution.
Start point can be used at times when we do not desire to execute the entire test script starting from the beginning rather we customize the script to execute from a certain step.
Start point can be set and clear in the following three ways:
#1. Using Actions tab from the Menu bar
#2. Using short cut key (“S”)
#3. Right click the test step and select “Set/Clear Start Point”. Menu similar to above image will be displayed.
In all the above cases, user is expected to select the test step from where he wants to start the execution prior to setting start point.
As soon as the user has marked the test step to indicate the start point, an icon gets affixed to it.
Now whenever we execute the test script, it execution would be started from the start point i.e. fourth line (type | id=Passwd | TestSelenium) of the test script.
Notes
- There can be one and only one start point in a single script.
- The start point can be cleared in the same way it was set.
- User is responsible to bring the script after applying start point and Firefox in context. There is a probability of failure if the user has not opened the legitimate web page.
Using Break point
Selenium IDE allows the user to specify break points within a test script. The break points indicate Selenium IDE where to pause the test script.
------------
Break points can be used at times when we desire to break the execution in smaller logical chunks to witness the execution trends.
Break point can be set and clear in the following three ways:
- Using Actions tab from the Menu bar
- Right click the test step and select “Toggle Breakpoint”.
- Using short cut key (“B”)
As soon as the user has marked the test step to indicate the break point, an icon gets affixed to it.
Now whenever we execute the test script, the execution pauses at the break point i.e. fourth line (type | id=Passwd | TestSelenium) of the test script.
Apply multiple breakpoints
Selenium IDE allows user to apply multiple breakpoints in a single test script. Once the first section of the test script is executed, the script pauses as and when the breakpoint is reached. To execute the subsequent test steps, user is required to execute each of the test steps explicitly.
In the above test script, the execution pauses at the line “assertTitle | Sign in – Google Accounts”. After explicitly executing this test step, the control moves to the next test step in sequence “type | id=Email | TestSelenium1607@gmail.com”. Thus, user needs to explicitly execute this test step. The similar trend is followed for rest of the subsequent steps.
Thus, this feature lets the user to spend more time executing each step and reviewing the outcomes of the previously executed test step.
Notes
- There can be as many break points as you wish in a single script.
- The break point can be cleared in the same way it was set.
Using Find Button
One of the most crucial aspects of Selenium IDE test scripts is to find and locate web elements within a web page. At times, there are web elements which have analogous properties associated with them, thus making it challenging for a user to identify a particular web element uniquely.
To address this issue, Selenium IDE provides Find button. The Find Button is used to ascertain that locator value provided in the Target test box is indeed correct and identifies the designated web element on the GUI.
Let us consider the above created Selenium IDE test script. Select any command and notice the target text box. Click on the Find button present just beside the Target text box.
Notice that the corresponding web element would be highlighted in yellow with a fluorescent green border around it. If no or wrong web element is highlighted, then the user is required to rectify the issue and would need to impose some other locator value.
(Click to view enlarged image)
Thus, this procedure makes the user assured about the target value being used and that it corresponds to the correct web element on the GUI.
Using Other Formats
Converting Selenium IDE test scripts to Other Programming Languages
Selenium IDE supports conversion test scripts into set of programming languages from a default type (HTML). The converted test scripts cannot be played back using Selenium IDE until and unless it is reverted back to HTML. Thus the conversion is beneficial and constructive only when we are executing it from other tools of Selenium Suite.
Step 1 – Click on the options tab under the menu bar and select the programming language format under format option in order to convert the test script into our desired format.
Step 2 – As soon as we select our Desired Programming language format (“Java / JUnit4 / WebDriver” in our case), a prompt box appears which says “Changing format is now marked experimental! If you continue, recording and playback may not work, your changes may be lost and you may have to copy and paste the test in a text editor to save. It is better to make a copy of your test cases before you continue. Do you still want to proceed?” Click “OK” to continue.
Thus, the above converted code can be executed by using WebDriver.
Mark that editing or modifying Selenium IDE test scripts from Source View is not advisable. If done so, the tool might introduce several repercussions. Several known bugs are already associated with it.
Selenium IDE Commands
Each Selenium IDE test step can chiefly be split into following three components:
- Command
- Target
- Value
Types of Selenium IDE commands
There are three flavors of Selenium IDE commands. Each of the test step in Selenium IDE falls under any of the following category.
- Actions
- Accessors
- Assertions
Actions
Actions are those commands which interact directly with the application by either altering its state or by pouring some test data.
For Example, “type” command lets the user to interact directly with the web elements like text box. It allows them to enter a specific value in the text box and as when the value is entered; it is showed on the UI as well.
Another example is “click” command. “click” command lets the user to manipulate with the state of the application.
In case of failure of an action type command, the test script execution halts and rest of the test steps would not be executed.
Accessors
Accessors are those commands which allows user to store certain values to a user defined variable. These stored values can be later on used to create assertions and verifications.
For example, “storeAllLinks” reads and stores all the hyperlinks available within a web page into a user defined variable. Remember the variable is of array type if there are multiple values to store.
Assertions
Assertions are very similar to Accessors as they do not interact with the application directly. Assertions are used to verify the current state of the application with an expected state.
Forms of Assertions:
#1. assert – the “assert” command makes sure that the test execution is terminated in case of failure.
#2. verify – the “verify” command lets the Selenium IDE to carry on with the test script execution even if the verification is failed.
#3. waitFor – the “waitFor” command waits for a certain condition to be met before executing the next test step. The conditions are like page to be loaded, element to be present. It allows the test execution to proceed even if the condition is not met within the stipulated waiting period.
Commonly used Selenium IDE commands
open | Opens a specified URL in the browser. | 1 |
assertTitle, VerifyTitle | Returns the current page title and compares it with the specified title | 1 |
assertElementPresent, verifyElementPresent | Verify / Asserts the presence of an element on a web page. | 1 |
assertTextPresent, verifyTextPresent | Verify / Asserts the presence of a text within the web page. | 1 |
type, typeKeys, sendKeys |
Enters a value (String) in the specified web element. | 2 |
Click, clickAt, clickAndWait |
Clicks on a specified web element within a web page. | 1 |
waitForPageToLoad | Sleeps the execution and waits until the page is loaded completely. | 1 |
waitForElement Present |
Sleeps the execution and waits until the specified element is present | 1 |
chooseOkOnNext Confirmation, chooseCancelOn NextConfirmation |
Click on ”OK” or “Cancel” button when next confirmation box appears. | 0 |
Conclusion
In this tutorial, we tried to make you acquainted with the creation of Selenium IDE scripts. We also briefed you about the usage of various Selenium features.
Here are the cruxes of this article.
- Test script in Selenium IDE can be created using Record and Playback feature.
- The script creation mechanism can be divided into 3 processes –Recording, Playing back and Saving the test script.
- Selenium IDE allows the user to execute a single test step within the test script without executing the entire test script. “Execute this command” is the option which makes this obtainable.
- User is leveraged to set the execution speed from the option within the toolbar.
- User can define any test step as a Start point. Thus, the execution will always initiate from that particular test step only.
- User can set multiple Break points to pause the execution at a certain test step.
- User can find and verify if the provided target value corresponds to the correct web element within the web page using Find
- Changing the source view to other formats is not recommended as there is a probability of loss of data.
- Remember to keep a copy of HTML test script before converting the test script into other non HTML formats.
- There are majorly three types of commands – Actions, Accessors and Assertions.
- Actions directly interact with the application and alter its state.
- Accessors are used to store an elements property in a user defined variable.
- Assertions are used to check if a specified condition is met or not.
- Assertions can further be categorized as verify, assert andwaitFor commands.
- Verify makes sure that the test script execution is never halted if even if the verification fails.
- Assert lets no further execution of the test script in case of failure.
- WaitFor waits for a stipulated period for a certain condition to meet.
-
Some of the Selenium IDE commands which are used commonly are:
- open
- assertTitle / VerifyTitle
- AssertForElementPresent / VerifyForElementPresent
- AssertForTextPresent / VerifyForTextPresent
- type / typeAndWait / sendKeys
- click /clickAt / clickAndWait
- waitForPageToLoad
- waitForElementPresent
- chooseOkOnNextConfirmation / chooseCancelOnNextConfirmation
Next Tutorial #4: There is another tool which plays a very important role in assisting us to create effective test scripts known as “Firebug”. Firebug helps us in inspecting the properties of web elements and web pages. Thus the next tutorial is comprised of installation of Firebug and its usability. We would also create a test script manually using firebug and Selenium IDE.
Note: Do not miss the next tutorial because of its great importance with respect to our forthcoming tutorials on WebDriver.
相关推荐
selenium tutorial Selenium Tutorials 32 Best Free Selenium Training Tutorials Posted In | Automation Testing, Selenium Tutorials | Last Updated: "December 14, 2016
java -jar selenium-server-standalone-3.141.59.jar (用您的jar文件名替换jar文件名) 这将在本地主机和端口4444上运行Selenium 从安装Node.js 运行示例: 下载示例 选项1: git clone ...
Applitools教程-Selenium Java-超快速网格 通过此Ultrafast Grid示例开始使用Applitools Eyes视觉测试,该示例使用 ,Java和在Applitools云中运行测试。 通过我们的了解有关如何安装和启动该项目的更多信息! 更多...
(Images Legacy) Selenium(Selenium3) (WDIO4) eye (WDIO4 服务) -webdriverio (WDIO5) eye (WDIO5 服务) (Cypress) (故事书) (LeanFT)教程 https://github.com/applitools/tutorial-...
3. Selenium IDE:这是一个集成在Firefox中的插件,用于录制和回放测试脚本。它是初学者快速上手Selenium的好工具。 4. Selenium Grid:用于分布式测试,可以同时在多台机器上运行测试,提高测试效率。 在Eclipse...
Eclipse- https://courses.in28minutes.com/p/eclipse-tutorial-for-beginners Maven- https://courses.in28minutes.com/p/maven-tutorial-for-beginners-in-5-steps JUnit- ...
本教程“selenium-tutorial”旨在引导用户了解如何利用Java有效地编写Selenium WebDriver测试。 首先,我们要了解Selenium WebDriver。WebDriver是Selenium的最新接口,它允许与各种浏览器进行直接通信,实现跨...
"ecommerce-tutorial-planning"项目旨在为初学者提供一个逐步学习电子商务系统开发的框架。在这个项目中,我们将涵盖从需求分析到系统实现的整个过程,确保你能够掌握核心的Java编程技能以及电子商务系统设计的关键...
# Unix或MacOS上激活虚拟环境```shellsource tutorial-env/bin/activate```# windows上激活虚拟环境```shelltutorial-env\Scripts\activate.bat```# 安装requirement.txt依赖```shellpip install -r requirements....
分布式爬虫从零开始从零学习python爬虫欢迎在issues中留言,如果文章中有错别字可以向我提pr,感谢各位!目录实例目录文献整理http知识百度百科来自简书Chrome控制台官方教程来自知乎Requests使用官方中文文档JSON...
search_box.send_keys("Selenium Tutorial") search_box.submit() ``` ### 5. 断言与等待 在编写测试脚本时,我们通常会使用断言来验证预期结果。Python的unittest或pytest库中的assert语句可以用于此目的。此外,...
Selenium Remote Control(简称SRC)是Selenium Suite的一个组件,它允许通过编程语言来控制Web浏览器,主要用于自动化Web应用程序的测试。在Java环境中,我们可以结合JUnit框架进行测试脚本的编写。这篇教程的第二...
实习生Esri-jsapi 这是有关使用实习生对esri JavaScript API应用进行单元测试/功能测试... 要在Selenium中运行测试,请阅读Selenium部分中的注释。第2步: 使用npm安装intern,grunt和其他开发依赖项: cd < path>npm
本教程提供了安装Python、Selenium的Python客户端驱动、HTMLTestRunner以及Eclipse集成开发环境和PyDev插件的详细步骤,这些都是为了在自动化测试开发中使用Selenium进行测试所必需的。 首先,我们需要安装Python。...
3. **BeautifulSoup结合**:虽然Selenium可以提取页面内容,但解析HTML更方便的库如BeautifulSoup可以与Selenium结合使用,提高数据提取效率。 **异常处理和优化** 1. **错误处理**:在编写爬虫时,应考虑可能遇到...
数据分析师薪酬项目创建了一种估算数据分析...Selenium,烧瓶,泡菜刮板文章: ://towardsdatascience.com/selenium-tutorial-scraping-glassdoor-com 网页抓取受到上述scaper文章的启发,我调整了github存储库,以从G
УрокипоSelenium。 Python Полезныессылки: Chromedriver: https://chromedriver.storage.googleapis.com/index.html Geckodriver-Mozilla Firefox浏览器: ...
java教程 这些是带有 Selenium 风格的 Java 程序教程。 一旦您精通 java,那么您就可以使用 Selenium 测试框架(链接如下)来编写您的 selenium 测试。 可以在此处访问相应的 java 视频教程。
在这个“Python-crawler-tutorial-starts-from-zero-master”教程中,你将逐步学习这些技能,并实践于实际项目中。教程可能包含了从安装环境、基本语法介绍,到各个模块的实战应用,最后是整个项目的整合。通过这个...
- **内置函数**:QTP提供一系列内置函数,如Selenium-like函数,用于辅助脚本编写。 - **自定义函数**:用户可以创建自己的函数库,提高代码复用性和可维护性。 9. **异常处理**: - **错误处理**:通过Try......