Showing posts with label Selenium 2. Show all posts
Showing posts with label Selenium 2. Show all posts

BrowserStack is web cloud platform which provides us an environment to test web and mobile applications on different version combinations of OS and browsers. BrowserStack provides limited access in Free trial version but you can get full access in Paid version's different plans. Many of you already aware about it's different features and usage. But still let me introduce you with browserstack little bit.

Earlier we already learn different selenium webdriver methods to add cookie, get cookies detail by name and all cookies. Sometimes you also need to delete all cookies from your browser in selenium webdriver test. Selenium Webdriver have built in deleteAllCookies() to Delete all cookies from current running browser window in test.

Earlier we learnt how to add cookie and get cookie details using different methods like addCookie(), getCookieNamed() and getCookies(). Sometimes you also need to delete cookie. Selenium webdriver have built in methods to delete cookies by deleteCookieNamed() or passing cookie object in deleteCookie() method.

Any site can have single or multiple cookies. If you know cookie name then you can get it's detail easily using getCookieNamed(). But if there are multiple cookies and you need all of them then you need to use getCookies(). It will retrieve all cookies of site you are navigating in selenium webdriver test. Here we will learn how to get all cookies using getCookies() and extracting all cookie detail using Java Set interface and Iterate through cookie set using Iterator.

Most of all you are already aware about browser cookie. Basically cookie is piece of data that is stored in your browser. It is sent from website you visit and mostly it is used to recognize if user return to website again. In sort, It tracks your website navigation journey. Cookie consist of different parameters like name, value, expiry, path, etc. Here we will see how can we add cookie and get cookie from browser in selenium webdriver using addCookie() and getCookieNamed().

Sometimes you need to set Dimension and Position of your browser window. Webdriver have built in Dimension and Position class with many different methods. We can use both these class and it's methods to set dimensions and positions of browser window. Let's see how we can use Dimension and Position methods to manage size and position

manage() method is very basic and we are using it very frequently in selenium WebDriver tests. You can use it to manage size and positions of browser window during your test. You can use it to add or delete cookie, get cookie, timeouts, waits and there are many other usages as well but here we will discuss about how to maximize browser or set it to full screen mode.

Many new learners are initially confused about when to use close() and when to use quit() method in Selenium WebDriver. close() method will close the current instance of the webdriver object reference. In simple word, It will close current window or tab on which your test is currently running. quit() methods will dispose webdriver object so it is also known as dispose method. In simple word, quit() methods will close all open browser tabs or windows.

As name suggest, getPageSource() method is useful to get source of last loaded web page. Please note here, If web page is modified(by javascript) after loading of page then getPageSource() may return page source of before modified page. You can get whole page source using this method and then you can use it as per your requirement.

Let's see how getPageSource() method can be used in selenium test.

Selenium Webdriver's findElement() method is useful to locate WebElement for page. It is one of the mostly used method in selenium webdriver. It uses By object as parameter can can use it with various element locating strategies like ID, Name, Linktext, Partial Linktext, Tag Name, Class Name, DOM Locator, CSS Selector and Xpath. findElement() will return first matching webelement from page.

Since last update of selenium 3, Most of the users(especially those who are new with selenium) are facing common issue with error "Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases" when try to execute test in firefox browser.

Configure Geckodriver In Selenium Test

  • LinkedHashMap class is one of the class of map interface which extends HashMap class and implements Map interface.
  • It is combination of linked list and Hash table implementation of the Map interface and that's why it is called LinkedHashMap.
  • It is maintaining doubly-linked list insertion order in which keys were inserted into the map.
  • It allows to store null elements and optional Map operations are also available.
  • It is non synchronized implementation so if any thread modifies map structurally when map is accessed by multiple threads then it must be synchronized externally.

  • Is is pronounced as HashMap because It is hash table based implementation of map interface.
  • It extends AbstractMap class and implements Map interface.
  • It allows to store null key and null values.
  • It is non synchronized implementation so if multiple threads accessing it concurrently and any one of them modifies it then it must be synchronized externally.
  • It does not guarantee of maintaining the map order.

  • Java Map interface represents the mapping between unique keys to values.
  • Map can not hold duplicate values.
  • In Map interface, Each key can map at most one value.
  • Each Map interface provides three different collection views. Using which you can view map's content as a set of keys, collection of values and set of key-value mappings.
  • Map will helps you when you wants to search, update or delete elements based on it's key.
  • The map interface is implemented by different java classes like HashTable, HashMap and TreeMap.

  • Hashtable Class implements Map, Cloneable and Serializable interfaces and also extends Dictionary class.
  • It maps keys to values in table format. Every key is linked to it's value.
  • In Hashtable, any object which is non null will be used as a key or it's value.
  • Initial capacity and load factor are two parameters of Hashtable that affect its performance.
  • Meaning of capacity is the number of buckets in Hashtable and Meaning of initial capacity is number of buckets in Hashtable at the time of its creation.
  • Load factor is parameter which measure how much full Hashtable is and when to increase it's capacity automatically.
  • In order to successfully retrieve and store object in Hashtable, the object which is used as key must implement the equals and the hashCode methods.

  • TreeSet is class under Set interface of collection framework.
  • It implements NavigableSet interface which extends SortedSet interface.
  • Elements are ordered by a Comparator which is provided at set creation time or by natural ordering.
  • It maintains the ascending sorting order.
  • TreeSet is not synchronized so if multiple threads accessing it concurrently and any one modifies set entry then it must be synchronized externally.
  • Element's access and retrieval time is very fast from TreeSet so it will much useful when you wants to store large information in ascending order and retrieve any element quickly.
Java TreeSet Class hierarchy

  • SortedSet interface extends Set interface in collection framework of java.
  • As name suggest, It provides total ordering on elements of Set.
  • Set elements will be ordered using their natural ordering or using a comparator interface.
  • All the elements entries of SortedSet must implement Comparable interface.
  • All the elements of SortedSet must be comparable. So e1.compareTo(e2) must not throw ClassCastException.
  • In collection framework, TreeSet class is an implementation for the SortedSet interface.
Java SortedSet Interface hierarchy

It Is most Important to learn shortcuts of eclipse IDE If you wants to speed up Selenium WebDriver test creation and execution process because performing each and every actions In eclipse using just mouse Is time consuming. If you knows keyboard shortcut keys to perform regular actions In eclipse then It will be very easy for you to do It within one second.

  • HashSet is a class of collection framework which extends AbstractSet class and implements the Set interface.
  • HasSet doesn't guarantee that elements order will remain same over the time and returned in any random order.
  • HasSet doesn't allow duplicate values. If you try to insert duplicate, It will overwrite.
  • HasSet allows to store null values.
  • HasSet implementation is not synchronized.
Hashset hierarchy in Java Collection

  • LinkedHashSet Class extends extends HashSet class and Implements Set interface in collection interface hierarchy.
  • LinkedHashSet implementation differs from HashSet as it maintains doubly-linked list running through all of its entries.
  • It maintains element's entries in set as per it's insertion order. So it will allow you insertion order iteration over the set. So when you iterate over LinkedHashSet, In which order it will return elements? Answer is As per it's insertion order.
  • So you will get same copy of elements with the order how they inserted in set. 
  • LinkedHashSetis not synchronized.
LinkedHashSet Class hierarchy