Posts

Essential Gradle Commands

I use some of the gradle commands everyday in my project and many times I had to randomly search in the internet (as I don't remember these commands by heart). This article is for my personal reference, so that I don't have to search it in random places. These commands include running tests, generating binaries, filtering tests, changing property values during runtime, listing available tasks for a project, executing task in a subproject, printing dependencies information etc.. If you have reached this paragraph and your are still interested in reading further down, then happy reading.. :) For developers working on Windows platform, please replace './gradlew' with gradlew.bat in the following commands General gradle tasks List available projects ./gradlew projects List available properties ./gradlew properties List available tasks for root project and sub-project ./gradlew tasks :SomeProject:tasks --all Build a project Clean the buil...

JUnit's stopwatch to capture time taken per integration test in csv file

I was looking to improve my integration test suite, which contains large number of integration test (more than 900 test cases). My immediate focus was to tackle the slowest running tests in my test suite. TestNG reports provide the information of slowest running test out of the box, however my project was using JUnit 4. Being a lazy developer, I didn't want to migrate my entire test suite to TestNG in order to get reports about slowest running test. Hence I was looking at other options available in JUnit test framework. JUnit offers a Rule called stopwatch, which notifies us the time taken to complete each test as callback methods. However, most of the examples showed how to print the information on console or some logger. Printing on the console or logger is particularly not very helpful, as it doesn't allow us to analyse the data in an easy way. Hence I had created a custom stopwatch rule which extends JUnit's stopwatch rule and capture the information provided by ...

Headless Web Driver testing with Chrome on Headless Servers

Recently, I had a task to migrate the WebDriver based test cases from PhantomJs to Chrome headless and the tests were running on headless CI docker containers. The migration was not a smooth journey as I had anticipated and this article is based on my learning experience during this migration. PhantomJs was widely used for headless testing and now it has been unofficially abandoned by the PhantomJs team. So we had to switch to some other browser which is under active development and also which supports headless mode. The choice was Google Chrome (or Chromium). As more and more organizations move towards cloud containers or virtual machines to run their CI build, it is quite important to have the ability to run your WebDriver based tests in headless mode. My key learnings from this migration: Avoid using Xvfb (Virtual Frame Buffer) as virtual display when your test suite has hundreds of test cases.  Xvfb crashes in the middle of the test for unknown reason and Chrome fail...

Import Personal Information Exchange (.pfx or .p12) file on Mac

Steps to import Personal Information Exchange (.pfx or .p12) file on Mac using Keychain Access application Goto Keychain Access  application Click on System  Keychains Select File  menu -> Import Items.. Select downloaded_file.p12  file in the dialog box Enter your login password if prompted Enter the keystore password if prompted After successful import, you should see a new certificate Double click on the newly imported certificate Click the Trust  arrow to expand the trust attributes Change the value of When using this certificate:  to Always Trust Close the certificate dialog box and enter login password if prompted A blue '+' symbol should appear on the newly imported certificate, which means the certificate is imported and trusted

How to add additional dns host mapping to localhost

Why we need additional dns host mapping? In enterprise environments, some applications can serve into multiple domains. For example, same running instance(s) can be mapped for guest.example.com and customer.example.com and the functionality of the application could vary based on the domain being used by the user. Lets say, customer.example.com will need authentication, authorization and may contain premium features for customers, whereas guest.example.com will contain limited features. To test this type of application in local, which contains domain aware functionalities, we need to map additional routes in the OS host file to map these domains to localhost. And then the tests can make use of these domains to test the application running in local development machine. For Mac: Add the following lines to /private/etc/hosts file using vi or nano or any text editor application. Might need to use sudo if required. 127.0.0.1       local.example.com ...

Installing chromedriver for Selenium WebDriver testing

For Mac: Using homebrew: brew install --cask chromedriver chromedriver --version Using manual steps: Add the following lines to ~./bash_profile  or ~/.zprofile using vi or nano or any text editor # Installing Chrome Driver export CHROME_DRIVER_HOME=/downloaded_and_extracted_location/chrome_driver_2.33 export PATH=$CHROME_DRIVER_HOME:$PATH Verify the installation by executing the following command in Terminal chromedriver --version For Windows: Add c: \downloaded_and_extracted_location\chrome_driver_2.33\chromedriver to PATH environment variable (most probably through My Computer). Verify the installation by executing the following command in Command Prompt chromedriver --version For Ubuntu (Linux): sudo apt-get install chromium-browser sudo apt-get install chromium-chromedriver sudo ln -s /usr/lib/chromium-browser/chromedriver /usr/local/bin/chromedriver chromium-browser --version chromedriver --version For Debian (Linux): s...

Importing a self signed certificate to java cacert trust store

The following steps to be used only in non production environments. Self signed certificates could be used in some organisations to make server to server calls between java programs on SSL.  During these situations, we can import the certificate from the server jvm to client's jvm to fix the SSL handshake issue. On Server JVM: Generate a self signed certificate keytool -genkey -noprompt -alias test.example.com -dname "CN=localhost, OU=Team Name, O=Organisation Name, L=London, S=Greater London, C=UK" -ext "san=dns:test.example.com,dns:test.example.org" -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore /tmp/keystore.p12 -validity 36500 -storepass mypassword -keypass mypassword List the certificate keytool -list -keystore /tmp/keystore.p12 -storepass mypassword -storetype PKCS12 -v Export the certificate keytool -exportcert -keystore /tmp/keystore.p12 -storetype PKCS12 -storepass mypassword -alias localhost -file /tmp/test.example.com.crt On...