Useful Jenkins Plugins: JobConfigHistory Plugin

This plugin comes in handy while creating/modifying Jenkins jobs. Once you install this plugin, there is small ‘spanner’ symbol next to the individual builds run

Screen Shot 2015-04-27 at 5.45.05 pm

Clicking on this spanner icon will show you an xml comparison between the configurations before and after the change on the respective jenkins job.

Screen Shot 2015-04-27 at 5.41.19 pm

Also there is a button called ‘Restore this configuration’ which will revert the configuration to the previous one. This comes in very handy while designing CI pipelines where in frequent changes/additions are made to the build process.

This is a must have plugin if you are a Jenkins user. 🙂

Hope this is helpful 🙂

Regards,

VJ

Steps to get Safari Webdriver running on Mac OSX

Since this topic has not been well documented on the net and I struggled myself to get Selenium tests running on Safari browser, here are the complete set of steps to get Selenium tests up and running on Safari browsers. :-

Creating “Safari Extension” Developer Certificate

  1. Create an Apple developer account.
  • Go to https://developer.apple.com/
  • Click on “Member Center” on top panel.
  • Select “Create Apple ID”.
  • Go through the sign up forms and provide valid fields for a succesful sign up

2.  Login to created Apple account.

3.  Sign up for “Safari Extensions” developer

  • Click on “Certificates, Identifiers & Profiles”
  • In the “Safari Extensions’ section, click on “Join Now”
  • Go through the following steps and provide valid fields to successfully sign up for the “Safari Extensions” program

4.  Create “Developer Certificate”

  • Now inside “Certificates, Identifiers & Profiles” > “Click on Create/Add Safari Certificate”
  • You will see the following page – “About Creating a Certificate Signing Request (CSR)” Screen Shot 2015-04-15 at 1.40.24 pm
  • Click on “Continue”

You will see the following page :-Screen Shot 2015-04-15 at 1.40.42 pm

  • Upload the CSR file and Click on ‘Generate’ to generate the certificate
  • Now download the certificate once it is generated.

5. Download the certificate and install in the machine

  • Download the certificate in the download tab.
  • The certificate is downloaded as “safari_extension.cer”.
  • Double-click on the file to install the certificate in the Mac client/OSX.

6.  We have installed the safari extensions certificate for developers. Now we need to install the Safari Webdriver extension for the Safari Browser.

 Installing the Safari Webdriver extension in the Safari Browser

  1. Download latest Selenium Safari extension.

2.  Install the Safari Extension

  • Double-click on the “SafariDriver.safariextz” file.
  • You will get a prompt asking “Are you sure you want to install the extension “WebDriver”?“.
  • Click on “Install”

3.  Provide the default setting for the Selenium Webdriver Extension.

  • Click on “Safari” > “Preferences” > “Extensions” > You will find Selenium extension
  • Select “Enable Webdriver”

Now all the settings are done and now we should be able to launch our Selenium scripts using Safari Webdriver.

Launching Safari Webdriver

Webdriver driver = new SafariDriver();                

driver.get( http://www.google.co.in” );

builder = new Actions(driver);

This should launch your safari browser with the Safari Webdriver Extension 🙂

Hope this article comes of use to you all.

UPDATE (18th June,2015): With the latest update of Yosemite 10.10.3 & Safari 8.0.6, the execution on Safari Browsers has become unstable & unreliable.

Selenium Scripts work best on 10.10.2 , Safari 8.0.3 & Selenium 2.45.0 combination.

So if OSX prompts you for updates, please DO NOT install them if you want to run automation on Safari Browser

Regards,

VJ

Difference between ArrayList and LinkedList in Java

ArrayList and LinkedList both implements List interface and their methods and results are almost identical. However there are few differences between them which make one better over another depending on the requirement.

ArrayList Vs LinkedList

1) Search: ArrayList search operation is pretty fast compared to the LinkedList search operation. get(int index) in ArrayList gives the performance of O(1)while LinkedList performance is O(n).

Reason: ArrayList maintains index based system for its elements as it uses array data structure implicitly which makes it faster for searching an element in the list. On the other side LinkedList implements doubly linked list which requires the traversal through all the elements for searching an element.

2) Deletion: LinkedList remove operation gives O(1) performance while ArrayList gives variable performance: O(n) in worst case (while removing first element) and O(1) in best case (While removing last element).

Conclusion: LinkedList element deletion is faster compared to ArrayList.

Reason: LinkedList’s each element maintains two pointers (addresses) which points to the both neighbor elements in the list. Hence removal only requires change in the pointer location in the two neighbor nodes (elements) of the node which is going to be removed. While In ArrayList all the elements need to be shifted to fill out the space created by removed element.

3) Inserts Performance: LinkedList add method gives O(1) performance while ArrayList gives O(n) in worst case. Reason is same as explained for remove.

4) Memory Overhead: ArrayList maintains indexes and element data while LinkedList maintains element data and two pointers for neighbor nodes hence the memory consumption is high in LinkedList comparatively.

There are few similarities between these classes which are as follows:

  1. Both ArrayList and LinkedList are implementation of List interface.
  2. They both maintain the elements insertion order which means while displaying ArrayList and LinkedList elements the result set would be having the same order in which the elements got inserted into the List.
  3. Both these classes are non-synchronized and can be made synchronized explicitly by using Collections.synchronizedList method.
  4. The iterator and listIterator returned by these classes are fail-fast (if list is structurally modified at any time after the iterator is created, in any way except through the iterator’s own remove or add methods, the iterator will throw a ConcurrentModificationException).

When to use LinkedList and when to use ArrayList?

1) As explained above the insert and remove operations give good performance (O(1)) in LinkedList compared to ArrayList(O(n)). Hence if there is a requirement of frequent addition and deletion in application then LinkedList is a best choice.

2) Search (get method) operations are fast in Arraylist (O(1)) but not in LinkedList (O(n)) so If there are less add and remove operations and more search operations requirement, ArrayList would be your best bet.

Courtesy: http://beginnersbook.com/2013/12/difference-between-arraylist-and-linkedlist-in-java/

How to format Date in Java – SimpleDateFormat Example

SimpleDateFormat in Java is used to format Date in Java. You can format date on any String format based upon various attribute available in SimpleDateFormat class e.g. mm, dd, YYetc. You can also put timezone information in formatted Date using Z attribute of DateFormat class. SimpleDateFormat is sub class of DateFormat and provide format() and parse()method to convert Date to and from String in Java. Worth noting is that SimpleDateFormat is not thread-safe and should not be shared with others. Avoid using static SimpleDateFormat inJava classes. If you want to share SimpleDateFormat or want to make it thread-safe, you can use ThreadLocal variable in Java to avoid sharing SimpleDateFormat among multiple threads.parse() method of SimpleDateFormat throws ParseException if String input is not a valid date or can not be parsed into mentioned format.

How to format Date in Java

In order to format dates using SimpleDateFormat, we first needs to define a String date format e.g. “dd-MM-yyyy”will print dates in that format e.g. 01-11-2012. You can defined format based upon identifiers supported bySimpleDateFormat class. e.g. d means day of month, y means year and M means Month of year. Javadoc ofSimpleDateFormat has complete list of supported Date and Time patterns . Once you create a DateFormat, you can just call format() method which accept java.util.Date and returns String, which is formatted Date. In this way you can alsoconvert Date to String in Java. SimpleDateFormat formats date in same pattern which is provided to it while creating instance ofSimpleDateFormat. You can also include time information e.g. hour, minutes and seconds while formatting dates by using HH, mm and SS time pattern. DateFormat class also supports inclusion of timezone in formatted date String by z and Z. If you use z you can show timezone information as abbreviation e.g. PST, IST etc. If you use Z you provide timezone, relative to GMT e.g.+0530. In next section we will see couple of SimpleDateFormat example in Java to get hands on on date formatting.

SimpleDateFormat Example in Java

Here is complete code example of How to format Date in Java using SimpleDateFormat. In this example we will see simple date formatting without time information e.g. dd-MM-yyyy, Date formatting with time information with patterns like dd-MM-yyyy:HH:mm:SS and Dates with timezone information in it e.g. dd-MM-yyyy:HH:mm:SS z or dd-MM-yyyy:HH:mm:SS Z.

import java.text.SimpleDateFormat;
import java.util.Date;

/**
*
* Java program to show how to format date in Java using SimpleDateFormat
* Examples. Java allows to include date, time and timezone information
* while formatting dates in Java.
*
* @author http://java67.blogspot.com
*/
public class DateFormatExample {

public static void main(String args[]) {

// This is how to get today’s date in Java
Date today = new Date();

//If you print Date, you will get un formatted output
System.out.println(“Today is : ” + today);

//formatting date in Java using SimpleDateFormat
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(“dd-MM-yyyy”);
String date = DATE_FORMAT.format(today);
System.out.println(“Today in dd-MM-yyyy format : ” + date);

//Another Example of formatting Date in Java using SimpleDateFormat
DATE_FORMAT = new SimpleDateFormat(“dd/MM/yy”);
date = DATE_FORMAT.format(today);
System.out.println(“Today in dd/MM/yy pattern : ” + date);

//formatting Date with time information
DATE_FORMAT = new SimpleDateFormat(“dd-MM-yy:HH:mm:SS”);
date = DATE_FORMAT.format(today);
System.out.println(“Today in dd-MM-yy:HH:mm:SS : ” + date);

//SimpleDateFormat example – Date with timezone information
DATE_FORMAT = new SimpleDateFormat(“dd-MM-yy:HH:mm:SS Z”);
date = DATE_FORMAT.format(today);
System.out.println(“Today in dd-MM-yy:HH:mm:SSZ : ” + date);

}

}

Output:
Today is : Fri Nov 02 16:11:27 IST 2012
Today in dd-MM-yyyy format : 02-11-2012
Today in dd/MM/yy pattern : 02/11/12
Today in dd-MM-yy:HH:mm:SS : 02-11-12:16:11:316
Today in dd-MM-yy:HH:mm:SSZ : 02-11-12:16:11:316 +0530

That’s all on these SimpleDateFormat Example in Java. We have seen How to format date with time and timezone information in Java. Though using SimpleDateFormat is most easy way to format Date in Java but it also has its own set of problems. It’s notthread-safe and should be used carefully. Avoid using DateFormat as static variable, don’t share SimpleDateFormat betweenmultiple threads, result is unpredictable if it’s shared among multiple threads.

Courtesy : http://java67.blogspot.in/2013/01/how-to-format-date-in-java-simpledateformat-example.html