Author: admin

Cookies in selenium

Cookies in selenium

Level5, Selenium
Cookies: Cookie is a piece  of information from website and saved by your web browser Cookies are a way of remembering users and their interaction with the site by storing information in the cookie file as key value pairs. It stores the login information like user name / email and password HTTP cookie is also known as a web cookie, a browser cookie or Internet cookie. One website cannot access the cookies set by other websites   Handling Cookie in Selenium : Each cookie is associated with a name, value, domain, path, termination, and status of whether it is safe or not. We validate the cookie using selenium,  selenium can parse all the cookies When testing a web application using the Selenium, you may need to create, update or delete a cookie to check the
Webdriver Listeners in Selenium | WebDriverEventListener

Webdriver Listeners in Selenium | WebDriverEventListener

Level7, Selenium
Webdriver Listeners in Selenium : Event listener in WebDriver helps to tack event those we trigger and by using these we could get a better idea of sequential order of actions . Listeners are  helpful for logging and exception section. Suppose you are trying to track exception and the same time wants to take screenshot. Instead of hard-coding logging requests all over the place, we can leverage an event listener to give us the information we want If you think, Listeners are only useful in logging then you are wrong, it more helpful on pre and post steps of a action in selenium webdriver. Selenium provide WebDriverEventListener interface for listening event in selenium, WebDriverEventListener Interface provide methods, which covers most of the actions (not all) in selenium we
Navigation Commands in Selenium | To() | back() | forward() | refresh()

Navigation Commands in Selenium | To() | back() | forward() | refresh()

Level1, Selenium
Navigation Commands : Navigation commands are used to navigate from one web page to another web page, Navigation commands also helps to navigate through browser history like back forth or to refresh the current page.   To() : If you wants to navigate on specific web application page or URL in between your software test then you can use driver.navigate().to('url") command . driver.navigate().to("http://google.com/"); Back(): We can go back to previous page with driver.navigate().back() command. driver.navigate().back(); Forward(): We can go forward from current page to last opened page with driver.navigate().next() command, but for using forward() method, you must have navigated back first. driver.navigate().forward(); Refresh(): We can refresh
Open Browser in Selenium

Open Browser in Selenium

Automation, Level1, Selenium
Opening a browser with binary File: There will be situations, where you have to test your web application against two different versions of the  browser. For example consider FireFox, By default, when you create object to FirefoxDriver, the Firefox version that is available on the PATH variable is launched. But if you want to launch a different version of Firefox, we need to use Firefox Binary, or if the browser is not in the standard PATH then you should specify the browser binary file location to open the browser. public static void main(String[] args) { File pathToBinary = new File("C:\\PATH\\App\\Firefox\\firefox.exe"); FirefoxBinary firefoxBinary = new FirefoxBinary(pathToBinary); FirefoxProfile firefoxProfile = new FirefoxProfile(); WebDriver driver = new Firefo
Properties File in Selenium | Properties prop = new Properties()

Properties File in Selenium | Properties prop = new Properties()

Level6
Properties File in Selenium : Properties file is used to store project configuration data or settings in the the key value pair format. .properties is a file extension for files mainly used in Java related technologies to store the configurable parameters of an application. Each parameter is stored as a pair of strings, one storing the name of the parameter (called the key/map), and the other storing the value.   Properties Class in java: properties Class can be used to get property value based on the property key. The Properties class provides methods to get data from properties file and store data into properties file. Read  Properties file using Java Selenium: For reading the file we have to create a file with .properties and store some data in it. url = htttp://go
Robot Class in Selenium

Robot Class in Selenium

Level7, Selenium
Robot Class in Selenium : Robot Class is available under java.awt.package, Robot class is a Java class which helps the Java developer to emulate the Mouse and Keyboard like actual user, also robot class helps to take screenshot of the desktop Some platforms require special privileges or extensions to access low-level input control. If the current platform configuration does not allow input control, an AWTException will be thrown when trying to construct Robot objects. So, we need to use either AutoIT or Robot class in Selenium Webdriver to interact the Windows Dialog boxes like upload and download.   Use of Robot Class in Selenium: Robot class emulates real user in front of the computer Using Robot Class we can handle keyboard and mouse events in Selenium. Robot ...
Waits in Selenium | ImplicitWait | ExplicitWait | FluentWait | Sleep

Waits in Selenium | ImplicitWait | ExplicitWait | FluentWait | Sleep

Level3
Waits in selenium : In UI automation, waits are required because few elements get loaded on the page asynchronously,  so after triggering an event a page may get loaded successfully but some of its element may still not get loaded. Sometime Due to network issue an webpage elements load after sometime or with a delay. There is 3 different way to handle this using waits in Selenium: Implicit Waits Explicit Waits Fluent waits   Implicit Waits Implicit wait is set for the entire duration of your webdriver and is set at the start of your program. What it does is, in case while executing, if your webdriver doesn't finds any element then instead of throwing an exception, implicit wait makes your driver to wait for the specified wait time and then try to find the el
TestNG in Selenium

TestNG in Selenium

Level3, Popular, Selenium
TestNG Annotations : Annotations are nothing but a piece of instruction for the compiler that you apply to classes, methods or variables in your Java code. It is a powerful feature and an integral part of the TestNG framework.  The TestNG annotations extend the same concept and control the execution sequence of the test code and test methods   List of Annotations in TestNG: TestNG Annotations Description @Test Attaches a class or a method to become the part of the test. @BeforeTest Instructs the method to run before any test method related to the classes which are inside the <test> tag as per the testng.xml file @AfterTest Halts a method from execution till all the test methods finish their execution. These methods belong to the classes defined
Xpath in Selenium

Xpath in Selenium

Level2, Selenium
What is XPath : XPath (XML path) is the language for nodes in an XML document. Since many browsers support XHTML, we can use XPath to find items on web pages. XPath helps in finding direction of element through nodes and its attributes. in HTML pages.   Syntax of XPath:   Using tag and attributes It is possible to locate a specific web element with its HTML tag, its attributes such as Id, name, class, title, value, href, src etc., and their corresponding values. Syntax: "//tagName[@attribute='value']"; Identifies the element pointed by the XPath. ‘//’ identifies the specified node and ‘@’ symbol is used to select the specified attribute which matches the given value. //input[@name='FirstName'] //input[@id='abc']   Xpath with Index: By providing

ElementNotVisible Exception

Selenium
Selenium ElementNotVisibleException is also one of the frequent exceptions which we will face in selenium webdriver while automating any kind of application. This exception tells you that the WebElement that you are trying to interact with is not visible to the user. If the element is not visible to the user then they are not going to able to interact with it   Below are the causes to face this exception: Thrown to indicate that although an element is present on the DOM, it is not visible, and so is not able to be interacted with. To overcome this kind of situation we need to use synchronization concept in selenium. So, add an explicit wait to wait for the correct conditions to be met before trying to interact with the element. We have an option to use wait in so many ways ...

NoSuchWindow Exception

Selenium
Selenium NoSuchWindowException is similar to NoSuchFrameException, this is also one of the frequent exceptions which we will face in selenium webdriver.   Sometimes applications will have child windows(i.e. Separate windows) which will open when you click on any link or button.   Normally if you want to automate the child windows then you need to switch to that window then only you can interact with the elements which are there on that window.   To overcome this, we need to handle the opened windows using one of the webdriver methods called “driver.getWindowHandles()”.   Once  you have this information then you can switch to the corresponding window to automate or interact with the window.     Below are the causes to face this ex

NoSuchFrameException

Selenium
Selenium NoSuchFrameException will discuss about one of the frequent exceptions which we will face in selenium webdriver. You might face this kind of exception while automating the application if you have iFrames in your application.   In modern applications people are using iFrames very frequently as if you want to show the information from other sources then will use the frames in the application.   We will face this kind of exception in different kind of scenarios. Will discuss the reasons for this issue and we will know we can overcome this issue.     Below are the causes to face this exception: Let’s assume in your application if you have a frame and it contains some elements (for example we will take a textbox in this scenarios) and you wan

NoSuchElementException in Webdriver

Selenium
Selenium NoSuchElementException is the most and frequent facing exception. You will definitely find this kind of exception while automating the application. In this blog we will see what are the reasons to face this exception and how we can overcome this exception in detail.   Below are the reasons to get this exception: The locator which you are using to locate the element is incorrect/changed. The element which you are looking is not rendered. Trying to find the element before it was rendered.   Locator is Incorrect/changed: Here we have two possibilities that the locator which you have written to identify an element may be incorrect or sometimes after writing/capturing the code, if there are any changes in the application then the locator may change. ...
Exceptions in Webdriver

Exceptions in Webdriver

Level7, Selenium
In this tutorial, we  will discuss about what kind of exception we will get in selenium webdriver while executing the automation scripts. An exception is an infallible statement; it will always tell you why something has gone wrong in the code.   It may not always be easy to understand the exception, but it does always tell the information about the what is wrong in the code.   One of the good things in selenium is while looking into the exception we will come to know what went wrong as the exception names will give some what clear picture for the error which we will face.   Below are some of the Exceptions which we will see while automating the applications: NoSuchElementException NoSuchFrameException NoSuchWindowException ElementNotVisibleEx
JavaScript Executor in Selenium

JavaScript Executor in Selenium

Level7, Selenium
As JavaScript Executor is an interface so we cannot create an object to this, for this we will type caste to driver object using below syntax:   JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript(javaScript, arguments); Now we will see some of the examples below that how we can use JavaScriptExecutor to execute the JavaScript to interact with the web elements.   1. How to enter value into textbox: JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.getElementById('email').value='[email protected]'");   2. How to click a button: JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.querySelector('#enterimg').click()");   3. How to refresh a window: JavascriptExecutor js = (Javascri...
WebElement Actions

WebElement Actions

Automation, Level1, Selenium
In this selenium tutorial , we will learn all the different user actions that can be performed on an WebElement. Different WebElements will have different actions that can be taken on them. For example, in a textbar element, we can type in some text or clear the text that is already typed in it. Similarly for a button, we can click on it, get the dimensions of it, and position of it on the webpage, but we cannot type into a button, and for a link, we cannot type into it. All the actions are present as method in WebElement interface in selenium webdriver. In case we try to execute a wrong action on a WebElement, we don’t see any exception or error thrown and also we don’t see any action that really gets executed; WebDriver ignores such actions. The getAttribute() method The ge

What should be automated ?

Automation, Level1, Selenium
It's bee traditional thinking to... One to one mapping between manual tests and automated tests. Trying to have as much requirements and test case coverage as possible. Automated tests should be able be reproducible manually. But over the years, I've found that having 1000's of test cases I tend to cause even more problems. 1. Test code is harder to maintain which becomes production code. Besides the technical aspects like having to bend over backwards to accommodate changes in the software under test, it is also the lack of support from business and development for test code. For example, very few shops will hold up a release or delay development if there are broken tests or flaky tests.  The default is generally to comment those tests out..
Basic Selenium Commands

Basic Selenium Commands

Level1, Selenium
Get Command get() command is use to open a new web page in the current browser. Command: driver.get(“URL”); Example : driver.get("http://google.com");   Get Title Command getTitle() command is use to get the title of the current page. Example : driver.getTitle();   Get Current URL Command getCurrentUrl() command is use to get the URL of the page currently loaded in the browser. Example : driver.getCurrentUrl()   Close Command close() command is use to close the current window of the browser, if it’s the last window it will close the browser. Example : driver.close();   Quit Command quit() command is use to quit the browser and all the opened windows in the browser. Example : driver.quit();   Get Page Source Command