October 2, 2018

In this post we will see how to avoid downloading driver.exe file and setpath for browser binary.
As you guys already know in order to use chrome, firefox or edge browsers, first we need to download a binary file (driver.exe) and need to set path which allows Webdriver to handle browsers.

Below is example how to set path:

By adding a small dependency in your POM.xml (Assuming you are using maven project) we can avoid downloading binary files and set path.In addition, we have to check manually when new versions of the binaries are released. WebDriverManager will do this job for us automatically

How it works:

WebDriver Manager actually gets your browser version and download the compatible browser binary by itself to make you run your code without interruption.

So now, rather than setting the browser binaries, you just need to add below line of code and you’re done

The line WebDriverManager.chromedriver().setup(); WebDriverManager does magic for you:

Below is sample code:

Video is available here:

January 18, 2017

Git :Git is a version control system (VCS) for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for software development,but it can be used to keep track of changes in any files. As a distributed revision control system it is aimed at speed,data integrity and support for distributed, non-linear workflowsSteps to Install Git:

When you've successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation.While installing keep default options that will be ok for most of the users.Once the installation is done if you search for git you will see Git Bash and GitGUI.GitBash:Git for Windows provides a BASH emulation used to run Git from the command line. *NIX users should feel right at home, as the BASH emulation behaves just like the "git" command in LINUX and UNIX environments.

GitGUI:

Git for Windows also provides the Git GUI, a powerful alternative to Git BASH, offering a graphical version of just about every Git command line function, as well as comprehensive visual diff tools.

Shell Integration:Simply right-click on a folder in Windows Explorer to access the BASH or GUI.

In this article I will discuss about Git and GitHub.First question comes in everybody's mind, what is Git and what is GitHub. Both are same or different?GIT:Below is the definition from GIT official site. (https://git-scm.com/)Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiencyGit is a distributed version control system.There are two types of version control systems out there. “centralized” and “distributed”.Centralized:A single place everyone can check in and check out. Example :CVS, Subversion, and Perforce

Distributed:Every developer/user has their own repo. Everyone can push changes into a common repo. Example : Git, Mercurial, Bazaar or DarcsThe below diagram show the core difference.

Online project hosting using Git. It Includes source-code browser, in-line editing, wikis and ticketing. Free for public open-source code.GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere.GitHub is a web-based Git repository hosting service, which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features.Below are some of the advantages of GitHub:

Version control your projects

Push your projects to GitHub and let the world know how nice and useful code you write

Explore other’s projects on GitHub, get inspired code more, or contribute to their project

Collaborate with others, by letting other people contribute to your projects or you contributing to other’s projects

June 13, 2016

What is onchange event?The onchange event occurs when the value of an element has been changed.For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.onChange specifies script code to run when the data in the input field changes. The onChange event is triggered when the contents of the field changes.In this example if you type some thing in Quantity filed and click on anywhere on the page it will automatically update Total.

We can handle onchange events in different ways.

1. After entering quantity we can simulate clicking TAB button. But this is approach will not work always.

If you want to find descendants of Div tag you need to use below syntax//div[@id='browse-category']/descendant::*If you want a specific element from descendants then use below syntaxHere i want to identify Payment link using descendant.//div[@id='browse-category']/descendant::a[@data-category='Payment']In the above example descendant will search for child elements and child's child elements as well.UL is the child element for DIV and LI is the child element for UL and A is child element for LI. As we used descendant it will check for the matching element.Following:Selects
everything in the document after the closing tag of the current node.selects all elements after closing tag of P//p[@class='fk-font-14']/following::*

if you want a specific element using following below is the example

//p[@class='fk-font-14']/following::div[@id='fk-mainfooter-id']

Following-sibling:Selects
all siblings after the current node.//div[@id='browse-category']/ul/li/following-sibling::*if you want a specific element then//form[@class='faqsearchform']/following-sibling::div

Preceding:Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodespreceding-siblingSelects all siblings before the current nodeHere is the example://div[@id='browse-category']/preceding-sibling::form

Now Lets see a real time example how to use the above mentioned xpath Axes:Below is scenario:

Navigate to flipkart

add two products to cart

I want to remove one product based on its name.

Simple xpath without using product name --- //a[@class='cart-remove-item fk-inline-block fk-uppercase'] but it always identifies first Remove button.

First Step: I will identify xpath for product Name

//span[text()='HP 15-af114AU Notebook(AMD Quad Core A8/ 4GB/...']

From there onward using xpath Axes i need to identify Remove link.

By loooking at DOM we can understand that there are two TR tags

in one TR --we have product details and in another TR we have remove link.

so i have to traverse to second TR.

Second Step: Inorder to do that i need to traverse to parent element of span

October 30, 2015

How to run the selenium test scripts in Chrome/IE browser ?To run the selenium test cases in Chrome/IE browser is necessary and need of today's web world as Chrome being the one of the best and most widely used web browser.Selenium by default supports only Mozilla Firefox . To run your tests in Chrome browser please do the following set-up.1. Download chrome browser related jar file from here.2. Set the System configuration by adding the following code.System.setProperty("webdriver.chrome.driver", "Path to chrome related jar file downloaded in step 1");WebDriver driver = new ChromeDriver();To run the test in Internet explorer.1. Download IE browser related jar file from here.2. Set the System configuration by adding the following code.System.setProperty("webdriver.ie.driver", "C:\\Users\\ajain5\\Downloads\\IEDriverServer.exe");WebDriver driver = new InternetExplorerDriver();

October 20, 2015

Some of the applications that are secured with Basic Authentication. If you want to access those applications first you need to pass credentials. Those applications will launch a system level pop-up which cant not be handled by selenium.

October 7, 2015

Log file is just simple file, which keep track of the record or event or info when any event happens or any software run. This whole process known as logging. We can create log file as simple log file.Why Log file is required:We can create log file for our simple script also so we can track or debug our script easily if anything goes wrong in script. For example, if our script is failing at some point then we can track back what went wrongWhat is log4JLog4j is free open source tool for creating log files It help us to generate log file.Log4j is very lightweight and simple logging framework, comprising of three main componentsLoggersAppendersLayoutsDownload Log4J jar file.1. Navigate to http://mvnrepository.com/2. Search for Log4J3. Download latest version of log4J