Friday, May 17

Aspect of Supply Chain and Quality Management System...

 One of the most important aspects in Supply Chain is identification and traceability of products or services. Product traceability enables manufacturers to track the origin of a product, including the raw materials used in its production, the manufacturing process, and the packaging and distribution process. Product can be Final assembly, Sub-assembly, Component Parts, Raw Materials or any kind of Services.

In ISO 9001 standards, from the beginning version to the latest one (2015) , one important clause is there on Product identification and traceability.   In ISO 9001:2015, subclause 8.5.2- Identification and Traceability states the following three requirements around identification and traceability:

·       Use appropriate means to identify outputs when it is required to ensure the conformity of products and services.

·       Identify the status of outputs with respect to monitoring and measuring requirements throughout production and service provision.

·       Control the unique identification of the outputs when traceability is a requirement, and retain documented information on traceability.

This means, one manufacturer or service provider has to maintain proper objective evidence in terms of documentation for Identification and Traceability of their products and services to attain conformance in their Quality Standards. These documentation can be in the form of Paper work, Bar Code, ERP Forms , Route Card or Job Card, Work Order, Inspection Labels, Process Sheet, Project log or Status Report.

In early 90s , manufacturers who produces very critical items , these kind of documentations were mandatory as per their Customer’s requirement. I can remember when I was working in a manufacturing company who were producing Current collection unit for railways, used to maintain these documents mostly manually. One case happened when one Pantograph (Current collection unit in train) got failed in the trial run and returned to our factory from railways workshop. The failure was due to a machining fault of one its major part and we identified the root cause of the failure by tracing back from assembly to in process inspection following all its relevant document. The part has a serial number or an inspection date stamp on it and by that Number we could find out the inspection date, machining date, lot of the machining in shop floor and the machine number where it has been machined initially. We found that the internal diameter of the part was wrong (not in the tolerance limit) as it did not match with the drawing provided to the operator. The drawing was a controlled copy with latest revision. Eventually, it was a fault of the operator as well as shop floor inspector who measured the diameter incorrectly after machining and wrongly entered in the Job Sheet. In this way , we could reach to the root cause of the problem and took preventive action on this. So, product identification and traceability helped identifying bottlenecks in the production process and fix them quickly, resulting in improved throughput and reduced waste.

Product traceability can improve efficiency by streamlining the manufacturing process. By accurately tracking the movement of raw materials, manufacturers can better manage their inventory and avoid production delays due to shortages. Traceability is often a legal requirement for manufacturers, especially in the food, pharmaceutical, and automotive industries. Manufacturers must ensure their products meet regulatory requirements, including safety, quality, and environmental standards. Traceability provides the necessary documentation and audit trails required to demonstrate such regulatory compliance.

Responsibility of maintaining traceability lies on various stake holders who are involved in product development, manufacturing, planning and quality inspection. They are basically design engineers, planning engineers, shop floor supervisors, operators, inspection team and delivery executives. Each of them is equally responsible to maintain proper documentation of their respective action to ensure traceability of the any parts or products are maintained properly. Even sub-contractors, suppliers , external auditors, transportation agencies  are held responsible in this seamless process . They must provide accurate and detailed information about the materials and components they supply, including origin, quality, and compliance with regulatory requirements. Suppliers must also ensure that all materials are properly identified and labeled and maintain accurate records to enable traceability throughout the supply chain. Distributors or Logistics provider or seller also should present proper document to customers or consumers to ensure that product is identified properly and it can be traced throughout their manufacturing process to avoid any counterfeiting.

Procedure for Product Identification and Traceability :

Procedures to identify products and to maintain its traceability varies depending on type of industry and product or material being handled. However, generally it can be categorized as :

Procedures for identifying products.

Procedures for segregating and differentiating between product and tooling when their function and look are similar.

 Procedures for providing traceability of product or item including unique serialization.

Generally, there are three types of material are being handled in a Manufacturing Industry which need proper identification and traceability:

·Product: Any Part or Assembly which is Ordered by Customer or in Work in progress (WIP) . For Service Industry It can be a Software, Documents, Reports or Schedules or any other services.

 Raw Material: Any materials or items which become integral part of the finished products. Some of these items are called as consumables.

Tooling: Devices used by manufacturing for set up or production e.g Jigs and Fixtures. Similarly devices used for inspection to accept/reject the material, e.g. Testing fixtures.

Identification and Traceability of:

·Product: Identification typically includes assigning a Part Number, Revision and unique Serial Number (if applicable) or Work Order Number. This is done by any of the following methods :

a.Assigning a Part Number physically by ink or etching or some other method on the Part.

b.Storing  the Parts in designated /identified Location  with appropriate Tag/Board or Paper works.

c.For critical parts where unique serialization is required for traceability, the parts are identified by a unique serial number as per customer’s requirement. No two parts will be given same serial number. Work Order number, under which Parts are manufactured , is the Key Document Number which shall record the Part serial numbers.

d.Sometimes, if same kind of parts are produced in bulk, unique lot or batch number is used to identify the parts.

Raw Material:

a.For traceability raw materials are required to mark lot number or batch number under which the have been procured. These lot/batch number are put during receipt of material. Sometimes Purchase Order Number or Supplier lot number are also used for identification and traceability.

b.Unused Raw material will be returned to stock with proper identification before re-entry into inventory for future use.

Tooling:

a.All Tools used for Production (fixtures, jigs, molds, support or set up devices etc) should be designated and built according to engineering data. Those should be validated to ensure that performance of the tool is as expected without damaging the product.

b.After validation tools are marked with a unique Tool ID number. The Number should be such that it can be distinguished from Main Part Number or Raw material.

For Service Deliverable:

a.In case of Service Industries, Service deliverables are identified by Title, Document Number (Customer Contract Number) , Revision Number, Release date.

b.In all cases, the deliverables will be identified in a such way so that it can be understood for which Contract or Project the deliverables relate to.

After ERP evolved, product identification and traceability become an inherent feature in all ERP packages. It can be done by following ways:

·Codification of all items used in manufacturing process is the first step of Product identification. If Item is properly codified, from code itself it is possible to identify the nature of the item.

Different item attributes are also used to differentiate one item from another.

 Every item in the ERP system can be tracked at any point of item through Lot Control, Batch Control or Serial Control features. From serial number it can be traced back easily which supplier sent this and against which Purchase Order it is received.

·Similarly in case any of any customer complaints, the root cause of the problem can easily be found out exploring different functionality like Customer orders, Shop Floor Execution, Work Orders, Material Issue, Inventory, Inspection and Purchase Orders.

·ERP being an integrated system among various departments, it has become most effective tool nowadays for maintain product identification and traceability. To maintain this more effectively, manufacturers are currently integrating Bar coding, RFID Tagging or Blockchain with ERP system.

In conclusion, product identification and traceability play a major crucial role in any manufacturing industry. It keeps all records of Product journey from raw material to finished goods stage and ensures consumers a high quality and socially acceptable product. It also helps developing automation in manufacturing process. As the manufacturing industry continues to evolve, it is essential to stay up to date with the latest trends and advancements in product identification traceability to remain competitive and meet consumer demands.

HIPAA Compliance in AWS Cloud

 Introduction:

The Health Insurance Portability and Accountability Act of 1996 (HIPAA) is a law designed to protect the security and privacy of protected health information (PHI) data and applies to covered entities and Business Associates. HIPAA was revised in year 2009 by the Health Information Technology for Economic and Clinical Health (HITECH) Act. HIPAA has certain requirements on

  • How to use and disclosure the PHI information
  • Safeguards to protect PHI
  • Individual rights
  • Administrative responsibilities.

HIPAA required companies to develop regulations for protecting the privacy and security of certain health information. To fulfill this requirement, they need to manage what are commonly known as the HIPAA Privacy and Security Rule. The Privacy Rule, or Standards for Privacy of Individually Identifiable Health Information, establishes standards for the protection of health information. The Security Standards for the Protection of Electronic Protected Health Information (the Security Rule) set up a set of security standards for protecting certain health information that is stored or transferred in electronic form. Note that if you failed to comply with HIPPA regulation, then there are possibilities of  losing the trust of your client and expose you to legal action as well. There are criminal and civil penalties that could include fines of $250,000, and imprisonment for up to ten years.

1)  HIPAA Compliance top five challenges and How to overcome it?
1.1)  Find out, Is AWS Cloud HIPAA Compliant?

You will usually be wondering with one question, “Is AWS HIPAA compliant, let’s answer this important and mostly thought about by people working on compliance and audit related work. To answer you briefly, AWS alone doesn’t guarantee HIPAA compliance, but it offers services to meet the HIPAA compliance requirements. Now Let’s check what does it means. Amazon is supporting HIPAA compliance, and you would utilize its reliable services to create a cloud-based solution that will manage, maintain, and transfer confidential patient information and comply with HIPAA regulation. However, it’s not enough simply to use AWS services for HIPAA compliance. The main idea behind AWS HIPAA compliance is to have excellent knowledge of how to implement HIPAA controls using Amazon services. So, as a result, to deal with PHI data in a highly protected way, you should keep a note of  the AWS HIPAA security rules and standards and, of course, correctly fit it into your IT infrastructure.

Here is an example:
You are developing an application which is handling PHI data in AWS Cloud environment and your company is looking for HIPAA compliance. So, you would need to check what the AWS services are required, How Enterprise Architect will  design and architect applications to meet HIPAA compliance requirements. In this blog we will focus on the HIPAA compliance basic requirements for protecting PHI, what is service provider responsibility like signing agreement with AWS and others precaution to run workloads containing PHI.

1.2) How do we find out if I need a Business Associate Addendum for AWS Account?

The first step for HIPAA implementation, you need to sign and execute a Business Associate Addendum (BAA) agreement with Amazon Web Services to use the AWS Services for HIPAA compliance. BAA means Amazon Web Services share some of your legal obligations and guarantee that client will be informed of any data breach. To put it in simply way, you take care your data in cloud platforms, operating systems, apps, and other solutions. For AWS HIPAA compliant services, AWS are responsible for the security of database, cloud server infra, networks, and others infrastructure in the cloud and You are responsible for Security of the Cloud as per Shared Responsibility defined by AWS. It is up to you how you will use Amazon Web Services (AWS) to run workloads regulated under the HIPAA compliance. We are getting AWS services to securely process, store and transmit PHI data for the Covered Entities and their Business Associates. AWS is offering a standardized BAA for customer and HIPAA eligible Services to use HIPAA AWS account. This is mandatory to enter into an AWS Business Associate Agreement and without that customer suppose to not use the HIPAA eligible services for any purpose or in any manner involving PHI data. Thus AWS BAA agreement is required for an organization that would like to be HIPAA compliance for safeguarding PHI in AWS Cloud. For this you can use AWS Artifact service to Manage the agreements for HIPAA enable accounts in AWS Organization and during audit you can easily provide BAA agreement by using AWS Artifacts to your compliance officer

Example if you are developing an application which is handling PHI, so you need to find where Application is hosted in AWS Account including all infrastructure as per its architecture and must know how application is handling the PHI data (Example – Database, Logs etc). Accordingly, you need to accept the BAA for those AWS account(s). Please note that It is mandatory to accept BAA for the AWS Accounts which handle the PHI data.

Note:
As per AWS Organization OU and account structure design, the HIPAA compliance requirement for the application need to check at  AWS account level, you need to accept BAA at OU level or Account level. Before you accept an agreement,  Infosys recommend that you take advise from legal, privacy, and compliance team and get approval from them

1.3) What is Partner’s Platform As Service solution and BAA requirements for HIPAA compliant application?

Many AWS Partners may be hosting Platform As Service (PaaS) applications in AWS. In this case you as Partner has to sign a Business Associate Addendum (BAA) agreement with AWS and client that is using hosted application which we called as Healthcare Provider or Covered entity has to sign a BAA with you.  Please note that Covered entity do not have sign BAA with AWS. Please see below illustration on HIPAA compliance requirement in AWS cloud

1.4)  Implementation of HIPAA Controls in AWS Cloud?

You might be knowing that AWS  is offering  many services to fulfil your application’s high availability, scalability, security  requirements. You can begin with HIPAA compliant architecture of your application that will starting point for building a HIPAA applications. You need to review Application architecture in other layers as well as shown below

  • Authorization and Authentication of application and Infra
  • Application layer security
  • Database layer

The below are some key points for HIPAA compliant application or platform.

a)  Authentication and Authorization of App and Infra

You would use AWS IAM primarily toward the authenticating and authorizing the use of AWS services and you need to setup additional controls for authentication and authorization for healthcare application. You might also want to consider identity federation and that can be extended your existing Identity provider solution like SAML 2.0, or Active Directory to cloud. The below are some considerations to achieve HIPAA compliance

  • Check the authentication and authorization setup that you define for your HIPAA-eligible Application
  • Implement the Multifactor Authentication (MFA) for users
  • Do not create Access key for root account

b)   Application layer Security

Your application may accessible directly from Internet through Load Balancer (AWS ELB). You can enable HTTPS communications to protect PHI data and also enable SSL on Server side as well so that traffic between ELB and Backend servers is encrypted. You make use of additional layer of security  by introducing WAF – Web Application Firewalls in front of web applications and also use intrusion detection/prevention solutions. All these will help to  avoid any possible external malicious attacks to your applications.

c)   Database Layer Security

The PHI data is stored in database and to protect data, you should consider the following best practices for AWS based databases – Oracle, MSSQL, MySQL etc.

  • Enable access to the database only from the application tier by using necessary network security group(s) and Network Access Control List rules.
  • Enable encryption at AWS RDS level for Data at Rest and In-Transit

Note: Earlier before May 2017, the AWS HIPAA compliance program required that customers who are keeping PHI data using Amazon EC2 , they may needed to use dedicated instances or dedicated hosts, but this requirement has been removed now.

1.5)    Do we need to Segregate Prod and Non-Prod Environment?

Every Application may have Production and Non-Production environments as per development Team requirements. This Segregation serves as an obstacle and also limit environment from malicious attack and save it from technical issue. Also, it helps to control the user access as per environment and helps Security Team to gather the logs and enrich the data for Security Monitoring. Mostly the production environment will contain PHI data. You have to make sure that any non-Production environment must not get any PHI data from Production and there should be mechanism to track it.

 Note : If you are using any third part Application Monitoring then you have to see if it is HIPAA compliant before selecting it.  Example – Datadog log Management solution is HIPAA compliant so you can use it in your environment.

2) How Infosys assisted one of the Largest Pharmaceutical company

The Pharma company wanted to deploy their in-house/Third Party developed product in AWS cloud. It is Platform As Service based offering in production and Non-Prod environment which contain Protected Health Information (PHI) data. Infosys has analyzed their overall requirements for below client’s requirements

  1.  Client want to keep PHI data away from their own network
  2. The Platform As Service based solution  hosted  in AWS Cloud  should be completely owned by vendor in term of HIPAA compliance
  3. Client want to have Non-Prod and Prod setup for their application

To meet client requirement, we have suggested the followings

  1. AWS Cloud provider as CSP to host product in Infosys Owned cloud Tenancy.
  2. Infosys Architecture Team has reviewed and deployed AWS HIPAA eligible services
  3. Infosys has signed BAA contract document with AWS
  4. The business entities using the hosted products have signed BAA with Infosys
  5. Infosys architecture team segregated separately Non-Prod and Prod setups and make sure that there is no PHI data reside in Non-Prod setup
  6. Infosys has setup processes for HIPAA compliance and audit involving all stakeholders with RACI

3)   Conclusion:

The HIPAA Compliance is to protect patient PHI data and to follow the standard guideline given by US Department of Health and Human Services (HHS). In this article, we tried to clear the doubt of HIPAA compliance requirements , explained the HIPAA eligible AWS Services and how AWS is helping to maintain HIPAA compliant and also explained what role and responsibility of service provider who is maintaining the cloud hosted application/Infra. We also touched upon the topic of BAA requirements and what client has to do for AWS Account before storing PHI data in AWS Cloud by hosting HIPAA compliant application . In subsequence topic we discussed what is PaaS provider (Application hosting provider) responsibility to maintain the HIPAA for hosted application. We also explained how company can  implement the HIPAA compliance with help of example of Web, App and DB layer of application with important of segregation of environments. This way you can assist client to implement the HIPAA compliance in AWS Cloud which will be just start for Security Team to implement the HIPAA controls.

Enhance User Productivity and Improve Adoption of Oracle Content Management

 Businesses around the world prefer to manage the content for their usage centrally. This content could be related to different functions/processes such as sales, marketing, policies, training etc. Once this content is available in a single repository, web sites are generally developed for the end users to access this content. Key challenge is the ease of access to this content whenever user needs it, wherever user needs it. Apart from the websites, what if channels like intelligent chatbot is available for end users to search, fetch and access the content. Can this chatbot be seamlessly integrated with the commonly used tools like Microsoft teams or Slack.?

Oracle to the rescue

Oracle is the worldwide leader in providing SaaS and PaaS based solutions which spread across Customer Experience, ERP, HCM and more. Apart from these key solutions, Oracle also provides peripheral cloud services for Content Management and Conversational AI (chatbots) as well.

Oracle Content Management provides capability to create, publish and manage various types of content (documents, videos, images etc.).

Oracle Digital Assistant provides an AI platform to create conversational experiences for business applications through chat and voice interfaces. Let’s have a look at how these two cloud services can work in tandem to provide seamless experience to access the content easily and quickly.

Oracle Content Management (OCM)

Oracle Content Management is a cloud-based content hub. It is a PaaS service provided by Oracle Cloud Infrastructure (OCI). It offers powerful collaboration capabilities to streamline the creation and delivery of content and improve employee engagement. Organizations can create a repository of content which can be consumed by various users. This content can be published to different channels like websites, mobile, chat etc.

Key Solution Components are:

  • Repository: Repository is a logical storage location for all the assets. It is an entity which manages all the files/folders in a structured order.
  • Asset: An asset can be a content item that represents an individual piece of content, such as product literature, compliance documents, a blog post, case study, or a digital asset that represents an image, video, or other type of media.
  • Taxonomy: A taxonomy is a hierarchy of categories to allow asset categorizations and help users find assets. It represents how content across organization is defined and classified. For example, define taxonomies for products, branches, compliance type, roles or any other hierarchy of subject categories that is relevant for your organization.
  • Integration: Oracle Content Management provides REST APIs for content delivery. These APIs can be used by consuming systems, for example chatbots to search, fetch and display the content.

Oracle Digital Assistant (ODA)

Oracle Digital Assistant enables development of chatbots which understands natural language and can be interacted through voice or text. ODA powered by Natural Language Processing (NLP) can understand the user query and respond appropriately as per the skills it is trained for. ODA has API based integration capabilities which can fetch information from various sources.

  • Natural Language Processing: Allows creation of skills to cater to the user’s inputs and commands. The Digital Assistant takes care of the processing using inbuilt algorithms to understand the inputs.
  • Conversational flow and context: The context of the chat is maintained and based on the user input, the appropriate flow is invoked.
  • Enterprise Integration: Custom components can be created to integrate with multiple applications using APIs to fetch data and send data to the users.
  • Multi-Channel Support: Digital Assistant can be integrated with various channels, such as website, MS Teams which can carry the conversations back and forth from users on various messaging platforms to the digital assistant and its various skill bots.

Functional Flow

Oracle Digital Assistant integrated with Oracle Content Management can provide seamless access to content stored in Cloud.The following example flow suggests searching and accessing various documents by different means.

  • User can search documents by Categories.
  • User can search documents by Name.
  • User can search documents by Metadata (Content/Author)

Search by Categories

The user has an option to search by category hierarchy by choosing the category and then the Subcategory.  System displays all documents under the Subcategory hierarchy as hyperlink which user can click and download.

Search by Document Name

The user has an option to search the document using document name. The system searches the documents in the entire repository based on the document name and shows the documents as hyperlinks which user can click and download.

Search by Document Metadata (Content/Author)

The user has an option to search the document using document metadata. The system searches the documents in the entire repository-based document content, document author and other metadata and shows the documents as hyperlinks which user can click and download.

Architecture

The following diagram depicts the typical ODA architecture.

In this solution, ODA integrates with OCM to read metadata of the documents based on user inputs. A skill is created in ODA with different intents such as “List All Categories”, “Search Document By Content” and “Search Document by Name” for each of the options that user can choose. Based on the user selection the respective dialog flow is executed. System components built in node.js has the logic to integrate with OCM to retrieve data based on user inputs which is used by ODA to display as results. ODA has inbuilt capabilities for authentication using OAuth which is setup to enable authentication for APIs of external systems. OCM has built in Content Delivery APIs which are used to search documents, retrieve metadata of document to generate clickable URLs for document download. Below are the APIs which are used for this integration.

Get Taxonomy:

https://<<OCM_Host>>/content/published/api/v1.1/taxonomies?channelToken=<<channelToken>>&expand=children

Get Categories:

https://<<OCM_Host>>/content/published/api/v1.1/taxonomies/<<TaxonomyId>>/categories?channelToken=<<channelToken>>

Get Documents (By name, by metadata):

https://<<OCM_Host>>/content/published/api/v1.1/items?channelToken=<<channelToken>>

This skill can be used in different channels such as MS Teams, Intranet, Slack for use by end users. This skill can also be integrated with any other ODA based chatbot such as Oracle CX Sales in MS Teams which will provide a single window for end users for all conversations related to CRM.

Benefits

Integration of OCM with ODA provides the following benefits:

  • Content Adoption: Access to content easily and quickly over chat channel to increase the usage of content.
  • Increased Productivity: Employees can work more efficiently by accessing content at their fingertips.
  • Single Source: One repository for content across different departments.

Monday, May 6

Selenium Web Driver

 Selenium WebDriver is the most important component of Selenium Tool's Suite. The latest release "Selenium 2.0" is integrated with WebDriver API which provides a simpler and more concise programming interface.

The following image will give you a fair understanding of Selenium components and the Test Automation Tools.


Selenium WebDriver

Selenium WebDriver was first introduced as a part of Selenium v2.0. The initial version of Selenium i.e Selenium v1 consisted of only IDE, RC and Grid. However, with the release of Selenium v3, RC has been deprecated and moved to legacy package.

In WebDriver, test scripts can be developed using any of the supported programming languages and can be run directly in most modern web browsers. Languages supported by WebDriver include C#, Java, Perl, PHP, Python and Ruby.

Before learning the concepts of Selenium WebDriver, you should be well versed with any of the supported programming languages. Currently, Selenium Web driver is most popular with Java and C#. For this tutorial, we are using Selenium with java. You can refer to the links given below to learn basic as well as advance concepts of Java and C#:

Java Tutorial: https://www.javatpoint.com/java-tutorial

C# Tutorial: https://www.javatpoint.com/c-sharp-tutorial

Selenium WebDriver performs much faster as compared to Selenium RC because it makes direct calls to the web browsers. RC on the other hand needs an RC server to interact with the browser.

WebDriver has a built-in implementation of Firefox driver (Gecko Driver). For other browsers, you need to plug-in their browser specific drivers to communicate and run the test. Most commonly used WebDriver's include:

  • Google Chrome Driver
  • Internet Explorer Driver
  • Opera Driver
  • Safari Driver
  • HTML Unit Driver (a special headless driver)

Selenium WebDriver- Architecture

Selenium WebDriver API provides communication facility between languages and browsers.

The following image shows the architectural representation of Selenium WebDriver.


Selenium WebDriver Architecture

There are four basic components of WebDriver Architecture:

  • Selenium Language Bindings
  • JSON Wire Protocol
  • Browser Drivers
  • Real Browsers

Selenium Language Bindings / Selenium Client Libraries

Selenium developers have built language bindings/Selenium Client Libraries in order to support multiple languages. For instance, if you want to use the browser driver in java, use the java bindings. All the supported language bindings can be downloaded from the official website (https://www.seleniumhq.org/download/#client-drivers) of Selenium.

JSON Wire Protocol

JSON (JavaScript Object Notation) is an open standard for exchanging data on web. It supports data structures like object and array. So, it is easy to write and read data from JSON. To learn more about JSON, visit https://www.javatpoint.com/json-tutorial

JSON Wire Protocol provides a transport mechanism to transfer data between a server and a client. JSON Wire Protocol serves as an industry standard for various REST web services. To learn more about Web Services, visit https://www.javatpoint.com/web-services-tutorial

Browser Drivers

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. The browser driver is also specific to the language used for automation such as Java, C#, etc.

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

Browsers supported by Selenium WebDriver:

  • Internet Explorer
  • Mozilla Firefox
  • Google Chrome
  • Safari

Selenium WebDriver- Features

Some of the most important features of Selenium WebDriver are:

  • Multiple Browser Support: Selenium WebDriver supports a diverse range of web browsers such as Firefox, Chrome, Internet Explorer, Opera and many more. It also supports some of the non-conventional or rare browsers like HTMLUnit.


Selenium WebDriver Features

  • Multiple Languages Support: WebDriver also supports most of the commonly used programming languages like Java, C#, JavaScript, PHP, Ruby, Pearl and Python. Thus, the user can choose any one of the supported programming language based on his/her competency and start building the test scripts.
  • Speed: WebDriver performs faster as compared to other tools of Selenium Suite. Unlike RC, it doesn't require any intermediate server to communicate with the browser; rather the tool directly communicates with the browser.


Selenium WebDriver Features

  • 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:
    WebDriver driver = new Firefox Driver(); (Firefox browser )
    WebDriver driver = new Chrome Driver(); (Chrome browser)
    WebDriver driver = new Internet Explorer Driver(); (Internet Explorer browser)
  • WebDriver- Methods and Classes: WebDriver provides multiple solutions to cope with some potential challenges in automation testing.
    WebDriver also allows testers to deal with complex types of web elements such as checkboxes, dropdowns and alerts through dynamic finders.


Selenium WebDriver Features



Selenium WebDriver Vs Selenium RC

Selenium RC had a lot of limitations which eventually led to the development of Selenium WebDriver.

See the major differences between Selenium RC and Selenium WebDriver:

1. Architecture

The architecture of Selenium RC is complicated because it uses an intermediate RC Server to communicate with the browser. The RC Server is installed initially before running the test scripts and acts as mediator between your Selenium commands and your browser.

When we execute a test script in Selenium RC, the following operations are performed internally.

  • The server injects a JavaScript program known as Selenium Core into the browser.
  • Subsequently, Selenium Core will start receiving the instructions (Selenium commands) from the RC Server.
  • When all the instructions are received, Selenium Core will execute them as JavaScript commands.
  • These JavaScript commands act as instructions to the browser.
  • The browser will execute all of the instructions provided by Selenium Core and returns an overall summary to the Server. This overall summary acts as the final result which is displayed on the user screen.


Selenium WebDriver Vs Selenium RC

The architecture of Selenium WebDriver is simpler as compared to Selenium RC.

The browser is controlled directly from OS (Operating System) level. The basic requirements to run a test script on WebDriver are:

  • An IDE (Integrated Development Environment) with any of the supported programming language like Java, C#, etc.
  • A Browser to execute the instructions generated by the test script.


Selenium WebDriver Vs Selenium RC

2. Speed

Selenium WebDriver performs faster than Selenium RC because it interacts directly with the browser without using any external proxy server. Selenium RC, on the other hand uses an intermediate RC Server to communicate with the browser.

Execution of test scripts takes more time in Selenium RC than WebDriver, since it uses JavaScript commands as instructions to the browser.

3. Object Oriented

Selenium WebDriver is purely object oriented API, whereas Selenium RC is less object oriented API.

WebDriver is entirely based on object oriented programming languages like Java, C#, etc.

4. Testing Mobile Applications

Selenium WebDriver supports OS (Operating System) for mobile applications like iOS, windows mobile and android. On the other hand, Selenium RC doesn't support testing of mobile applications.

5. Browser Support

Selenium WebDriver also supports headless HTML Unit browser (Invisible Browser).

Selenium RC doesn't support the headless HTML Unit browser as it needs a real browser to work with.

Selenium WebDriver- Installation

Selenium WebDriver installation process is completed in four basic steps:

  1. Download and Install Java 8 or higher version.
  2. Download and configure Eclipse or any Java IDE of your choice.
  3. Download Selenium WebDriver Java Client
  4. Configure Selenium WebDriver

1. Download and Install Java

We assume that you have already installed Java 8 or above on your machine and successfully configured the environment variables required to run and compile java programs.

Note: you'll need to have Java 8 installed to use Selenium 3.

However, you can download the latest version of Java Development Kit (JDK) from the link given below.

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Once you have downloaded and installed the latest version of Java, you need to set path or configure the environment variables in your system. Refer the link given below to understand how we can set path and configure environment variables in Java.

https://www.javatpoint.com/how-to-set-path-in-java

2. Download and Configure Eclipse IDE

  • Open URL: https://www.eclipse.org/downloads/ .
  • Click on the "Download Packages" link (you can also download the IDE directly from the "downloads page" of Eclipse official website, but we will recommend you to navigate through the download packages section and get "Eclipse IDE for Java Developers").

Selenium WebDriver Installation
  • It will redirect you to the "Download Packages" section. Scroll down through the webpage and click on "Eclipse IDE for Java Developers".

Selenium WebDriver Installation
  • Go to the Download Links section and click on "Windows 64-bit". You can also select other options to download based on the operating system you are currently working on.

Selenium WebDriver Installation
  • The downloaded file would be in zipped format. Unpack the contents in a convenient directory.

Selenium WebDriver Installation
  • Double click on "eclipse" (.exe file).

Selenium WebDriver Installation
  • To configure the workspace, select a convenient directory where you want to keep all of your Selenium trails and click on Launch button.

Selenium WebDriver Installation
  • It will launch the default interface of Eclipse IDE.

Selenium WebDriver Installation

3. Download Selenium WebDriver Java Client

  • Open URL: https://docs.seleniumhq.org/download/
    It will redirect you to the "downloads page" of Selenium official website.
  • Scroll down through the web page and locate Selenium Client & WebDriver Language Bindings.
  • Click on the "Download" link of Java Client Driver as shown in the image given below.

Selenium WebDriver Installation
  • The downloaded file would be in zipped format. Unpack the contents in a convenient directory. It contains the essential jar files required to configure Selenium WebDriver in Eclipse IDE.

Selenium WebDriver Installation

4. Configure Selenium WebDriver

Now we will configure our Eclipse IDE with Selenium WebDriver. In simple terms, we will create a new Java Project in Eclipse and load all the essential jar files in order to create Selenium Test Scripts.

  • Launch Eclipse IDE
  • Create a new Java Project from File > New > Java Project.

Selenium WebDriver Installation
  • Give your Project name as "Demo_Test", leave the other fields unaltered and click on "Finish" button.
  • It will create a new Java project with the following directories.

Selenium WebDriver Installation

Note: Selenium Test Scripts are always written in ".class" file in Java. Here the project "Demo_Test" act as a Test Suite that may contain one or more Selenium test cases/test scripts.

  • Right click on the "src" folder and create a new Class File from New > Class.

Selenium WebDriver Installation
  • Give your Class name as "First" and click on "Finish" button.

Selenium WebDriver Installation

Now, we will add the Selenium jar files in our Test Suite (Demo_Test).

  • Right click on "Demo_Test" folder and select Properties.

Selenium WebDriver Installation
  • It will launch the Properties window for our "Demo_Test" Test Suite.
  • Click on "Java Build Path" option from the left hand side panel.

Selenium WebDriver Installation
  • Switch to Libraries tab and click on "Add External JARs" button.

Selenium WebDriver Installation
  • Locate the directory where you have downloaded the Selenium jar files, select the respective jars and click on "Open" button.

Selenium WebDriver Installation
  • Repeat the same steps for the jars which are present under the "libs" folder.
  • Open "libs" folder, select all of the respective jar files and click on "Open" button.

Selenium WebDriver Installation
  • Once you get all the Selenium jar files in your Libraries tab, click on Apply and Close button.
  • The following image shows the directory structure of our "Demo_Test" test suite after adding Selenium jars.

Selenium WebDriver Installation

Hence, we have successfully configured Selenium WebDriver with Eclipse IDE. Now, we are ready to write our test scripts in Eclipse and run it in WebDriver.

Selenium WebDriver- First Test Case

In this section, you will learn how to create your First Selenium Automation Test Script.

Under this test, we will automate the following scenarios:

  • Invoke Google Chrome browser.
  • Open URL: www.google.com
  • Click on the Google Search text box.
  • Type the value "java t point tutorials"
  • Click on the Search button.

We will create our test case step by step to give you a complete understanding of each component in detail.

Step1. Launch Eclipse IDE and open project "Demo_Test" which we have created in the previous section (Configure Selenium WebDriver) of this Tutorial. We will write our first Selenium test script in the "First.class" file under the "Demo_Test" test suite.

Selenium WebDriver First Test Case

Note: To invoke a browser in Selenium, we have to download an executable file specific to that browser. For example, Chrome browser implements the WebDriver protocol using an executable called ChromeDriver.exe. These executable files start a server on your system which in turn is responsible for running your test scripts in Selenium.

Step2. Open URL: https://sites.google.com/a/chromium.org/chromedriver/downloads in your browser.

Step3. Click on the "ChromeDriver 2.41" link. It will redirect you to the directory of ChromeDriver executables files. Download as per the operating system you are currently on.


Selenium WebDriver First Test Case

For windows, click on the "chromedriver_win32.zip" download.


Selenium WebDriver First Test Case

The downloaded file would be in zipped format. Unpack the contents in a convenient directory.


Selenium WebDriver First Test Case

Note: Selenium developers have defined properties for each browser that needs the location of the respective executable files to be parsed in order to invoke a browser. For example, the property defined for Chrome browser - webdriver.chrome.driver, needs the path of its executable file - D:\ChromeDriver\chromedriver.exe in order to launch chrome browser.

Selenium WebDriver First Test Case

Step4. We would need a unique identification for the web elements like Google Search text box and Search button in order to automate them through our test script. These unique identifications are configured along with some Commands/Syntax to form Locators. Locators help us to locate and identify a particular web element in context of a web application.

The method for finding a unique identification element involves inspection of HTML codes.

  • Open URL: https://www.google.com in your Chrome browser.
  • Right click on the Google search text box and select Inspect Element.


Selenium WebDriver First Test Case

  • It will launch a window containing all the specific codes involved in the development of the test box.


Selenium WebDriver First Test Case

  • Pick the value of id element i.e. "lst-ib".


Selenium WebDriver First Test Case

  • Given below is the Java syntax for locating elements through "id" in Selenium WebDriver.
    1. driver.findElement(By.id (<element ID>))  
  • Here is the complete code for locating Google Search text box in our test script.
    1. driver.findElement(By.id ("lst-ib"))  
  • Now, right click on the Google Search button and select Inspect Element.


Selenium WebDriver First Test Case

  • It will launch a window containing all the specific codes involved in the development of the Google Search button.


Selenium WebDriver First Test Case

  • Pick the value of name element i.e. "btnK".


Selenium WebDriver First Test Case

  • Given below is the Java syntax for locating elements through "name" in Selenium WebDriver.
    1. driver.findElement(By.name (<element name>))  
  • Here is the complete code for locating Google Search button in our test script.
    1. driver.findElement(By.name ("btnK"))  

Step5. Now it is time to code. We have embedded comments for each block of code to explain the steps clearly.

  1. import org.openqa.selenium.By;  
  2. import org.openqa.selenium.WebDriver;  
  3. import org.openqa.selenium.chrome.ChromeDriver;  
  4.   
  5. public class First {  
  6.   
  7.     public static void main(String[] args) {  
  8.         
  9.     // declaration and instantiation of objects/variables  
  10.     System.setProperty("webdriver.chrome.driver""D:\\ChromeDriver\\chromedriver.exe");  
  11.     WebDriver driver=new ChromeDriver();  
  12.       
  13. // Launch website  
  14.     driver.navigate().to("http://www.google.com/");  
  15.           
  16.     // Click on the search text box and send value  
  17.     driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");  
  18.           
  19.     // Click on the search button  
  20.     driver.findElement(By.name("btnK")).click();  
  21.       
  22.     }  
  23.   
  24. }  

The Eclipse code window will look like this:


Selenium WebDriver First Test Case

Step6. Right click on the Eclipse code and select Run As > Java Application.


Selenium WebDriver First Test Case

Step7. The output of above test script would be displayed in Google Chrome browser.


Selenium WebDriver First Test Case

Explanation of the Code

Import Packages/Statements

In java, import statements are used to import the classes present in another packages. In simple words, import keyword is used to import built-in and user-defined packages into your java source file.

  1. org.openqa.selenium.WebDriver - References the WebDriver interface which is required to instantiate a new web browser.
  2. 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.

Instantiating objects and variables

A driver object is instantiated through:

WebDriver driver=new ChromeDriver();  

Launch Website

To launch a new website, we use navigate().to() method in WebDriver.

driver.navigate().to("http://www.google.com/");  

Click on an element

In WebDriver, user interactions are performed through the use of Locators which we would discuss in later sessions of this tutorial. For now, following instance of code is used to locate and parse values in a specific web element.

driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");  

Selenium WebDriver- Commands

As we have discussed earlier in the IDE section, Selenium commands are the set of commands that are used to run our Selenium tests.

In Selenium WebDriver, we have an entirely different set of commands for performing different operations. Since we are using Selenium WebDriver with Java, commands are simply methods written in Java language.

Note: A java method is a collection of statements that are grouped together to perform a specific operation.

Before getting into the details of commands provided by Selenium WebDriver, we insist you to go through the Java OOPs (Object-Oriented Programming) concepts in java programming language. You can also refer to our Java OOPs concepts section provided in the Java Tutorial.

Now, the question arises is that how can we access methods provided by WebDriver.

Till now, we have successfully created our first test script in Selenium WebDriver. Therefore, one possible way to view the methods provided by WebDriver is to open the Eclipse IDE loaded with Selenium Webdriver jar files, create a driver object for WebDriver and press the dot key. It will show you all of the possible methods provided by WebDriver.

Selenium WebDriver Commands

Let us consider an example form the suggestions displayed by Eclipse to understand the syntax of the methods provided by WebDriver.

Selenium WebDriver Commands

Method Name

To access any method of any class, we need to create an object of class and then all the public methods will appear for the object.

Parameter

A parameter is an argument which is passed to a method to perform some specific operation.

Return type

Methods can return a value or returning nothing (void). If the void is mentioned after the method, it means, the method is returning no value. If it is returning a value, then it must display the type of the value for e.g. getTitle(): String.

Now, we will discuss the various commands provided by WebDriver. The commands provided by Selenium WebDriver can be broadly classified in following categories:

  1. Browser Commands
  2. Navigation Commands
  3. WebElement Commands

Given below are some of the most commonly used Selenium commands in WebDriver:

1. Fetching a web page

There are two methods to fetch a web page:

  • Using Get method
  1. driver.get("www.javatpoint.com")  
  • Using Navigate method
  1. driver.navigate().to("https://javatpoint.com/selenium-tutorial");  

2. Locating forms and sending user inputs

  1. driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");  

3. Clearing User inputs

The clear() method is used to clear the user inputs from the text box.

  1. driver.findElement(By.name("q")).clear();  

4. Fetching data over any web element

Sometimes we need to fetch the text written over a web element for performing some assertions and debugging. We use getText() method to fetch data written over any web element.

  1. driver.findElement(By.id("element567")).getText();  

5. Performing Click event

The click() method is used to perform click operation on any web element.

  1. driver.findElement(By.id("btnK")).click();  

6. Navigating backward in browser history

  1. driver.navigate().back();  

7. Navigating forward in browser history

  1. driver.navigate().forward();  

8. Refresh/ Reload a web page

  1. driver.navigate().refresh();  

9. Closing Browser

  1. driver.close();  

10. Closing Browser and other all other windows associated with the driver

  1. driver.quit();  

11. Moving between Windows

  1. driver.switchTo().window("windowName");  

13. Moving between Frames

  1. driver.switchTo().frame("frameName");  

14. Drag and Drop

Drag and Drop operation is performed using the Action class.

  1. WebElement element = driver.findElement(By.name("source"));  
  2. WebElement target = driver.findElement(By.name("target"));  
  3.   
  4. (new Actions(driver)).dragAndDrop(element, target).perform();  

Let us consider a sample test script which will cover most of the commonly used WebDriver commands.

For our test purpose, we are using a dummy web page under the URL:

https://www.testandquiz.com/selenium/testing.html

The default interface of the web page looks like this:

Selenium WebDriver Commands

You can also use this dummy web page for your Selenium Testing practice.

First you need to download the browser driver for the browser on which you are willing to automate your test scenarios. We have already discussed execution of Selenium test scripts on different browsers in the previous sections of this tutorial.

For this test, we are using Firefox Gecko driver to automate our test scenarios on Firefox browser.

Below is the sample test script with embedded comments.

  1. import org.openqa.selenium.By;  
  2. import org.openqa.selenium.WebDriver;  
  3. import org.openqa.selenium.firefox.FirefoxDriver;  
  4. import org.openqa.selenium.remote.DesiredCapabilities;  
  5. import org.openqa.selenium.support.ui.Select;  
  6.   
  7. public class Second {  
  8.   
  9.     public static void main(String[] args) {  
  10.           
  11.           // System Property for Gecko Driver   
  12.     System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );  
  13.           
  14.          // Initialize Gecko Driver using Desired Capabilities Class  
  15.         DesiredCapabilities capabilities = DesiredCapabilities.firefox();  
  16.         capabilities.setCapability("marionette",true);  
  17.         WebDriver driver= new FirefoxDriver(capabilities);  
  18.           
  19.         // Launch Website  
  20.      driver.navigate().to("https://www.testandquiz.com/selenium/testing.html");  
  21.       
  22.         // Fetch the text "This is sample text." and print it on console  
  23.         // Use the class name of the div to locate it and then fetch text using getText() method  
  24.      String sampleText = driver.findElement(By.className("col-md-12")).getText();  
  25.      System.out.println(sampleText);  
  26.           
  27.           // Use the linkText locator method to find the link and perform click using click() method  
  28.      driver.findElement(By.linkText("This is a link")).click();  
  29.        
  30.           // Click on the textbox and send value  
  31.      driver.findElement(By.id("fname")).sendKeys("JavaTpoint");  
  32.        
  33.         // Clear the text written in the textbox  
  34.      driver.findElement(By.id("fname")).clear();  
  35.           
  36.         // Click on the Submit button using click() command  
  37.      driver.findElement(By.id("idOfButton")).click();  
  38.    
  39.         // Locate the radio button by id and check it using click() function  
  40.      driver.findElement(By.id("male")).click();  
  41.           
  42.         // Locate the checkbox by cssSelector and check it using click() function  
  43.      driver.findElement(By.cssSelector("input.Automation")).click();  
  44.               
  45.         // Use Select class for selecting value from dropdown  
  46.     Select dropdown = new Select(driver.findElement(By.id("testingDropdown")));  
  47.     dropdown.selectByVisibleText("Automation Testing");  
  48.        
  49.         // Close the Browser  
  50.              driver.close();  
  51.       
  52.     }  
  53.   
  54. }  

Selenium WebDriver- Running test on Chrome Browser

In this section, you will learn how to run your Selenium Test Scripts on Chrome Browser.

Chrome browser implements the WebDriver protocol using an executable called ChromeDriver.exe. This executable start a server on your system which in turn is responsible for running your test scripts in Selenium.

Let us consider a test case in which we will try to automate the following scenarios in Google Chrome browser.

  • Launch Chrome browser.
  • Maximize the browser.
  • Open URL: www.javatpoint.com
  • Scroll down through the web page
  • Click on "Core Java" link from the Java Technology section.

We will create our third test case in the same test suite (Demo_Test).

Step1. Right click on the "src" folder and create a new Class File from New > Class.

Give your Class name as "Third" and click on "Finish" button.


Selenium WebDriver- Running test on Chrome Browser
Selenium WebDriver Running test on Chrome Browser

Step2. Open URL: https://sites.google.com/a/chromium.org/chromedriver/downloads in your browser.

Step3. Click on the "ChromeDriver 2.41" link. It will redirect you to the directory of ChromeDriver executables files. Download as per the operating system you are working currently on.


Selenium WebDriver Running test on Chrome Browser

For windows, click on the "chromedriver_win32.zip" download.


Selenium WebDriver Running test on Chrome Browser

The downloaded file would be in zipped format. Unpack the contents in a convenient directory.


Selenium WebDriver Running test on Chrome Browser

Step4. Set a system property "webdriver.chrome.driver" to the path of your ChromeDriver.exe file and instantiate a ChromeDriver class.

Here is a sample code to do that.

  1. // System Property for Chrome Driver   
  2.     System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe");  
  3.       
  4.        // Instantiate a ChromeDriver class.       
  5.     WebDriver driver=new ChromeDriver();  

Step5. Now it is time to code. We have embedded comments for each block of code to explain the steps clearly.

  1. import org.openqa.selenium.By;  
  2. import org.openqa.selenium.JavascriptExecutor;  
  3. import org.openqa.selenium.WebDriver;  
  4. import org.openqa.selenium.chrome.ChromeDriver;  
  5.   
  6. public class Third {  
  7.   
  8.     public static void main(String[] args) {  
  9.       
  10.            // System Property for Chrome Driver   
  11.         System.setProperty("webdriver.chrome.driver""D:\\ChromeDriver\\chromedriver.exe");  
  12.           
  13.              // Instantiate a ChromeDriver class.     
  14.         WebDriver driver=new ChromeDriver();  
  15.           
  16.            // Launch Website  
  17.         driver.navigate().to("http://www.javatpoint.com/");  
  18.           
  19.          //Maximize the browser  
  20.           driver.manage().window().maximize();  
  21.           
  22.           //Scroll down the webpage by 5000 pixels  
  23.         JavascriptExecutor js = (JavascriptExecutor)driver;  
  24.         js.executeScript("scrollBy(0, 5000)");   
  25.           
  26.          // Click on the Search button  
  27.         driver.findElement(By.linkText("Core Java")).click();     
  28.   
  29.     }  
  30.   
  31. }  

The Eclipse code window will look like this:


Selenium WebDriver Running test on Chrome Browser

Step6. Right click on the Eclipse code and select Run As > Java Application.


Selenium WebDriver Running test on Chrome Browser

Step6. The output of above test script would be displayed in Chrome browser.


Selenium WebDriver Running test on Chrome Browser

Selenium WebDriver- Running test on Firefox Browser- Gecko (Marionette) Driver

In this section, we will learn how to run your Selenium Test Scripts on Firefox Browser.

Before proceeding with this section, let us first understand the basics of Gecko Driver.

What is Gecko Driver?

The term Gecko refers to Gecko browser engine which was developed by Mozilla Foundation as a part of Mozilla browser.

Gecko Driver serves as a link between your tests in Selenium and the Firefox browser. It acts as a proxy between W3C WebDriver-compatible clients (Eclipse, Netbeans, etc.) to interact with Gecko-based browser (Mozilla Firefox).

Marionette (the next generation of FirefoxDriver) is turned on by default from Selenium 3. Selenium uses W3C Webdriver protocol to send requests to GeckoDriver, which translates them into a protocol named Marionette. Even if you are working with older versions of Firefox browser, Selenium 3 expects you to set path to the driver executable by the webdriver.gecko.driver.

Note: Selenium 3 has upgraded itself to now launch Firefox driver using Marionette driver instead of the default initialisation supported earlier.

Let us consider a test case in which we will try to automate the following scenarios in Firefox browser.

  • Launch Firefox browser.
  • Open URL: www.javatpoint.com
  • Click on the Custom Search text box
  • Type the value "Java"
  • Click on the Search button.

We will create our second test case in the same test suite (Demo_Test).

Step1. Right click on the "src" folder and create a new Class File from New > Class.

Give your Class name as "Second" and click on "Finish" button.


Selenium WebDriver Running test on Firefox Browser Gecko Driver
Selenium WebDriver Running test on Firefox Browser Gecko Driver

Step2. Open URL: https://github.com/mozilla/geckodriver/releases in your browser and click on the appropriate version for GeckoDriver download based on the operating system you are currently working on. Here, we are downloading the 64bit version of GeckoDriver for windows.


Selenium WebDriver Running test on Firefox Browser Gecko Driver

The downloaded file would be in zipped format. Unpack the contents in a convenient directory.


Selenium WebDriver Running test on Firefox Browser Gecko Driver

Before writing the test script, let us first understand how we can initialize GeckoDriver in Selenium. There are three ways to initialize GeckoDriver:

1. Using Desired Capabilities

First, we have to set the system property for Gecko Driver.

  1. System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );  

Below is the code to set gecko driver using DesiredCapabilities class.

  1. DesiredCapabilities capabilities = DesiredCapabilities.firefox();  
  2.         capabilities.setCapability("marionette",true);  

Here is the complete code:

  1. System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );  
  2.         DesiredCapabilities capabilities = DesiredCapabilities.firefox();  
  3.         capabilities.setCapability("marionette",true);  
  4.         WebDriver driver= new FirefoxDriver(capabilities);  

2. Using marionette property:

Gecko Driver can also be initialized using marionette property.

  1. System.setProperty("webdriver.firefox.marionette","D:\\GeckoDriver\\geckodriver.exe");  

The code for Desired Capabilities is not required for this method.

3. Using Firefox Options:

Firefox 47 or later versions have marionette driver as a legacy system. Thus, marionette driver can be called using Firefox Options as shown below.

  1. FirefoxOptions options = new FirefoxOptions();  
  2.     options.setLegacy(true);  

Step3. Now it is time to code. We have embedded comments for each block of code to explain the steps clearly.

  1. import org.openqa.selenium.By;  
  2. import org.openqa.selenium.WebDriver;  
  3. import org.openqa.selenium.firefox.FirefoxDriver;  
  4. import org.openqa.selenium.remote.DesiredCapabilities;  
  5.   
  6. public class Second {  
  7.   
  8.     public static void main(String[] args) {  
  9.           
  10.           // System Property for Gecko Driver   
  11. System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );  
  12.           
  13.           // Initialize Gecko Driver using Desired Capabilities Class  
  14.     DesiredCapabilities capabilities = DesiredCapabilities.firefox();  
  15.     capabilities.setCapability("marionette",true);  
  16.     WebDriver driver= new FirefoxDriver(capabilities);  
  17.           
  18.          // Launch Website  
  19.     driver.navigate().to("http://www.javatpoint.com/");  
  20.           
  21.         // Click on the Custom Search text box and send value  
  22.     driver.findElement(By.id("gsc-i-id1")).sendKeys("Java");  
  23.           
  24.         // Click on the Search button  
  25. driver.findElement(By.className("gsc-search-button gsc-search-buttonv2")).click();    
  26.         }  
  27.   
  28. }  

The Eclipse code window will look like this:


Selenium WebDriver Running test on Firefox Browser Gecko Driver

Step4. Right click on the Eclipse code and select Run As > Java Application.


Selenium WebDriver Running test on Firefox Browser Gecko Driver

Step5. The output of above test script would be displayed in Firefox browser.


Selenium WebDriver Running test on Firefox Browser Gecko Driver

Selenium WebDriver- Running test on IE Browser

In this section, you will learn how to run your Selenium Test Scripts on IE Browser.

Internet Explorer implements the WebDriver protocol using Internet Explorer Driver Server. The Internet explorer Driver Server is the link between your tests in Selenium and the Internet Explorer Browser.

Let us consider a test case in which we will try to automate the following scenarios in IE browser.

We will create our fourth test case in the same test suite (Demo_Test).

Step1. Right click on the "src" folder and create a new Class File from New > Class. Give your Class name as "Fourth" and click on "Finish" button.


Selenium WebDriver Running test on IE Browser
Selenium WebDriver Running test on IE Browser

Step2. Open URL: http://selenium-release.storage.googleapis.com/index.html?path=2.48/ in your browser.

Step3. Choose the latest version and download as per the operating system you are currently working on.

For windows 64 bit, click on the "IEDriverServer x64 2.48.0 zip" download.


Selenium WebDriver Running test on IE Browser

The downloaded file would be in zipped format. Unpack the contents in a convenient directory.


Selenium WebDriver Running test on IE Browser

Step4. Set a system property "webdriver.ie.driver" to the path of your IEDriverServer.exe file and instantiate an IEDriver class.


Here is a sample code to do that.

  1. // System Property for IEDriver   
  2. System.setProperty("webdriver.ie.driver""D:\\IE Driver Server\\IEDriverServer.exe");  
  3.           
  4.      // Instantiate a IEDriver class.     
  5. WebDriver driver=new InternetExplorerDriver();  

Step5. Now it is time to code. We have embedded comments for each block of code to explain the steps clearly.

  1. import org.openqa.selenium.By;  
  2. import org.openqa.selenium.WebDriver;  
  3. import org.openqa.selenium.ie.InternetExplorerDriver;  
  4.   
  5. public class Fourth {  
  6.   
  7.     public static void main(String[] args) {  
  8.       
  9.             // System Property for IEDriver   
  10.         System.setProperty("webdriver.ie.driver""D:\\IE Driver Server\\IEDriverServer.exe");  
  11.           
  12.            // Instantiate a IEDriver class.       
  13.         WebDriver driver=new InternetExplorerDriver();  
  14.           
  15.            // Launch Website  
  16.         driver.navigate().to("http://www.google.com/");  
  17.           
  18.            //Maximize the browser  
  19.           driver.manage().window().maximize();  
  20.             
  21.            // Click on the search text box and send value  
  22.         driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");  
  23.               
  24.            // Click on the search button  
  25.         driver.findElement(By.name("btnK")).click();  
  26.             
  27.   
  28.     }  
  29.   
  30. }  

The Eclipse code window will look like this:


Selenium WebDriver Running test on IE Browser


Step6. Right click on the Eclipse code and select Run As > Java Application.


Selenium WebDriver Running test on IE Browser

Step6. The output of above test script would be displayed in Internet Explorer browser.


Selenium WebDriver Running test on IE Browser

Selenium WebDriver- Running test on Safari Browser

In this section, we will learn how to run our Selenium Test Scripts on Safari Browser.

Safari Browser implements the WebDriver protocol using SafariDriver. The SafariDriver is the link between your tests in Selenium and the Safari Browser. SafariDriver has been implemented as a plugin in safari browser and this provides a perfect match of client and server machine where SafariDriverServer acts as server and Selenium-Java/Language binding acts as client.

Note: Previously SafariDriver was supporting safari browser on Windows machine but recently Apple has decided to remove its support for windows and then execution on safari has become the job of Mac machine. So for the same, we need mac machine where safari browser should be installed.

Let us consider a test case in which we will try to automate the following scenarios in Safari browser.

  • Launch Safari browser.
  • Open URL: www.google.com
  • Type the value "javatpoint tutorials"
  • Click on the Search button.
  • Close the browser

We will create our fifth test case in the same test suite (Demo_Test).

Step1. Right click on the "src" folder and create a new Class File from New > Class. Give your Class name as "Fifth" and click on "Finish" button.

Selenium WebDriver Running test on Safari Browser Selenium WebDriver Running test on Safari Browser

Step2. Open URL: https://www.seleniumhq.org/download/ in your Safari browser. It will direct you to the 'downloads' page of Selenium official website. Scroll down through the web page and locate SafariDriver.

Step3. Click on the "Latest Release" option to download the latest version of SafariDriver.

Selenium WebDriver Running test on Safari Browser

Step4. Double click on the downloaded file.

Selenium WebDriver Running test on Safari Browser

This will launch a pop-up box on your Safari browser extension window. Click on the "Trust" button to configure WebDriver in your Safari browser.

Selenium WebDriver Running test on Safari Browser


Selenium WebDriver Running test on Safari Browser

Step5. Restart your browser.

Before writing the test script, let us first understand how we can initialize SafariDriver in Selenium. Safari browser is represented by a class called SafariDriver in the org.openqa.selenium.safari package. All we have to do is to create an instance of SafariDriver class.

Here is a sample code to do that:

  1. WebDriver driver = new SafariDriver();  

Step6. Now, it is time to code. We have embedded comments for each block of code to explain the steps clearly.

  1. import org.openqa.selenium.By;  
  2. import org.openqa.selenium.WebDriver;  
  3. import org.openqa.selenium.safari.SafariDriver;  
  4.   
  5. public class Fifth {  
  6.   
  7.     public static void main(String[] args) {  
  8.           
  9.           // Instantiate a SafariDriver class.    
  10.         WebDriver driver = new SafariDriver();  
  11.   
  12.           // Launch Website  
  13.         driver.navigate().to("http://www.google.com/");  
  14.               
  15.           // Click on the search text box and send value  
  16.         driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");  
  17.               
  18.           // Click on the search button  
  19.         driver.findElement(By.name("btnK")).click();  
  20.           
  21.           // Close the Browser  
  22.         driver.close();  
  23.           
  24.     }  

The Eclipse code window will look like this:

Selenium WebDriver Running test on Safari Browser

Step7. Right click on the Eclipse code and select Run As > Java Application.

Selenium WebDriver Running test on Safari Browser

Upon execution, the above test script will launch the Safari browser and automate all the test scenarios.



Holiday Gift Guide: Unique Finds for Everyone on Your List

  Holiday Gift Guide is all about finding unique and thoughtful presents that cater to different tastes and needs. Whether you’re shopping ...