Where we learn technology

Category: Uncategorised (Page 3 of 7)

Java Program to Add Two Integers

This is very simple, just define two integer variables and use + operator to add them.

package JavaQuestions;

/**
 * 
 * @author NaveenKhunteta
 *
 */
public class AddNumbers {

	public static void main(String[] args) {

		int a = 10;
		int b = 20;

		int sum = a + b;

		System.out.println("sum of a and b is: " + sum);

	}

}

Output:

sum of a and b is: 30

Setup Jenkins with Docker on Mac

Setup Jenkins with Docker on Mac

Environment

OS: macOS High Sierra 10.13

Download Docker for Mac

Create Docker ID

You need to go to https://www.docker.com/ to create you own docker id.

Download Jenkins CI with blue ocean plugin.

Follow the installation instructions to install the jenkinsci/blueocean Docker container. And do remember to launch the Docker.app after installation as launching the application is a necessary step to get the Docker daemon run.

Start the Jenkins CI container

$ docker run -u root --rm -d -p 8080:8080 -p 50000:50000 -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

Command options

--rm 
is to remove the docker container after it is shut down.

-d 
is to let jenkinsci container run in background and silent the output rather than print out in terminal console. Recommend not to add this option, because usually you want to check the output from terminal console, e.g. the initial password. 

-p 8080:8080 
is the to map the port number for host machine and docker container respectively.

-p 50000:50000 
is for the JNLP based Jenkins master-slave configurations. JNLP-based Jenkins agents communicate with the Jenkins master through TCP port 50000 by default.

-v jenkins-data:/var/jenkins_home 
is to map the /var/jenkins_home directory in the container to the Docker volume with the name jenkins-data, this option is to ask Jenkins to persist state for instance restarts. -v /var/run/docker.sock:/var/run/docker.sock, this option is to allow jenkins ci container to communicate with docker daemon.  jenkinsci/blueocean is the jenkinsci image with blueocean plugin, specifying this option will automatically pull any updates.  

Possibile errors

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

See 'docker run --help'.
This error is because the Docker daemon is not started yet. On MacOS, you need to manually start the Docker.app in order to let the docker daemon start.

Open the Jenkins landing page

Browse http://localhost:8080/ , you will see below page.
Screen Shot 2018-04-15 at 11.24.19
Find the password from console output and paste it above input box to continue.
If you suddenly lost your initial password from the console output. You can use below command to get it back. Also, actually this password is your default password for your Jenkins admin account.
$ docker exec cat /var/jenkins_home/secrets/initialAdminPassword

Initial customisation

You can ask the Jenkins to install the suggested plugins for you or choose the ones you need only. You can also install the plugins from “Manage Plugins” after you complete the Jenkins setup.
Screen Shot 2018-04-15 at 12.04.34

Create your first jenkins account

You can create your own jenkins account during the setup phase. Or you can also ignore this step but use the “admin” account with its default password, the one output in console, for login.
Screen Shot 2018-04-15 at 12.06.22

Proxy Setup

If your Jenkins server is behind a proxy, then you need to configure this proxy properly in order to install your Jenkins plugins. Navigate yourself to “Manage Jenkins” -> “Manager Plugins” -> “Advanced“.
Screen Shot 2018-04-17 at 09.24.46

Some useful commands

Check container IDs
docker ps -a
Check logs for a particular container
docker logs <container-id>

Cheers!!

Naveen AutomationLabs 

Payment Details

Naveen AutomationLabs Online Courses:

 
Payment Options:
Here I’m sharing the bank account details. Please send me the screenshot of the receipt once you make the payment without fail. 
 
Please send the details at : naveenanimation20@gmail.com
Subject Line: Online Course Payment Receipt – Your Full Name

Please find below bank details: You can make the transaction directly to the given account or make it via Western Union Or Xoom.
 
Please find the bank details:
 
Full Name: NAVEEN KHUNTETA
 
Contact No.: 9902233400
 
Payee name: NAVEEN KHUNTETA
 
Name of the Bank: ICICI bank
 
Address of the Bank: Bhandarkar Road, Pune
 
 Bank Account Number: 624001553272
 
 IFSC Code(11 Digit Code): ICIC0006240  
 
PayPal Payment: 
Check out with PayPal

For Candidates in India:

  • You can also make the payment via Tez (Google Pay) OR PhonePe:
  • UPI to this number: +91-9902233400
  • UPI: naveenanimation20@okicici
  • OR Google Pay IDnaveenanimation20@gmail.com

 

For Candidates in India:

Please scan this QR code to make the payment via PhonePe, GPay / PayTM/ Amazon Pay/ UPI.

Push Code to Git Repositories using Command Prompt

Steps to Push Code to Git Repositories using Command Prompt

Pre-requisites:      

1. Download Git from below Link:

https://git-scm.com/download/win/ [Git must be installed in Local System].

2. Once Git is installed >> SSH Key should be Added in Git.

Login to Github >> Go to Settings >> User should be able to see SSH and GPG Keys on Left Side Panel as per below Screenshot.                  

Click on SSH and GPG Keys >> User should be able to see as shown below in same page.

Now Click on New SSH Key and Add SSH Key.

Below are the Steps to Generate SSH Key using Git bash:          

Step1: Launch git bash.

Step2: Type ssh-keygen -t rsa -> Enter -> Enter -> Enter -> Key will be generated.

 

Admin@Admin-PC MINGW64 ~
$ ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Admin/.ssh/id_rsa):
/c/Users/Admin/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Admin/.ssh/id_rsa.
Your public key has been saved in /c/Users/Admin/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RWDx9MsZekrqrGMqKoL7tWVvjq51BSlUnzknk78RAzU Admin@Admin-PC

Now Go to Path as shown above which is highlighted.              

[Path will be changed from System to System].

Open the File which is of Publisher type and user should be able to see SSH Key which needs to be added in Git. 

[Make sure key is starting with ssh-rsa].

Once SSH key is added, you are good to add your code to created repository in Git.

Note: We can add as many as ssh keys, if we need to give permission for someone who can contribute to our repositories.

Below are the commands to Push Code from Command Prompt:

Step 1:  Open Command Prompt.

Step 2:  Go to Folder/Workspace where your project/files stored.

In my case my project is stored in D: Drive and User should be in Project Folder.

 

Step 3: git init >> Command to initialise project with repository.

Step 4: git status >> To check status.

Since my project is already associated with created repository, it is showing as Reinitialized existing Git Repository.  If it is not initialized, still you can proceed and you can initialize later on.

Then I am checking status of files >> All files are highlighted in Red color because they are not ready to be committed.

Step 5: git add . Or git add Filename >> Commands to add all files or To add particular File.

Step 6: git status >> To check status. 

Now all files are highlighted in Green color because all files are ready to be Committed.

Step 7: git commit –m “Comment Message”

Step 8: git status

Now my code is ready to be pushed to Repository.

If Project is not initialised with GIT Repository  – Follow below command to initialise project with GIT Repository before pushing code to Repository. [It is a One Time Activity].

If Project is already initialzed you can ignore Step-9.

Step 9: git remote add  origin “Path of Git Repository”

Now Project will be initialised with GIT Repository and we are good to push our code.

 

Step 10: git push origin master [Master >> Branch Name].

If it asks for credentials >> Enter Valid Username and Password.

Code is Pushed to initialised GIT Repository.

 

Other git commands:

git clone “repository path“ – To download or clone complete repository from git.

 

git pull origin master – Once repository is cloned from git to local and we udpate any code for same repository in git. To get same code to be udpated in Local and in Eclipse we can use this command.

 

 

This blog is written by Pavan. He is an expert in Selenium Automation and currently working in Infosys as Automation QA Engineer.

 

Cheers!

Naveen AutomationLabs

How to check Palindrome Number

How to check Palindrome Number


Learn:
1. check the given number is Palindrome or not.
2. write different test cases



Code:


package Questions;
public class PalindromeNumber {
//151 454 34543 161 78987  
//teet
public static void isPalindromeNumber(int num){
System.out.println(“Given Number is :” + num);
int r=0;
int sum=0;
int t;
t=num;
while(num>0){
r = num%10; //get the remainder
sum = (sum*10)+r;
num=num/10;
}
if(t==sum){
System.out.println(“palindrome number”);
}else{
System.out.println(“not palindrome number”);
}
}
public static void main(String[] args) {
isPalindromeNumber(151);
isPalindromeNumber(152);
isPalindromeNumber(78987);
isPalindromeNumber(1110);
isPalindromeNumber(0);
}
}

How to find Prime Number

How to find Prime Number in Java

Learn:
1. check the given number is prime or not.
2. print all the prime numbers upto a given a number
3. write different test cases

Code:

package Questions;
public class PrimeNumber {
//2 is the lowest prime number
//3
//num = 20
public static boolean isPrimeNumber(int num){
//edge/corner cases:
if(num<=1){
return false;
}
for(int i=2; i<num; i++){
if(num % i == 0){
return false;
}
}
return true;
}
public static void getPrimeNumbers(int num){
for(int i=2; i<=num; i++){
if(isPrimeNumber(i))
System.out.print(i + ” “);
}
}
public static void main(String[] args) {
System.out.println(“2 is prime number: “+ isPrimeNumber(2));
System.out.println(“3 is prime number: “+ isPrimeNumber(2));
System.out.println(“10 is prime number: “+ isPrimeNumber(10));
System.out.println(“17 is prime number: “+ isPrimeNumber(17));
System.out.println(“0 is prime number: “+ isPrimeNumber(0));
System.out.println(“1 is prime number: “+ isPrimeNumber(0));
System.out.println(“-3 is prime number: “+ isPrimeNumber(-3));
getPrimeNumbers(7);
getPrimeNumbers(13);
getPrimeNumbers(20);
}
}

How to record Selenium Test Execution Video

In this video, we will learn about recording of your test cases execution using Monte Screen Recorder API.

-How to record Selenium Test Execution Video.

This utility can be used to create AVI/Mp4 recording files for your test case execution, which can be shared to developers while logging the bugs.

Here is the GIT Repo:
https://github.com/naveenanimation20/ScreenRecorder

Here is the Monte Maven Dependency:
https://mvnrepository.com/artifact/com.github.stephenc.monte/monte-screen-recorder/0.7.7.0

~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
https://www.youtube.com/c/Naveen%20AutomationLabs?sub_confirmation=1

Follow me on my Facebook Page:
https://www.facebook.com/groups/naveenqtpexpert/

Let’s join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
https://t.me/joinchat/COJqZUPB02rRd8wQsIQ9Cw

WebServices API Automation Tutorials:
https://vimeo.com/ondemand/webservicesapiautomation

Full Playlists from Naveen AutomationLabs

Full Playlists from Naveen AutomationLabs:



1. Core Java:

Core Java Tutorials Series : https://www.youtube.com/watch?v=Wm0KeM90bUo&list=PLFGoYjJG_fqqyIj2ht0aHMx_HnGX3ZFEx

Core Java Interview Questions & Answers: https://www.youtube.com/watch?v=exzJoArl0h0&list=PLFGoYjJG_fqr84PKCp88iPkQDWJSfzaqz

Java Collections Series: https://www.youtube.com/watch?v=mQ9uxTWZCXA&list=PLFGoYjJG_fqooGAq7UKpkXb8l4xjyEQUr


2. Selenium:
Selenium WebDriver – Basics to Advanced Series: https://www.youtube.com/watch?v=j2dkdqfzY9Y&list=PLFGoYjJG_fqo4oVsa6l_V-_7-tzBnlulT

Selenium Interview Questions & Answers: https://www.youtube.com/watch?v=JjelA7ZUf9I&list=PLFGoYjJG_fqp1zvxelcB2WGHzUyVxDSQK

Become a Genius in XPATH: https://www.youtube.com/watch?v=3uktjWgKrtI&list=PLFGoYjJG_fqoY3PNcMLjp4pJZSXUCHeiB


3. Framework:
Data Driven Framework Series: https://www.youtube.com/watch?v=sSNqjNzaP6s&list=PLFGoYjJG_fqqlW6swKwutBOVU2O8k_JHT

Full Page Object Model in Selenium: https://www.youtube.com/watch?v=P9ZWOWm7i0k&list=PLFGoYjJG_fqq6cHeqfsDes3pdVh3kpl74

Cucumber (BDD) Framework with Java- Full Series: https://www.youtube.com/watch?v=vHzMJuc9Zuk&list=PLFGoYjJG_fqoBFPevCDZDCufDX5h-o3yO

TestNG (TDD) Framework Series: https://www.youtube.com/watch?v=0Gew2XOuum8&list=PLFGoYjJG_fqp25buwscrsKA5q8qsLsuUy

Protractor (JavaScript) with Jasmine Series: https://www.youtube.com/watch?v=z-DBzW2xlB0&list=PLFGoYjJG_fqq-MIAaOhu4GtfJ7TRUN7Cu


4. Rest API & WebServices:
Rest API & WebServices Tutorials Series: https://www.youtube.com/watch?v=LUbBkiIhrE4&list=PLFGoYjJG_fqp891lruz5fCRPWsDtEXJky

API & WebServices Interview Questions & Answers Series: https://www.youtube.com/watch?v=OWCu7Pp8LEQ&list=PLFGoYjJG_fqoezy5mOlQdRIjMPc-TLTiv


5. GIT & Maven:
GIT HUB Tutorials: https://www.youtube.com/watch?v=ywzEFZL75YM&list=PLFGoYjJG_fqptiT0rprATVt3BWU_bKW0P

Learn Maven: https://www.youtube.com/watch?v=tyLSFciTU-s&list=PLFGoYjJG_fqrY1RKpMmoVxMzL57WNc8cf


6. Python:
Python Tutorials: https://www.youtube.com/watch?v=oiHuaVQxUv8&list=PLFGoYjJG_fqr7PBCFKD9_bXN9mRusY_oC
« Older posts Newer posts »