Hello Everyone! Welcome back to another Fresh article of MODTECHSTUFF where you Learn Automation testing.
In this article, I will introduce you to the basic concept of Selenium with the help of a simple program.
Basic Requirements
Basically, to start learning the concepts of Selenium, you should have a fundamental knowledge of JAVA or any other object-oriented programming language.
Selenium is compatible with C#, Java, Perl, PHP, Python, and Ruby. Selenium Webdriver is most common with Java. So, if you know any OOP languages then it won't be hard to grasp the concepts of Selenium.knowledge of software testing techniques like automation testing is a plus point.
What is Selenium?
Selenium is an open-source automated testing tool used to automate web applications. You can utilize various programming languages like Ruby, Java, NodeJS, PHP, Perl, C#, Python, and so on to make Selenium Test Scripts. Testing done utilizing the Selenium tool is generally term as Selenium Testing.
Selenium Software isn't only a single tool however a set-up of different software, each piece taking into account distinctive testing needs of an association. To begin with Selenium's most recent adaptation (WebDriver-based usage), you'll just need a single selenium JAR file (selenium-independent server-'{'version'}'.jar) to run tests both locally and on remote systems.
Brief History of Selenium:
Selenium was developed by Jason Huggins in 2004. An architect at ThoughtWorks, he was taking a shot at a web application that necessary successive testing. Having understood that the tedious Manual Testing of their application was turning out to be increasingly wasteful, he made a JavaScript program that would consequently control the program's activities. He named this program JavaScriptTestRunner.
The Selenium name originated from a simple joke in which Jason broke one an opportunity to his group. Another automated testing structure was mainstream during Selenium's turn of events, and it was by the organization called Mercury Interactive (indeed, the organization that initially made QTP before it was procured by HP).
Components of Selenium Suite:
- Selenium (IDE)
- Selenium Remote Control (RC)
- Selenium WebDriver
- Selenium Grid
Selenium IDE:
Selenium Integrated Development Environment (IDE) is the most simple system in the Selenium suite and is the least demanding one to learn in the present scenario. Due to its simplicity, the Selenium IDE should just be utilized for only a prototyping tool. If you further develop advanced test cases, you should employ either Selenium RC or WebDriver.
Selenium RC:
Selenium RC was the lead testing system of the entire Selenium venture for quite a while. This is the primary automated web testing device that permitted clients to utilize a programming language they like. As of form 2.25.0, you can use Java, Ruby, Python, C#, Pearl in Selenium RC.
Selenium WebDriver:
The Selenium WebDriver demonstrates itself to be better than both Selenium IDE and Selenium RC in numerous perspectives. It actualizes a progressively current and stable methodology in the automation of the browser activities. WebDriver, not at all like Selenium RC, doesn't depend on JavaScript for Automation. It controls the browser by legitimately communicating with it. Selenium RC is compatible with Java, Ruby, Python, C#, Pearl.
Selenium Grid:
Selenium Grid is a tool utilized along with Selenium RC to run equal tests across various machines and various browsers simultaneously. Equal execution implies running different tests immediately.
Allows concurrent running of tests in numerous browsers and environments.
Save time effectively. Uses the nodes and-hubs approach. The hub works as a central source of Selenium command to every node associated with it.
Which Selenium YOU need?
1. Selenium IDE:
To find out about approaches on automated testing and Selenium, including:
Selenese commands, for example, type, open, clickAndWait, attest, confirm, and much more. Locators, for example, id, name, xpath, css selector. Executing customized JavaScript code utilizing runScript To develop tests with no earlier practical knowledge in programming. To make simple test cases and test suites that you can send out later to RC or WebDriver.
2. Selenium RC:
To structure a test utilizing a more expressive language than Selenese
To run your test against various programs (with the exception of HtmlUnit) on various working frameworks.
To send your tests over numerous situations utilizing Selenium Grid, the application against another program that underpins JavaScript and web applications with complex AJAX-based situations.
3. Selenium WebDriver:
To utilize a specific programming language in structuring your test cases. To test applications that are using more AJAX-based functionalities.
To execute tests on the HtmlUnit program.
4.Selenium Grid:
To run your Selenium RC contents in numerous test cases and working frameworks in parallel. To run a large number of the test suite, that can be finished as soon as possible.
Why do I need Selenium Automation Testing?
Let us suppose you are a manual tester who has this situation: Checking whether the Facebook sign up page approves input strings and registers a customer effectively in most recent versions of Chrome and Safari.
Accept that the sign-up page has these info fields—username, email address, and password. The tester will get a Windows 10 And Mac OS and follow these means, successively, on most recent variants of Chrome and Safar.
Enter the URL in the location bar (www.facebook.com/signup)
Enter an invalid string in each info field (email, username, and password)
Check whether the information was approved against comparing regexes and data in the database
Enter 'valid' strings in each information field; click Sign Up
Check whether "Welcome to Facebook, '{'username'}'" page appeared
Check whether the framework database made another userID for '{'username'}'
Depending upon the number of manual testers it might take a few hours to weeks to be certain that the web application is completely Tested.
Present-day engineers don't have that sort of time to allow for testing, however, they can't put aside comprehensive testing in a rush to discharge either. This is the reason Selenium comes under the picture.
With the help of Selenium Automation Testing, we can reduce labor time and get more accurate results in no time.
How to Install Selenium:
We can install Selenium in just three steps. The first step is installing JAVA SDK, the second step is installing the Eclipse IDE and finally some Selenium Driver Files.
Step.1 Installing JAVA on your System:
After clicking on JDK download, you have to choose Your Operating System
as shown below
This JDK version comes with an inbuilt Java Runtime Environment (JRE), so the advantage of JDK you do not need to download and install the JRE additionally.
Next step is
- Go to Start and search for ‘System’
- Click on ‘System’
- Click on ‘Advanced system settings’
- Click on ‘Environment Variables’ under the ‘Advanced’ tab as shown below:
- Under ‘Variable value’, at the end of the line, enter the following path – %JAVA_HOME%bin;
- Now, you can click ‘OK’ and you are done.
Once the installation is finished, open command prompt and type " java-version". If you see the following screen, then Congratulations you successfully installed JAVA on your System.
Step.2 Installing Eclipse IDE
After downloading you will get a zip file, unzip it and install. Launch the Eclipse after a successful installation. When you launch eclipse IDE a popup window will open and asked to select for a workspace, just accept the default location.
The next step is to create a new project through the File > New > Java Project. Name the project as a "new project".
A new pop-up window will open enter details
- Project Name
- Location to save the project
- Select an execution JRE
- Select layout project option
- Click on Finish button
Step.3 Download Selenium jar File:
Extract the zip file and save it in your selenium folder. Next, you have to download Chrome Driver for Google Chrome and Gecko Driver if you are using Mozilla Firefox. In the same downloads page, scroll further down and you will find third-party drivers section.
now next steps are
- Right-click on "new project" and select Properties.
- On the Properties dialog, click on "Java Build Path".
- Click on the Libraries tab, and then
- Click on "Add External JAR file.
Writing our First Test Case
In this segment, you will learn how to build your First Selenium Automation Test.
Here are the following steps:
1. Open the Google Chrome browser.
2. Type URL: www.google.com in the search bar
3. Click on the Google Search text box.
4. Write the keyword "modtechstuff "
5. Press the Search button.
I will explain the test case step by step to give you complete knowledge of each element in detail.
Launch Eclipse IDE and open your project which you build in the above steps We will write our first test case in the "First.class" file under the Project name.
Step 2.
In this step, you have to download the chromedriver for your google chrome, according to your system requirements 32/64 bits.
You can Download ChromeDriver from here.
Step 3.
We would need a unique identifier for the web elements like the Google Search text box and the Search button in order on the page to automate them through our test script. We can inspect elements by pressing shortcut "control+shift+i" or right-click on a particular item and select inspect element.
for example, we inspect google search box
After clicking on inspect element, a new window will be open as shown below
Given below is the method for locating elements through "name" in Selenium.
driver.findElement(By.name (<element ID>))
In our case, element ID is q as shown below
driver.findElement(By.name ("q"))
Now, for the search button right-click on the Google Search button and select Inspect Element.
Given below is the method for locating elements by "name" in Selenium
driver.findElement(By.name (<element name>))
In our case element ID is btnK as shown below
driver.findElement(By.name ("btnK"))
Step4.
Now it is time to start writing programs.
This is a basic program, where I Automate the search of my site MODTECHSTUFF!
In java, import statements are used to import the classes present in other packages.
org.openqa.selenium.WebDriver - References the WebDriver interface which is required to instantiate a new web browser.
org.openqa.selenium.chrome.ChromeDriver - References the ChromeDriver class that is required to instantiate a Chrome-specific driver onto the browser instantiated by the WebDriver class.
A driver object is instantiated by WebDriver driver=new ChromeDriver();
To launch a URL, we use navigate().to() method.
To click an element we use click() method.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class first {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", "drivers/chromedriver.exe");
WebDriver driver=new ChromeDriver();
// Launch website
driver.navigate().to("https://www.google.com/");
// Click on the search text box and send value
driver.findElement(By.name("q")).sendKeys("Modetechstuff");
// Click on the search button
driver.findElement(By.name("btnK")).click();
}
}
Wrap-UP
I hope this article has helped to learn basic concept of Selenium with the help of a simple program.
Please let us know your feedback and also share your experiences and for any query send me a message here. I will ready to help(In FREE).
Comments
Post a Comment