0% found this document useful (0 votes)
58 views19 pages

ST - Module 5: Introduction To Selenium Introduction To Selenium

Selenium is an automated testing tool that was initially released as a Firefox plugin. It allows testing of web applications without requiring programming knowledge. The document discusses how to install and use Selenium IDE by recording and playing back test cases on a website. It also covers the scope of test automation, frameworks, and common challenges in automation like testing complex applications, time constraints, and deciding what to test first.

Uploaded by

Raghu C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views19 pages

ST - Module 5: Introduction To Selenium Introduction To Selenium

Selenium is an automated testing tool that was initially released as a Firefox plugin. It allows testing of web applications without requiring programming knowledge. The document discusses how to install and use Selenium IDE by recording and playing back test cases on a website. It also covers the scope of test automation, frameworks, and common challenges in automation like testing complex applications, time constraints, and deciding what to test first.

Uploaded by

Raghu C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

ST - Module 5

Introduction to Selenium
Introduction to Selenium
• Selenium integrated development environment, acronym as Selenium IDE is an
automated testing tool that was released initially as a Firefox plug-in.
• It is one of the simplest and easiest tools to install, learn and to go ahead with the
creation of test scripts.
• The tool is laid on a record and playback fundamental and also allows editing of
the recorded scripts.
• The most impressive aspect of using selenium IDE is that the user is not required
to possess any prior programming knowledge.
• The minimum that the user needs is the minimal knowledge with HTML, DOMS
and JavaScript to create numerous test scripts using this tool.

Selenium IDE installation


• Before taking off, there is one thing that needs to be in place prior to the
installation;
• Step 1: Using Chrome browser, go to (https://chrome.google.com/webstore) and
search for ‘Selenium’ or ‘Selenium IDE’ in the search box.
• Step 2: Click on the extension named ‘Selenium IDE’
• Step 3: Download the Selenium IDE extension from the Chrome Web Store by
clicking on the ‘Add to Chrome’ button.

• Step 4: This will lead to a dialog box appearing at the top of the screen. Read the
permissions that the extension will have and click on ‘Add extension’.

• Step 5: Click on the Extension icon which looks like a puzzle piece, located in the
top-right corner of the screen. Then click on ‘Selenium IDE’.

• Step 6: If the extension has been added successfully, a window showing various
actions to perform like the following should be seen:
o Record a new test in a new project
o Open an existing project
o Create a new project
o Close Selenium IDE
Recording and Running Test Cases using Selenium IDE
• Record And Playback in Selenium is an easy process of creating test cases by simply
using the web browser and performing several steps that need to be included in
the test cases.
• It is a very useful feature that enables the users to create test cases without
having to write long scripts and without any rigid programming knowledge.
• It breaks the barrier that most people feel with programming languages and
enables people with little to no experience with testing frameworks to test their
applications from start to end.
• Follow the steps below to get started with Selenium IDE and start recording the
test cases:
1. Step 1: Launch Selenium IDE. After opening the Selenium IDE extension in the
browser, a pop-up will open.
2. Step 2: Select ‘Create a new project’ option
3. Step 3: Create a New Test: To create a new test case, simply provide the name
of the test. The Selenium IDE will redirect to the dashboard where testers can
start Record and Playback for the test cases.

4. Step 4: Start with Record and Playback: A button on the top-right corner will
take the QA to the target website and start recording the actions or events
created while in the record mode.

5. Step 5: Record a test in Selenium: After pressing the “rec” button, the IDE will
open a prompt to provide the target website. In this example, the website link is
– “https://www.google.com/”.
6. Step 6: After providing the website, the IDE will redirect to the webpage where
each action will be recorded as a step in the test case. While recording, testers
see a symbol that states “Selenium IDE is recording”.

7. Step 7: Once the test case is complete, simply go back to the Selenium IDE
dashboard and stop the recording.
8. Step 8: Playback a test in Selenium:
o Playback in Selenium checks or runs recorded test cases to determine if
the test will run without any errors like it did while recording the tests.
o As soon as the recording finishes, the test cases will be displayed with
commands and targets.
o The playback button will run the tests and return the results in the log.

9. Step 9: If all tests run successfully, the log will show the results. In the above
example, the test case will open the website and click on the sign-in option on
the web page.
Scope of Automation in Testing
• Automation is the process of evaluating the AUT (Application under Test) against
the specification with the help of a tool.
• Depending upon the nature of testing there are two main branches of automation:
o Functional testing with automation.
o Performance testing with automation.

Test Automation Framework


• A “Test Automation Framework” is a scaffolding that is used to provide an
execution environment for the automation test scripts.
• The framework provides the user with various benefits that help them to develop,
execute and report the automation test scripts efficiently.
• It is more like a system that has been created specifically to automate our tests.
• Advantage of Test Automation Framework:
o Reusability of code o Low-cost maintenance
o Maximum coverage o Minimal manual intervention
o Recovery scenario o Easy Reporting

Challenges in Automation

1. Testing the Complete Application


o It is not possible to test each and every combination in both Manual as well
as Automation Testing.
o If you try all these combinations, you will never ship the product.

2. Misunderstanding of Company Processes


o Sometimes you just don’t pay proper attention to what the company-defined
processes are and for what purposes they are.
o There is a myth among testers that they should only go with the company
processes even if they are not applicable for their current testing scenario.
o This results in incomplete and inappropriate Application Testing.
3. Relationship with Developers
o It’s a big challenge and it requires a very skilled tester to handle this
relationship positively and complete the work via the tester’s way.
o There are simply hundreds of excuses that the developers or testers can
make when they do not agree with some points.
o For this, the tester also requires Good Communication, Troubleshooting and
analyzing skills.

4. Regression Testing
o If a project continues to expand, then regression testing work simply
becomes uncontrolled.
o There will be pressure to handle current functionality changes, previous
working functionality checks, and bug tracking.

5. Lack of Skilled Testers


o This could be called as a “wrong management decision” while selecting or
training testers for their project task in hand.
o Unskilled testers may add more chaos than simplifying the testing work.
o This results in incomplete, insufficient and ad-hoc testing throughout the
Testing Life Cycle.

6. Testing always under Time Constraint


o Hey tester, we want to ship this product by this weekend, are you ready for
completion?
o When this order is from the boss, the tester simply focuses on task
completion and not on the test coverage and quality of work.
o There is a huge list of tasks that you need to complete within the specified
time. This includes writing, executing, automating and reviewing test cases.

7. Which Tests to Execute First?


o If you are facing the challenge stated in point 6, then how will you decide
which test cases should be executed and with what priority?
o Which tests are more important than others?
o This requires a good experience to work under pressure.
8. Understanding the Requirements
o Sometimes testers are responsible for communicating with customers to
understand the requirements.
o What if the tester fails to understand the requirements? Will he be able to
test the application properly? Definitely not! Testers require good listening
and understanding capabilities.

9. Automation Testing
o Automation Testing has many sub-challenges
▪ Should automate the testing work?
▪ Until what level, should automation be done?
▪ Do you have sufficient and skilled resources for Automation?
▪ Is time permissible for automating the test cases?
o The decision of Automation or Manual Testing will need to address the pros
and cons of each process.
10. Decision to Stop Testing
o When to stop testing?
o This is a very difficult decision. It requires core judgment of testing processes
and the importance of each process.
o It also requires an “on the fly” decision ability.
11. One Test Team under Multiple Projects
o It is quite challenging to keep track of each task.
o Communication challenges are also involved.
o Many times, it results in failure of one or both the projects.
12. Reuse of Test Scripts
o Application development methods are changing rapidly, thereby making it
difficult to manage the test tools and test scripts.
o Test script migration or reuse is a very essential but difficult task.
13. Testers Focusing on Finding Easy Bugs
o If the organization is rewarding testers based on the number of bugs (very
bad approach for judging Testers Performance) then some testers only
concentrate on finding easy bugs that don’t require deep understanding and
testing.
o Hard or subtle bugs remain unnoticed in such a testing/rewarding approach.
Web Driver
• It is a web automation framework which allows us to execute test across various
browsers. It can execute multiple tests over multiple browsers on multiple OS.
• WebDriver makes it possible to write a test script in Linux and run it in Windows.
• There are multiple programming languages which are supported by Web Driver
such as Java, Python, Ruby, .Net, PHP to create test scripts.
• Web Driver is one of the most powerful and popular tools which is integration with
Selenium toolkit.
• WebDriver comes as an extended version to Selenium RC with superfluous
advantages and addresses many of its limitations.
• WebDriver extends its support to many latest browsers and platforms unlike
Selenium IDE. Web Driver also doesn’t require Selenium server to be started prior
to execution of the test scripts unlike Selenium RC.
• Selenium RC in aggregation with WebDriver API is known as Selenium 2.0.
• New Features introduced −
o It can test dynamic websites where the content of pages changes by a mouse
click.
o Using Web Driver, mobile automation is also feasible.
o Selenium was developed in order to support dynamic web pages and Ajax calls.
o It also supports various drivers to exercise web based mobile testing.

How does Selenium Web-Driver work?

When WebDriver code in Selenium executes , the following actions happen in the
background
• An HTTP request generates, and it goes to the respective browser driver (Chrome,
IE, Firefox). There is an individual request for each Selenium command.
• The browser driver receives the request through an HTTP server.
• The HTTP server decides which actions/instructions need to execute on the
browser.
• The browser executes the instructions/steps as decided above.
• The HTTP server then receives the execution status and then sends back the status
to an automation script, which then shows the result (as passed or an exception or
error).

How to use Selenium WebDriver for Web Automation?


• Selenium WebDriver provides a very seamless, user-friendly, and code friendly
approach to automation using various browsers.
• Since it supports most of the major browser vendors, it's just a matter of using the
respective browser driver and browser and setting up Selenium to use the same.

Selenium WebDriver Architecture


• Selenium WebDriver API provides communication facility between languages and
browsers.
• The following shows the architectural representation of Selenium WebDriver.

• There are four basic components of WebDriver Architecture:


o Selenium Language Bindings
o JSON Wire Protocol
o Browser Drivers
o Real Browsers
• Selenium Language Bindings / Selenium Client Libraries
o Selenium developers have built language bindings/Selenium Client Libraries
in order to support multiple languages.
o For instance, if you want to use the browser driver in java, use the java
bindings.
• JSON Wire Protocol
o JSON (JavaScript Object Notation) is an open standard for exchanging data on
web.
o It supports data structures like object and array. So, it is easy to write and
read data from JSON.
o JSON Wire Protocol provides a transport mechanism to transfer data
between a server and a client.
o JSON Wire Protocol serves as an industry standard for various REST web
services.
• Browser Drivers
o Selenium uses drivers, specific to each browser in order to establish a secure
connection with the browser without revealing the internal logic of browser's
functionality.
o The browser driver is also specific to the language used for automation such
as Java, C#, etc.
o When we execute a test script using WebDriver, the following operations are
performed internally.
▪ HTTP request is generated and sent to the browser driver for each
Selenium command.
▪ The driver receives the HTTP request through HTTP server.
▪ HTTP Server decides all the steps to perform instructions which are
executed on browser.
▪ Execution status is sent back to HTTP Server which is subsequently sent
back to automation script.
• Browsers
o Browsers are the end-point of our test execution. Selenium supports all
major browsers like Firefox, Chrome, Safari, Edge, etc.
o So, browser installation is necessary.
Selenium WebDriver- Features
• Multiple Browser Support:
o Selenium WebDriver supports a diverse range of web browsers such as
Firefox, Chrome, Internet Explorer, Opera and many more.
o It also supports some of the non-conventional / rare browsers like HTMLUnit.
• Multiple Languages Support:
o WebDriver also supports most of the commonly used programming
languages like Java, C#, JavaScript, PHP, Ruby, Pearl and Python.
o Thus, the user can choose any one of the supported programming language
based on his/her competency and start building the test scripts.
• Speed:
o WebDriver performs faster as compared to other tools of Selenium Suite.
o Unlike Selenium RC, it doesn't require any intermediate server to
communicate with the browser; rather the tool directly communicates with
the browser.

• Simple Commands: Most of the commands used in Selenium WebDriver are easy
to implement. For instance, to launch a browser in WebDriver following commands
are used:
o WebDriver driver = new FirefoxDriver(); (Firefox browser )
o WebDriver driver = new ChromeDriver(); (Chrome browser)
o WebDriver driver = new InternetExplorerDriver(); (IE browser)

• WebDriver- Methods and Classes:


o WebDriver provides multiple solutions to cope with some potential
challenges in automation testing.
o WebDriver also allows testers to deal with complex types of web elements
such as checkboxes, dropdowns and alerts through dynamic finders.
Selenium WebDriver Commands
• To launch a new Chrome instance: WebDriver driver = new ChromeDriver();
• To fetch a website: → Where url is the website address to load
o driver.get(url);
o driver.navigate().to(url)
• To fetch the title of a website: driver.getTitle();
• To fetch the current URL that is opened in the browser: driver.getCurrentUrl();
• To fetch the source code of a page: driver.getPageSource();
• To navigate backwards in browser history: driver.navigate().back();
• To navigate forwards in browser history: driver.navigate().forward();
• To refresh the current page: driver.navigate().refresh();
• To quit the browser if it's the last window currently open: driver.close();
• To quit the browser and close every associated window: driver.quit();
• Note: driver.close() closes only the current window on which Selenium is running
automated tests. The WebDriver session, however, remains active.
• On the other hand, the driver.quit() method closes all browser windows and ends
the WebDriver session.

WebElement Commands
• WebElement represents an HTML element. HTML documents are made up
by HTML elements.
• HTML elements are written with a start tag, with an end tag, with the content in
between: <tagname> content </tagname>
• WebElement can be of any type, like it can be a Text, Link, Radio Button, Drop
Down, WebTable or any HTML element.
• findElement
o returns a WebElement object
o Example: WebElement element = driver.findElement(By.id("UserName"));
• sendKeys
o This simulates typing into an element, which may set its value
o WebElement element = driver.findElement(By.id("name"));
element.sendKeys("Rahul"); //OR
o driver.findElement(By.id("name")).sendKeys("Rahul");
o This method works fine with text entry elements like INPUT and TEXTAREA
elements.
• getText
o Used to fetch data written over any web element.
o String name = driver.findElement(By.id("name")).getText();
• click
o Common way of interacting with web elements like text elements, links, radio
boxes and many more.
o Most of the time we click on the links and it causes a new page to load.
o driver.findElement(By.id(“button")).click();
• clear
o If this element is a text entry element, this will clear the value.
o This method accepts nothing as a parameter and returns nothing.
o driver.findElement(By.name("name")).clear();
• isDisplayed
o This method determines if an element is currently being displayed or not.
o This accepts nothing as a parameter but returns a boolean value(true/false).
o boolean status = driver.findElement(By.id("name")).isDisplayed();
• isEnabled
o This determines if the element currently is enabled or not
o This accepts nothing as a parameter but returns boolean value (true/false).
• isSelected
o Determines whether or not this element is selected or not.
• submit
o If this causes the current page to change, then this method will wait until the
new page is loaded unlike the click() method

Waits in Selenium
• Implicit wait: used to set the default waiting time throughout the program
• Explicit wait: used to set the waiting time for a particular instance only
• Implicit waits are used to set the waiting time throughout the program,
while explicit waits are used only on specific portions.
Implicit Waits
• It is used to tell the web driver to wait for a certain amount of time before it
throws a “NoSuchElementException”.
• The default setting is 0. Once we set the time, the web driver will wait for the
element to load for the specified period of time before throwing an exception.
• It is simpler to code than Explicit Waits.
• It is usually declared in the instantiation part of the code.
• To start using an implicit wait, you would have to import this package into your
code: import java.util.concurrent.TimeUnit;
• Then on the instantiation part of your code, add this.
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Explicit Waits
• The Explicit Wait in Selenium is used to tell the Web Driver to wait for certain
conditions (Expected Conditions) or maximum time exceeded before throwing
“TimeoutException” exception.
• It is an intelligent kind of wait, but it can be applied only for specified elements.
• In this WebDriver wait example, wait for whichever occurs first:
o the amount of time defined in the “WebDriverWait” class to elapse or
o the condition specified in “ExpectedConditions” to occur
• Step 1: Import packages
o import org.openqa.selenium.support.ui.ExpectedConditions;
o import org.openqa.selenium.support.ui.WebDriverWait;
• Step 2: Declare a WebDriverWait variable
o ChromeDriver driver = new ChromeDriver();
o WebDriverWait myWaitVar = new WebDriverWait(driver, 10);
• Step 3: Use myWaitVar with ExpectedConditions on portions where you need the
explicit wait to occur.
myWaitVar.until(ExpectedConditions.visibilityOfElementLocated(By.id("pid")));
Installation of Selenium Web Driver
• Step 1: Ensure your Chrome browser is updated to the latest version. To do this, go
to Chrome Settings (chrome://settings/) and click on ‘About Chrome’. If you are
using the latest version of Chrome, you will see a text saying ‘Chrome is up to date’

• Step 2: Go to the official Chromium Driver website


(https://chromedriver.chromium.org/) and download the latest stable version of
Chrome Driver.

• Step 3: Go to the Selenium website’s download page


(https://www.selenium.dev/downloads/) and download the latest stable version of
Selenium Server
• Step 4: Open the Eclipse IDE and create a new ‘Java Project’ and give it a name.

• Step 5: Create a new Java class by right-clicking on the Project and select
New ⟶ Class. Give a suitable class name.

• Step 6: Now, add the Selenium Standalone Server jar file, downloaded in Step 3 to
the project by right clicking on the project and selecting Build Path ⟶ Configure
Build Path
• Step 7: Click on the ‘Libraries’ tab and then click on the ‘Add External JARs’ button.

• Step 8: Select the Selenium Standalone Server JAR file and click ‘Open’

• Step 9: Once you add the Selenium Standalone JAR file, you will see it in the
‘Libraries’. Now, click ‘Apply’ and then ‘Ok’.
• Step 10: If done correctly, the project structure will now look like this. A new folder
named ‘Referenced Libraries’ is added and the Selenium Standalone Server JAR file
is added under it.

You might also like