- What is Selenium?
- Selenium Basic Terminology
- Features of Selenium
- Limitations of Selenium
- Selenium Vs QTP
- IDE (Selenium Integrated Development)
- Selenium IDE Installation
- Selenium IDE Features
- IDE First Test Case
- Selenium-IDE Login test
- Selenium IDE- Commands (Selenese)
- IDE Locating Strategies
- Selenium Web driver
- What is Selenium Grid?
- Conclusion
- Selenium Tutorial FAQs
What is Selenium?
Selenium is an open-source tool and portable framework that is used for automating the tests administered on web browsers. It is only used for testing web applications such as Shopping Carts, Email Programs like Gmail, Yahoo.
Testing done using Selenium is often referred to as Selenium Testing.
Selenium is not just a single tool, as it is a collection of softwares, and each tool has different cases of testing.
Now, you might be wondering, who created Selenium?
Selenium was introduced by Jason Huggins in 2004. Jason Huggins an Engineer at Thoughtworks. He was doing his work on some web application and he suddenly required testing.
He realized that mundane Manual Testing (used to identify bugs, issues, and defects in software) of their application was turning to be more and more ineffective.
He created a JavaScript Program that would instinctively control the browser’s action. And he named the program “JavaScriptTestRunner” and later he made JavaScriptTestRunner as an Open Source that was later renamed as Selenium core.
Selenium Basic Terminology
Before we start with this terminology, let us learn selenium basic principles connected with an application’s Automation research.
With the growing need for products related to software, each software development community requires to hold out a series of tests before the ultimate product is released into the market.
Test engineers aim to detect the errors or bugs before the software package is released, but there are often flaws within the delivered software. Also for the strongest manual verification procedures, there’s still a risk that the finished software package is going to be left with a flaw or that it’s not going to be ready to fulfill the user requirements.
Automation Testing
Selenium Automation Testing uses the resources that are advanced to enhance achievement without any human interference. These testing tools access the test data, control the fulfillment of the real result and help Automation Testing relate the actual result against the anticipated result.
Selenium Automation Testing enfold (cover) Functional and Performance tests on web Application:-
- Regression tests which are repeated in nature, are automated mechanized. And this is the example of Functional Automation that is primarily used for the automation of functional test instances.
- Automation of performance is employed to eliminate the non-functional output test cases. For eg, measure the application’s response time under reasonable load.
Note:- Performance testing using Selenium and WebDriver is usually not advised. Not because it’s incapable, but because it’s not optimised for the work and you’re unlikely to urge good results.
Automation Testing tools that are pre-owned to Functional operations:-
- Auto It, open Source.
- Unified Functional Testing (UFT)
- Selenium, it’s Open Source
- Parasoft SOAtest
Automation Testing tools which are pre-owned for nonfunctioning automation:
- JMeter, by Apache
- Loadster,
- Webserver Stress Tool
- Acunetix, provided by Acunetix
Why Automated Testing?
Automated Testing has numerous advantages for improving the efficiency ability of a Software. The key benefits are as follows:
- Big software organizations often use Automated Testing because it is very expensive and difficult for small countries to implement
- Manual Testing for all workflows, all negative scenarios, and fields, are time-consuming and expensive
- Infinite Iterations are provided for test case execution
- Less errors as compared to manual testing
- Automation testing supports constant regression testing
- Disciplined documentation provided for test cases.
- Provides quick feedback to the developer
- Automated Testing can audiovisual (playback) pre-recorded and predefined actions
Test Automation for Web Applications
If we take a glance at the sort of software applications prevailing in the current market framework, most of the software applications are written as web-based applications to be run in an online browser.
The testing strategy for web-based applications varies widely among companies and organisations. In a stage of highly interactive and responsive software processes where many organisations are using some sort of nimble procedure, test automation is usually becoming a requirement for software projects.
The most effective manner to hold out test automation for web applications is to adopt a pyramid testing strategy.
This pyramid testing scheme includes automation tests at three non-identical levels.
- Unit testing represents the bottom and largest percentage of this test automation pyramid.
- service layer, or API testing. and eventually,
- GUI tests sit at the highest.
The pyramid looks something like this:
Features of Selenium
Selenium is gaining popularity because of its insane features like:
- Selenium supports multiple browsers: Selenium supports multiple browsers like Google Chrome, Safari, Firefox, Opera, etc. One can launch any browser by just giving simple commands.
- Multiple Programming Languages Support: Selenium supports multiple programming languages for writing test scripts. It includes Java, python, “C#”, Perl, etc.
- Momentum(Speed) and execution: There is no need for an intermediate server as Selenium directly conveys with the browser.
- Easy to Identify and use web elements: Locators in Webdriver helps in finding the web elements in web applications. This advantage is very easy for testers to implement.
- Open Source and Portable : It is a major benefit that Selenium is Open-Source and portable. Selenium can be downloaded from its official site from https://www.selenium.dev/downloads/
- Works On different Operating System : Selenium web driver scripts can work on different OS such as Linux, MAC, Chrome.
- Simple Commands :Selenium has very simple commands to implement. It can be learnt easily.
- Server Installation Not Required Selenium Web Driver is not required to Install a server, as it interacts directly with the browser.
Some More Key Features are:-
- Selenium Automation Tool requires very few tools as compared to other automation tools.
- Selenium can be desegregated with testing frameworks.
- Parallel test execution is also supported as that reduces time and increases the efficiency of tests.
- Pipelines Such as Continuous Integration and Continuous Delivery can be integrated with Selenium.
- There are also many kinds of testing that can be automated using Selenium. Some are- Unit Testing, Regression Testing, Automated Browser Testing.
- It is widely used in the web development domain.
Limitations of Selenium
- Selenium is only used for testing web applications not any software or GUI’s
- Mobile Automation can’t be done by Selenium itself.
- Captchas are not automated using Selenium.
- Inbuilt Reporting feature is not available in Selenium.
- Selenium isn’t accurate in handling dynamic web pages.
- Selenium faces some problems in handling frames and pop-ups.
- Enormous timeout, sync, and page loading issues.
- The irresponsibility of new features. They may work or may not.
- Test Integration tool is not provided for Test Management.
- Barcodes can’t be automated using Selenium.
- Automation analysis can’t be performed on web services like SOAP Or REST.
- Selenium can’t perform testing on images.
- High skillsets are required for automating test tools.
- Selenium depends on Cucumber for reporting. (Learn Cucumber today!)
Selenium Vs QTP
Let us first learn a little bit about QTP.
QTP (QuickTest Professional) is a Product of HP. This tool helps testers to perform automated functional testing seamlessly, without observing, once script development is complete.
Now, let’s compare Selenium and QTP
Selenium | QTP |
Open source tool as it doesn’t require a license to be used | The commercial user-friendly tool as it requires a license and hence is expensive. |
Various Environments are supported Like MAC, Linux, Windows, etc. | Only One Supported “Windows” |
Supports Automation Only for web Applications. | Supports Automation for web and desktop applications. |
Low Resource utilization during test Script Execution. | High Resource Utilization. |
Multiple Supported Programming Languages like Java, Python, Perl, etc. | Only One Supported Programming Language is VB Script. |
Selenium has less functionality and hence takes much time to develop. | QTP is Friendly with users and test scripts are quickly developed. |
Object Repository and Recovery Scenario is absent. | Built-in Object repository and Recovery Scenario. |
Built-in tools are not available for parametrization. | Built-in tools are available for parameterization. |
Browser Controls are None. | Controls Such as the favorites bar, forward buttons can access using the browser. |
It Requires External Tool For Giving Reports. | Built tools are available for giving reports. |
Community Forums are available for Customer Support. | Dedicated HP Support. |
Supported Browsers are chrome, safari, firefox, Yahoo, etc. | Specific Version of Chrome, Firefox, Internet Explorer. |
Widely Range IDE Like VS Code, Eclipse, Netbeans. | QTP tests can only be developed using QTP IDE. |
Automation Testing Using Selenium has less Cost. | Automation Testing Using QTP has Expensive Costs due to its license costing. |
Test Scripts Require To Be Updated. | Backward Association is Powerful. |
Key Differences Between QTP and Selenium are:-
- Selenium is Open-Source as it doesn’t require a License. Whereas, QTP requires license to be used
- Selenium is used for web applications. QTP can be used for web and desktop applications
- Selenium Automation tool costs less. Whereas, QTP is expensive
- Less functionality. Hence, takes so much time to develop and maintain. Test Scripts can be quickly done because of its user-friendly nature
- Selenium supports multiple programming languages. Whereas, QTP supports only one.
Now let’s talk about IDE (Selenium Integrated Development) in-depth.
IDE (Selenium Integrated Development)
Selenium integrated tool is the easiest web automation tool present in the selenium suite. It is very easy to learn.
It is an add-on of firefox so that tests are created quickly through its works and functionality. This feature is similar to QTP.
It is so simple, and thus, is only used for prototyping tools and not for developing complex test suites.
Even so, you will be able to use Selenium IDE as you don’t need any programming knowledge. Familiarity with Html, JavaScript, DOM is recommended if you wish to use IDE perfectly.
Some knowledge of JavaScript is required for learning Selenese “runscript”.
When creating tests, Selenium supports autocomplete mode for the following purposes:
- Helps to enter commands quickly.
- Restricting users from entering the wrong command.
Note:
- Selenium IDE only supports Firefox and Chrome plug-in, which means you are not able to record your test cases other than these two. But, it can be exported in multiple programming languages like Python, Perl, Java, C#.
Selenium IDE Installation
As you all know, Selenium IDE is only in Mozilla Firefox and Chrome plug-in. So I assume that you had pre-installed firefox. If not, you can go to the link below and simply download it from here.
Steps For Downloading Selenium IDE and Installing it:-
- Launch your Installed Firefox browser.
- Click Here and You Will be Redirected to the page of firefox where you have to download it.
- Click add to Firefox
- A Popup Will Come then allow that and your Selenium IDE Has Installed
- Restart your browser
- Top right corner of your firefox browser and look for the Selenium IDE
- Click on That Icon and Your Selenium has been launched.
Now that we are done with the Selenium Installation, we are ready to move further ahead in this Selenium Tutorial. We now have all the tools that are required before learning more about Selenium IDE.
Selenium IDE Features
Selenium IDE has various components. Each component has its features for what they are designed. Given below is the diagram by categorizing its components.
- Menu bar Component
- Test Case Pane
- Toolbar
- Address bar
- Test Script Editor box
- Log, Reference Pane
- Stop and Start Button
- Menu bar
Menu Bar is very handy when working with Selenium IDE. It is located at the topmost of the IDE Interface.
- Project Name
You can Edit or Rename your project.
- Open Project
If you have any personal project.
- Save Project
You can save your existing project.
- New Project
If you want to make a new project, you can click on the new project icon.
All the labeled diagrams are shown below.
Now. Let’s Talk About The Toolbar.
- Toolbar
All the execution of your test cases is controlled by the toolbar. It gives you a step feature of debugging your test scripts. The most commonly used modules for Toolbar are:
- Speed Control Option
It allows you to control the speed of execution of test cases.
- Step Feature
Step feature helps step into each specific command in the test script and it is used for debugging the test cases.
- Run Tests And Run All Tests
Run test allows you to run the selected tests. Whereas, run all allows you to run all tests.
Tip:-
ShortCut for Run Tests is Ctrl + R
ShortCut For Run All Tests is Ctrl + Shift + R
- Address Bar
The current URL is shown in the address bar. When we click on the drop down, it displays all the previously visited websites as a part of automation.
The below diagram shows the address bar in IDE.
- Test Case Pane
Recorder modules by IDE are contained in this module. It is a list of recorded test cases by IDE.
The selection of test cases from the test case can be done using the test case pane.
- Test Script Editor Box
As depicted within the diagram below, the Test Script Editor Box contains the user interactions that are recorded within the sort of Test Steps in Selenium IDE.
Each and every recorded test step contains values under the three columns i.e. Command, Target, and Value.
For example, if you record the typing of QAFox text into the search box field on the QAFox.com website.
The commands are going to be typed. The target is going to be the locator for locating the Search box field. The values are going to be the text that’s typed into the Search box field.
- Command
Commands are often considered because of the actual operation/action that’s performed on the browser elements. For example, if you’re opening a replacement URL, the command is going to be ‘open’; if you’re clicking on a link or a button on the online page, then the commands are going to be ‘clicked’.
- Target
Target specifies the online element on which the operation has got to be performed alongside a locator attribute.
- Value
Value is treated as an optional field and may be used once we get to send some actual parameters. As an example, if you’re entering the e-mail address or password during a textbox, then the worth will contain the particular credentials.
- Start/Stop Recording Button
It records all the user action to the browser.
- Log, Reference Pane
The Log pane will display the runtime commentary/messages during the execution of the chosen test.
The reference pane will display the small print of the command within the currently selected test step within the Test Script Editor Box.
IDE First Test Case
In this part, you will learn to create a basic test case in your Selenium IDE.
Given below are the three steps to follow to create your first test case:
- Recording (Recording of browser interaction between the user)
- Audiovisual (Playback) (The Recorded Script accomplishing)
- Liberate the test suites or save it
Let’s discuss each step in a detailed manner.
- Recording
- Initiate(Start) your Firefox.
- There is the Selenium Icon at the top right-most, Click on that icon, and your Selenium IDE will be launched. Downloading and setting up is shown above.
- You will see the default interface as shown above.
- You can name the project as you wish to. I am renaming it as Great Learning Project.
- Rename the test event as you wish. I will be naming it as Selenium Tuts.
- At the top right corner of the IDE, you will find Start/Stop Recording Tab, click on that to start recording your test case.
- Let me show you something interesting. Go to your firefox and search for the Great Learning blog and click on any particular blog of Great Learning.
- Make sure your recording tab is on in your IDE.
- Now, you will see all actions done by you in the selenium IDE being recorded.
- Now stop the recording in your Selenium IDE.
- And you will see all the browser interactions that you have done.
2.Playing Back
- Click on the Run Current test tab as shown above that is present on the toolbar menu in your Selenium IDE.
- What it will do is that It executes all the interactivity with the browser and handover all the summary of the executed test script.
- The Log and Reference pane component displays all the summary of all the executed test scripts.
3.liberate the test suites or save it
- Click on the Save button at the rightmost of your Selenium IDE.
- Save as “Selenium Review”
- The Saved Test Suite Extension is “SIDE”.
Note:- If you are unfamiliar with the above topics like toolbar, recording button, etc, you will find the topic “SELENIUM IDE”. Start learning from there, and you will understand it all.
Selenium-IDE Login test
In this part, we are going to do a Login Test in Selenium IDE. For educational purposes, we will use the Joodle Website for Testing. You can find that particular URL:- https://www.jdoodle.com/ . Go to this site.
The default look of this website is something like this:
This is the default look. Now, let us start learning.
Firstly, we have to register here, and then we will sign up. Now we are going to create a test script for login/sign-up in Selenium IDE.
The steps to be followed are given below:
Recording
- Open your Firefox Browser.
- At the top right corner, you will find the Selenium icon, hit on that. Now your Selenium IDE is Launched.
- Go to the Firefox browser and then go this URL:- https://www.jdoodle.com/
- Enter the project name as –Login_Test
- Enter the Test Event name as- First_Test
- Now click on the start recording button to keep track of all action done by the user.
- Go to your firefox browser and right-click and select the Selenium IDE Option.
- Then select the assert title. This prescribes that your title is correct.
- Click on the Sign-up Button to sign up with your email.
- After Signing-up, you will get an email to activate click on activate. Now you are done.
- Now go to the login section. You will have to fill in your provided credentials.
- This website provides an online text editor and compiler for multiple languages.
- Click on any programming language you want.
- Go back to your profile and then logout from there.
- Go to your Selenium IDE Interface, click on stop recording.
Playing back
- Click on The “Run Current Test Tab”. The Actions by browsers are executed and then it gives the overall summary of the test scripts.
2 . The Execution process of all the execution tests are displayed on the log pane.
Save Project:-
- Click on the save project button.
- Save the project whatever you want to name it.
- In the future, if you want to work on this project you can go to the open project option.
Selenium IDE- Commands (Selenese)
Selenium commands also referred to as Selenese is the place of commands implemented in Selenium IDE that run your tests. A sequence of Selenium commands (Selenese) together is understood as a test script. Using Selenese, one can perform activities like:
Testing the existence of UI elements supported their HTML tags.
Testing is done for specific content.
Testing is done for broken links. Assessing the window size, mouse options, alerts, Ajax functionality, pop-up windows, event handling, and much more.
Note: Test Scripts are the sequence of Selenium Commands or Selenese.
Simplicity commands are classified into different types, let’s see.
Types of Selenium Commands:
Primarily there are three types of commands that are classified in Selenium IDE:
- Actions
- Accessors
- Assertions
Now, in these three types, there are several commands that we are going to see.
- Actions
The state of application is generally manipulated from the Actions Commands in Selenium IDE.
Some of the most frequently used Actions Commands are given below:
Commands | Description | Arguments |
click at | The coordinates are correlative to the target element and it clicks on the target element and they are used to check effects. | Locators coord string |
open | In This Case, it opens the URL and the URL is accepted is both relative and absolute URLs | URLs |
type | It Sets the value of an input field, as you typed it in. Also Used to set values for combo boxes. | locator, value |
typeKeys | Keystroke events are simulated on the specified element. | locator, value |
doubleClick | dual Click on an element. | locator |
focus | moves the focus to the specific element | locator |
highlight | background colors are changed to yellow of a particular element. | locator |
close | It Closes one window, no need to close the initial window. | |
store | Easy reuse, it saves the target string | text, variable name |
waitForCondition | It Evaluates to “true” until and unless the specified javascript executes. | script, timeout |
- Accessors
Accessors are the selenium IDE commands that inspect the application state and the result in variables is stored. They also automatically generate assertions.
Commands | Description | Arguments |
store title | Gets the title of the current page. | text, variable name |
storeValue | It Gets the value of an element and they are kept for future use. | locators, variable name |
storeTable | This Command Extracts the text from the cell of the table. | tableCellAddress, variableName |
storeAllFields | ID’s of all the input fields are returned. | variableName |
storeAllLinks | It returns the ID’s all the links. | variable Name |
storeText | This Command gets the text from an element and stores it for future use. | locator, variable name |
storeLocation | This command gets the absolute URL of the particular page. | variableName |
storeBodyText | This Command gets the entire text from the current page. | variableName |
storeAllButtons | ID’s of All The Buttons are returned. | variableName |
storeElementIndex | It Gets the relative of an element starting from 0 to its parent. | locator, variableName |
- Assertions
Assertions commands are generally used for authorizing testers to substantiate the state of the Application.
Some of the widely used commands in selenium IDE are given below:
Commands | Description | Arguments |
verifySelected | This Command confirms that the chosen option of a drop-down persuades the option specifies. | selectLocator, optionLocator |
verifyAllLinks | This command confirms all the links used with the accessorstoreAllLinks. | pattern |
verifyAlert | This Command confirms the Alerttext; used with accessorstoreAlert. | pattern |
verifyBodyText | This Command Confirms the body text used with some commands | pattern |
verifyAttribute | This Command confirms the features of an element used with the accessorstoreAttribute. | attributeLocator, pattern |
verifyAllWindowIds | This Command confirms the windows id. | pattern |
waitForAlert | This Command authorizes the wait of alerts; used with accessorstoreAlert. | pattern |
waitForErrorOnNext | This Command authorizes wait of errors; used with Accessors | Message |
IDE Locating Strategies
Before directly going to Llcating strategies, let’s first understand what Locators are.
Locators in commands tell the Selenium IDE which GUI (Graphical User Interface) component to work on.
The prerequisite for creating automation scripts is choosing the correct GUI (Graphical User Interface) component which can include Text Box, Buttons, Check Boxes, etc.
But choosing the precise recognition of GUI Components is more difficult as it sounds.
Consequently, Selenium Provides several locators to accurately locate GUI components. Different types of locating strategies are given below:
- Locating by ID
- Locating by Name
- Locating by Identifier
- Locating by XPath Expressions
- Locating by CSS Selectors
- Locating by DOM (Document Object Model)
- Locating by ID
Locating by ID is the most frequent method of locating elements. But IDs are supposed to be unique.
Let us consider an example related to locating by identifier.
As we had done before, we will create a login test to understand it better.
Steps to be followed below:
- Open Firefox Browser
- Click on the particular selenium icon on the top right of most of your browser.
- It will launch your Selenium IDE
- Click on the command tab present in the Text Editor.
- Recast it to the possession of the first command as:-
- Command: open
- Target: https://mail.rediff.com/cgi-bin/login.cgi
- Execute It.
After Execution, your program will look like:-
To enter the second command, we need some identification for the username text box which would serve the IDE to recognize the target location.
- Right-click on your mouse with hand over to the username and select inspect element.
- The Codes will be launched contained in the production of username text box.
- Select the Component with the matching name feature that contains the precise name for the “Username” text box.
- Recast it to the possession of the first command as:-
- Command: click at
- Target: id=login
- Execute it.
- Recast it to the possession of the first command as:-
- Command: type
- Target: id=login1
- Value: username
- Execute it.
Now we will go through with password
- Right-click on your password text box and click on inspect element.
- Again containing codes at the bottom.
- Select the component with the matching name feature that contains the precise name for the “Password” text box.
- Recast it to the possession of the first command as:-
- Command: click at
- Target: id=password
- Execute it.
- Recast it to the possession of the first command as:-
- Command: type
- Target : id=password
- Value : *********
- Now, Right Click on “sign-in” and select inspect element.
- Recast it to the possession of the first command as:-
- Command: click at
- Target : id=proceed
- Execute it.
- Now, at last Click on the run current test tab which will execute your scripts.
- The log pane summarizes it.
Format of a Target: name=name of the element
- Locating by Identifier
Locating by identifier contains both locating strategies like Locating by Name and ID.
- The identifier was applied as a welshed(default) type previously but now it is not endorsed now as it is not reinforced by the web driver.
- With identifiers, we will use a locating approach like ID and name both.
- The starting element with the matching ID feature is employed.
- If no element features a matching ID attribute then the primary element with an identical name attribute is employed.
- For instance: Identifier=login (this might be ID or Name)
Let us consider an example related to locating by identifier:
As we had done before, we will create a login test to understand it better.
Steps to be followed below:
- Open Firefox Browser
- Click on the particular selenium icon on the top right of most of your browser.
- It will launch your Selenium IDE
- Click on the command tab present in the Text Editor
- Recast it to the possession of the first command as:
- Command: open
- Target: https://mail.rediff.com/cgi-bin/login.cgi
- Execute It.
After Execution, your program will look like:-
To enter the second command, we need some identification for the username text box which would serve the ide to recognize the target location.
- Right-click on your mouse with hand over to the username and select inspect element.
- The codes will be launched contained in the production of the username text box.
- Select the Component with the matching name feature that contains the precise name for the “Username” text box.
- Recast it to the possession of the first command as:-
- Command: click at
- Target: name=login
- Execute it.
Now we will go through with password:
- Right-click on your password text box and click on Inspect Element.
- Again Containing Codes at the bottom.
- Select the Component with the matching name feature that contains the precise name for the “Password” text box.
- Recast it to the possession of the first command as:-
- Command: click atTarget: name=password
- Execute it.
- Recast it to the possession of the first command as:-
- Command: click at
- Target: name=login
- value: username (whatever you want)
- Execute it.
- Recast it to the possession of first command as:-
- Command : type
- Target : name=passwd
- Value : **********(User Login Password)
- Now, Right Click on “signin” and select inspect element.
- Recast it to the possession of the first command as:-
- Command: click at
- Target : name=proceed
- Execute it.
- Now, at last, Click on the run current test tab which will execute your scripts.
- The log pane summarizes it.
- Locating by Name
Locating by name is very related to Locating by ID, but only the exception is that it uses the “name” prefix instead.
The name locator type will locate the primary element with an identical name attribute.
Locating By Name is Syntax is Same as Locating by Identifier. All the procedures are the same.
- Locating by XPath Expressions
- XPath may be a language used for locating nodes in XML documents.
- XPath is often used as a replacement once you do not have an appropriate id or name attribute for the element you would like to locate.
XPath provides locating plans like:
- XPath Absolute
- XPath Attributes
XPath Absolute (not recommended)
- XPath Absolute enables users to say the entire XPath location from the basis HTML tag to the precise components.
- It is not recommended because it takes the entire XPath location and if the situation of the online element is modified or it belongs to another parent then XPath is going to be unable to locate the particular component.
rules : //html/body/tag1[index]/tag2[index]/…/tagN[index]
Example: //html/body/div[2]/div/div[2]/div/div/div/fieldset/form/div[1]/input[1]
XPath Attributes
- XPath Attributes are usually recommended once you do not have an appropriate id or name attribute for the element you would like to locate.
Syntax: //htmltag[@attribute1=’value1′ and @attribute2=’value2′]
Example: //input[@id=’passwd’ and @placeholder=’password’]
Locating by XPath Expressions is used when locating XML (Extensible Markup Language) Nodes. Since HTML elements can be convinced of XML, XML Expressions can also be used in locating HTML Elements.
Pros: It can access almost any element, even those that are present without class, name, or ID’s Features.
Cons:- The biggest disadvantage is that it is more complicated because of its hard rules and considerations.
- Locating by CSS Selectors
They are the string patterns used to recognize a component based on the combination of HTML tag, ID, class, and features. It is commonly used with Selenium Advanced users as it can even access those elements without ID or Name.
There are many formats in CSS Selectors Some are:-
- Locating by ID
- Locating by Class
- Locating by Attribute
- Locating by ID/Class & Attribute
Let’s Take a Loot at Locating by ID.
Rules:- css=<HTML tag><#><Value of ID attribute>.
Note:- ‘#’ symbol is used to represent the attribute of ID.
Steps to be followed below:
- Open Firefox Browser
- Click on the particular selenium icon on the top right of most of your browser.
- It will launch your Selenium IDE
- Click on the command tab present in the Text Editor.
- Recast it to the possession of the first command as:
- Command: open
- Target: https://www.testandquiz.com/user-login
- Execute it
- Right Click on it and choose to inspect elements.
- Codes will appear at the bottom of the website.
- Recast it to the possession of the first command as:
- Command: click at
- Target: css=input#email
- Execute it
- instructions will type the value in the “Username” text box.
- Lastly click on “Run Current Test”, after that your test will be executed and the log pane displays the overall summary of your test scripts.
- Locating by DOM (Document Object Model)
The DOM (The Document Object Model)
The Document Object Model (DOM), in straightforward terms, is the way by which HTML elements are organized. Selenium IDE is in a position to use the Document Object Model in accessing page elements.
If we use this technique, our target box will always initiate with “dom=document…”;
However, the “dom=” designation is usually removed because Selenium IDE is in a position to impulsively illuminate anything that executes with the key “document” to be a path within the DOM regardless.
There are four primitive way to locate a component through DOM:-
- dom:index
- dom:name
- getElementById
- getElementsByName
- dom:index
- Format:- document.forms[index of the form].elements[index of the element]
- Index of the form:- Starting from 0 indexes and the type is the integer
- Element Index:- The value of an integer with respect to the whole form contains it and starting from 0.
- dom:name
Format: document.forms[“name of the form”].elements[“name of the element”]
Name of the shape – it’s the worth of the name attribute of the shape tag that contains the element you would like to access.
Name of the element – it’s the worth of the name attribute of the element you would like to access.
Example: “document.forms[“home”].elements[“userName”]”
- getElementsByName
Format:- document.getElementByName(“name”)[index] Name
Index:- The Location of a crave component
- getElementByID
Format:- document.getElementById(“element id”)
Elements ID:- The Result of an ID Attribute is being retrieved.
Selenium Web driver
Selenium Webdriver is an open-source assemblage of API’s and it is the most important component of Selenium Tool’s Suite. It is used for testing web applications. Webdriver API is integrated with the latest release of selenium which is “Selenium 2.0” provided with a simpler and a condensed programming look.
Test Scripts in Selenium Webdriver can be developed with any supported programming language and can be executed in any modern or fancy browsers.
Language Supported are:
- C#
- Python
- Perl
- Java
- Ruby
- .NET
- PHP
You don’t have to know them all, but basic knowledge is always helpful. Currently, the most used programming language for Selenium Web Driver is Java and C#.
Selenium web driver Architecture is uncomplicated than Selenium RC. Selenium Web Driver makes direct contact with the web browsers as it is much faster than Selenium RC.
Selenium Web Driver Supports the following browsers:
- Firefox
- Chrome
- Safari
- Internet Explorer
Cross-browser testing is permitted.
Selenium WebDriver- Architecture
Selenium Web Driver is much simpler than Selenium RC.
- It powers the browser from the Operating System level
- The only thing you need is the programming languages IDE
In Selenium RC, it is more complicated.
There are primitively four basic components of WebDriver Architecture:
- Selenium Language Bindings
- JSON Wire Protocol
- Browser Drivers
- Real Browsers
Selenium Language Bindings
All supported programming languages are built-in by the language bindings. Let’s say you want to work with java, for working with java, you have to install Java bindings and likewise, they can be installed.
You can download all the bindings from this URL: https://www.selenium.dev/downloads/
JSON Wire Protocol
JSON today is one of the foremost widely used and accepted methods for the communication of heterogeneous systems. JSON has employed tons of web services in REST and has been a robust competition for XML.
Let’s understand how Web driver uses it when testing the online applications −
WebDriver uses JSON as a medium to speak between client libraries (Java, C#, Python than on) and drivers (Firefox Driver, IE Driver, Chrome Driver). The request is within the form of an HTTP request which accepts input within the sort of JSON. The operations are performed, and therefore, the response of execution is shared back to the client within the sort of JSON.
Similarly, the RemoteWebDriver client and therefore the RemoteWebDriver server use the JSON wire protocol to speak among themselves.
To sum up, let’s examine how it works in a step by step manner −
In a server-client architecture, the client and server must be in sync and are ready to receive and send the request and response.
The server doesn’t understand the programming language during which the program is made, it just understands the protocol, and here comes the role of JSON Wire Protocol.
It uses the method of serialization (convert Object’s data to JSON Format) and de-serialization (convert JSON format to object) a bit like REST web services.
Browser Drivers
Drivers are specific to particular browsers to set up a secure connection to the browser and all actions are performed internally. The browser driver is specific to the particular language used for automation such as Java, C#, etc.
Operations that are performed internally while execution of test script using WebDriver:
- For each Selenium Command, an HTTP request is generated and sent to the browser.
- The Driver acquires the HTTP request along with HTTP Server.
- The server determines all the steps to accomplish commandment which are executed on the browser.
- After this, the execution status is followed back to HTTP Server.
Browsers
The Browser Supported By WebDriver are:
- Internet Explorer
- Firefox
- Opera
- Safari
Selenium WebDriver- Features
Some of The Most Important Features:
- Multiple Browser Support: Selenium WebDriver Supports Multiple Browsers such as Firefox, Opera, Safari, Internet Explorer and many more.
- Speed: WebDriver Performs much faster than Selenium Remote Control.
- Simple Commands: Selenium WebDriver Uses Simple Commands That are easier to Learn and Implement.
- WebDriver- Methods, and Classes.
What is Selenium Grid?
Selenium Grid may be a smart proxy server that creates easy to run tests in parallel on multiple machines. This is often done by routing commands to remote browser instances, where one server acts as the hub. This hub routes test commands that are in JSON format to multiple registered Grid nodes.
Hub conducts a multiprogramming of tests on multiple machines, managing different browsers centrally, rather than conducting different tests for every one of them. Selenium Grid makes cross-browser testing easy as one test is often carried on multiple machines and browsers, all at once, making it easy to research and compare the results.
The two major components of Selenium Grid are:
Hub may be a server that accepts the access requests from the WebDriver client, routing the JSON test commands to the remote drives on nodes. It takes instructions from the client and executes them remotely on the varied nodes in parallel.
The node may be a remote device that consists of a native OS and a foreign WebDriver. It receives requests from the hub within the sort of JSON test commands and executes them using WebDriver.
Why Selenium Grid?
Selenium Grid is useful for different reasons are as follows:
- Run on different platforms
- Parallel Execution
When to use Selenium Grid?
- To run tests on multiple browsers
- To reduce the time
Conclusion
From the above Selenium Tutorial, it is proved that Selenium is one of the best Automation tools and it is open-source. Selenium provides various components to easily come up with tasks.
I hope that you found this Selenium Tutorial enjoyable and interesting. And I hope that it helped you in learning Selenium in-depth. If you found this blog on Selenium Tutorial helpful, you can check out the various courses that Great Learning Academy offers, and learn more such skills.
Selenium Tutorial FAQs
Q: Can I learn Selenium on my own?
A: Selenium is easy to understand; therefore, you can certainly learn it on your own. However, you need to know languages that are supported by Selenium, such as Python, Ruby, Java, and many more. If you do not know the programming languages, then you need to start with the languages first.
Q: Which is the best tutorial for Selenium?
A: There are several tutorials on Selenium that you can find on the web. However, if you want to have a thorough knowledge of Selenium and want to start with the basics, you can refer to Great Learning. You will certainly be able to learn in the easiest way possible.
Q: What is the use of Selenium?
A: Selenium is an open-source tool that helps in automating web browsers. It provides a single interface that enables you to write test scripts in programming languages such as NodeJS, Ruby, Java, PHP, Perl, Python, and C#, to name a few.
Q: Is Selenium easy to learn?
A: Learning Selenium is not at all tough; however, you need to be dedicated. For better understanding, you must know Selenium WebDriver, Java, TestNG, and Frameworks to learn automation testing with Selenium. Knowing about these would make the process easier and faster.
Q: How long does it take to learn Selenium?
A: If you are dedicated to learning Selenium, it will take you no more than two months at the most to have complete knowledge about it. Having prior knowledge of programming languages like PHP, Java, Python, etc., will make the process faster.
Q: Does Selenium testing require coding?
A: Even if you have basic knowledge of Java, it will be sufficient to make simple test automation scripts with Selenium. The scripts will have WebDriver API, which is helpful in learning Selenium.
Q: Should I learn Selenium with Java or Python?
A: You are recommended to learn Selenium with Python rather than Java. There are chances that the software will automatically load the driver if it is available in the same folder as your system, on in the Python path. Apart from these, you can also consider the Ruby language.
Q: Is Selenium a good career?
A: In the software industry, Selenium is one of the best choices for developers. It is also one of the best web testing tools that have a massive 300% growth in job postings in the last three years.
Q: Can I learn Selenium without knowing Java?
A: You can learn Selenium without having knowledge of Java, provided you want to create tests by using the record and play features of Selenium IDE. Selenium IDE is a GUI-based tool that essentially works on Mozilla Firefox. If you want to create test cases by using Selenium WebDriver, you need to know at least one programming language from Python, Java, C#, Perl, Ruby, and PHP.
Q: Is there any Selenium certification?
A: There is Selenium Tester certification which is based on practical training courses that are aimed at test professionals who want to understand the ways to design, implement, and maintain automated solutions by using Selenium WebDriver.
{ “@context”: “https://schema.org”, “@type”: “FAQPage”, “mainEntity”: [{ “@type”: “Question”, “name”: “Can I learn Selenium on my own?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “Selenium is easy to understand; therefore, you can certainly learn it on your own. However, you need to know languages that are supported by Selenium, such as Python, Ruby, Java, and many more. If you do not know the programming languages, then you need to start with the languages first.” } },{ “@type”: “Question”, “name”: “Which is the best tutorial for Selenium?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “There are several tutorials on Selenium that you can find on the web. However, if you want to have a thorough knowledge of Selenium and want to start with the basics, you can refer to Great Learning. You will certainly be able to learn in the easiest way possible.” } },{ “@type”: “Question”, “name”: “What is the use of Selenium?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “Selenium is an open-source tool that helps in automating web browsers. It provides a single interface that enables you to write test scripts in programming languages such as NodeJS, Ruby, Java, PHP, Perl, Python, and C#, to name a few.” } },{ “@type”: “Question”, “name”: “Is Selenium easy to learn?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “Learning Selenium is not at all tough; however, you need to be dedicated. For better understanding, you must know Selenium WebDriver, Java, TestNG, and Frameworks to learn automation testing with Selenium. Knowing about these would make the process easier and faster.” } },{ “@type”: “Question”, “name”: “How long does it take to learn Selenium?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “If you are dedicated to learning Selenium, it will take you no more than two months at the most to have complete knowledge about it. Having prior knowledge of programming languages like PHP, Java, Python, etc., will make the process faster.” } },{ “@type”: “Question”, “name”: “Does Selenium testing require coding?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “Even if you have basic knowledge of Java, it will be sufficient to make simple test automation scripts with Selenium. The scripts will have WebDriver API, which is helpful in learning Selenium.” } },{ “@type”: “Question”, “name”: “Should I learn Selenium with Java or Python?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “You are recommended to learn Selenium with Python rather than Java. There are chances that the software will automatically load the driver if it is available in the same folder as your system, on in the Python path. Apart from these, you can also consider the Ruby language.” } },{ “@type”: “Question”, “name”: “Is Selenium a good career?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “In the software industry, Selenium is one of the best choices for developers. It is also one of the best web testing tools that have a massive 300% growth in job postings in the last three years.” } },{ “@type”: “Question”, “name”: “Can I learn Selenium without knowing Java?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “You can learn Selenium without having knowledge of Java, provided you want to create tests by using the record and play features of Selenium IDE. Selenium IDE is a GUI-based tool that essentially works on Mozilla Firefox. If you want to create test cases by using Selenium WebDriver, you need to know at least one programming language from Python, Java, C#, Perl, Ruby, and PHP.” } },{ “@type”: “Question”, “name”: “Is there any Selenium certification?”, “acceptedAnswer”: { “@type”: “Answer”, “text”: “There is Selenium Tester certification which is based on practical training courses that are aimed at test professionals who want to understand the ways to design, implement, and maintain automated solutions by using Selenium WebDriver.” } }] }This brings us to the end of the blog on Octave Tutorial. We hope that you found this helpful and were able to learn more about the concepts. If you wish to learn more such skills, join Great Learning Academy’s pool of Free Online Courses!