Posts

Property Reader In Java

Sample Property Reader in Java public class PropertyReader { private static Properties properties = new Properties(); static { try { ClassLoader classLoader = Thread. currentThread ().getContextClassLoader(); InputStream inputStream = classLoader.getResourceAsStream( "filename.properties" ); properties = new Properties(); properties .load(inputStream); inputStream.close(); } catch (Exception ex) { ex.printStackTrace(); } } public static boolean containsKey(String key) { if ( properties .containsKey(key)) { return true ; } return false ; } public static String getPropertyValue(String key) { if ( properties .containsKey(key)) { return (String) properties .get(key); } return null ; } public static void setPropertyValue(String key, String value) { ...

Jenkins Declarative Pipeline

Image
Sample Jenkins Declarative Pipeline def A = false def B = true pipeline { agent any tools { maven 'MVN' jdk 'JDK' } stages { stage('Build Stage') { steps { git "https://github.com/nishantautomationlabs/nal-junitmockito.git" sh "mvn -U clean compile install -DskipTests" echo 'Build Stage executed' } } stage('Unit Test Stage') { steps { sh "mvn -Dtest=MockitoExampleTest test" echo 'Unit Test Stage executed' } } stage('Master Stage'){ when{ branch 'master' } steps { echo 'run this stage only if its running on the master branch' } } stage('Conditional Stage') { when { ...

Jenkins Scripted Pipeline

Image
Sample Jenkins Scripted Pipeline node { stage "Git Pull" git "https://github.com/nishantautomationlabs/nal-junitmockito.git" echo "code pulled" stage "Run Declarative Pipeline" build "Declarative Pipeline" echo "Declarative Pipeline triggered" stage "print" for(int i = 0; i < 10; i++) { if(i % 2 == 0) { echo "Number " + i } } } Jenkins Configuration: Build History:

Hot to fix apt-get “The following signatures were invalid: KEYEXPIRED”

Image
Hot to fix apt-get “The following signatures were invalid:  KEYEXPIRED ” If you are trying to run  apt-get update on your ubuntu machine and seeing the error "The following signatures were invalid: KEYEXPIRED" you have come to the right place. The key expired error occurs when one or more existing key on your ubuntu machine has expired which is hindering the update. To fix this issue, you need to renew these keys. Here are the steps to renew an expired key Find the expired Key:  Run the below command which will list all the expired keys on your ubuntu machine. Make a note of all the keys.  sudo apt-key list | grep -A 1 expired Renew the expired Key:  Take the keys from the previous command output and replace the <KEY_ID> in te below command with that. Execute this command to renew the expired key. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys <KEY_ID> Run apt-get update:  Now that you have renewed all the...

Install Docker on Ubuntu 16.04

Install Docker on Ubuntu 16.04 Docker Engine is an open-source containerization technology for building and containerizing your applications. Docker Engine acts as a client-server application with: A server with a long-running daemon process dockerd . APIs which specify interfaces that programs can use to talk to and instruct the Docker daemon. A command-line interface (CLI) client docker. To install Docker on your Ubuntu 16.04 machine, follow the following steps. Install Dependent packages:   Update the package index and install packages to allow apt to use a repository over HTTPS. sudo apt-get update   sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common Add repository key:    Add repository key to the package manager curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - Verify fingerprint:    Verify that you now have the key with the fingerprint sudo apt-...

Selenium Grid using Zalenium

Image
Selenium Grid using Zalenium Zalenium is a flexible and scalable container based Selenium Grid with video recording, live preview, basic auth & dashboard. To setup Zalenium, follow the following steps. Prerequisite:  Docker is pre-installed. Pull Docker Images:  Pull the elgalu selenium and zalenium docker images. docker pull elgalu/selenium   docker pull dosel/zalenium Run Zalenium:  Start zalenium using the command docker run --rm -ti --name zalenium -p 4444:4444  -v /var/run/docker.sock:/var/run/docker.sock  -v /tmp/videos:/home/nishant/videos --privileged dosel/zalenium start Stop Zalenium:  To stop zalenium run the command docker stop zalenium Access Selenium Hub:  Access the selenium hub   at   http://localhost:4444/grid/console   Access Selenium Grid Live View:  Access the selenium grid live view at   http://localhost:4444/grid/admin/live   Access Zalenium Dashbo...

Setup WordPress with MySQL using Docker Compose

Setup WordPress with MySQL using  Docker Compose Prerequisite:  Docker and docker-compose are installed. Create YAML File:  To create a docker-compose YAML file for Wordpress, create a new YAML file with the below content. wordpress-mysql .yaml version: '3.3' services:    db:      image: mysql:5.7      volumes:        - db_data:/var/lib/mysql      restart: always      environment:        MYSQL_ROOT_PASSWORD: test123!        MYSQL_DATABASE: nishantmysql        MYSQL_USER: nishant        MYSQL_PASSWORD: test123!    wordpress:      depends_on:        - db      image: wordpress:latest      ports:        - "8000:80"      restart: always      environment...

Setup Selenium Grid using Docker Compose

Setup Selenium Grid using  Docker Compose Prerequisite:  Docker and docker-compose are installed. Create YAML File:  To create a docker-compose YAML file for Selenium Hub, create a new YAML file with the below content. seleniumgrid .yaml version: "3" services:   selenium-hub:     image: selenium/hub:3.141.59-20200409     container_name: selenium-hub     ports:       - "4445:4444"   node1:     image: selenium/node-chrome-debug:3.141.59-20200409     volumes:       - /dev/shm:/dev/shm     depends_on:       - selenium-hub     environment:       - HUB_HOST=selenium-hub       - NODE_MAX_SESSION=10        - NODE_MAX_INSTANCES=10       - HUB_PORT=4444   node2:     image: selenium/node-chrome-debug:3.141.59-20200409     volumes: ...

Setup Selenium Grid using Kubernetes

Setup Selenium Grid using  Kubernetes Prerequisite:  Kubernetes is installed along with minikube if you are running in your local. Create Deployment:  To create a Kubernetes deployment for Selenium Hub, create a new YAML file with the below content. seleniumdeployment.yaml apiVersion: apps/v1 kind: Deployment metadata:   name: selenium-hub spec:   selector:     matchLabels:       app: selenium-hub   strategy:      type: RollingUpdate     rollingUpdate:       maxSurge: 1       maxUnavailable: 0         template:     metadata:       labels:         app: selenium-hub     spec:       containers:       - name: selenium-hub         image: selenium/hub:3.141.59-20200326         resources:     ...

Install and Setup MySQL on Ubuntu

Install and Setup MySQL on Ubuntu MySQL is an open-source relation database management system which is fairly easy to use and is the first choice for many to handle basic database requirement for their applications. To setup MySQL on your ubuntu system follow the steps below. Install MySQL: To install MySQL update the ubuntu package index and install the package using Ubuntu package manager: sudo apt-get update   sudo apt-get install mysql-server Setup Security: You will be promoted to setup root password during installation, set up a password you can remember as you are going to need it later. If you were not asked to set up your root password  or if you wish to change any of the security settings such as disallowing remote login , you can do so by running the command sudo mysql_secure_installation utility Open Port: If you wish to connect to the MySQL database from another machine or from an application hosted on a different server, you need to open a port...

Get rid of "Timed out receiving message from renderer"

Get rid of "Timed out receiving message from renderer" Message Well, if you using selenium web driver to automate your web flows you must be really annoyed by now with the console log [SEVERE]: Timed out receiving message from renderer: 0.100 This not only gives us a false impression of some error happening during the run but also makes it difficult to go over the console logs. Luckily, we can make use of the silent output mode in chrome to get rid of these messages. To do so we need to set the silentOutput parameter to true in System property as follows. System.setProperty("webdriver.chrome.silentOutput", "true"); and voila...no more annoying timeout message.   If you don't want to use setting the system property way for any reason, there is another way for you to achieve this. You can make use of ChromeDriverService builder to build it with " withSilent " set to true in the code as below.   ChromeDriverService.Builder bu...

Intellij JAR Remote Debugging

Image
Intellij JAR Remote Debugging Prerequisite: The code used to generate the JAR deployed on the remote location and the code on the local machine should be the same. Click on Edit Configurations option in Intellij and create a new Remote configuration Enter the Host IP  in the Host field and the below command in the command line arguments for remote JVM field -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 Save the remote configuration  Put the necessary breakpoints in place Run the JAR on the remote server using the command java -jar -Xmx2g -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 your-jar.jar argumen1 argument2  You will see that your program is not executing but instead listening to the port you mentioned in the command  Now select the remote configuration we created earlier in Intellij and click on Debug button, your code will now start executing and you will be able to debug the code.

How to create your first Jenkins Job

Image
Creating your first Jenkins Job Prerequisite:  Jenkins is installed and configured, if you need any help doing so, refer the steps  here  and here . Navigate to your Jenkins dashboard by browsing  http://localhost:8080   Since we are going to create a Maven job, lets first install the maven integration plugin and a couple of other plugins which will help us with reports. Click on "Manage Jenkins" from the left pane and then click on "Manage Plugins" Click on "Available" tab and search for maven in the Filter text box. Select "Maven Integration" from the list of suggestions. Next, you can also select "TestNG Results" and "HTML publisher" plugin which we will use for publishing reports. Optional: You can also select "Green Balls" plugins if you don't like the blue color balls of maven and want to show it in Green color on build success. Once you are done selecting the plug...