Saturday, August 13, 2022

How to install Java on EC2



*****************************************
How to install Java on EC2
*****************************************





To be continued, In this post, we will see how to install java in EC2


Step 1: Check if java is already installed java version javac -version
Step 2: Update existing packages sudo yum update

Step 3: Make a new directory and switch to directory java
“mkdir java”
“cd java”

Step 3. Now install java on the EC2 server

1. Go to Root Directory
“sudo su”

2. Check if java exist
“java -version”

3. Install java
“yum install java-1.8.0”
It will start installing  java of version 1.8, you can also use the latest tag to install the latest version of java
“yum install java-latest”

4. Check java, if java is installed successfully
“java -version”
You should be able to get the java version successfully.





 

 

 

 

 



How to install docker compose on EC2



******************************************
How to Install docker compose on EC2
******************************************



Here, we will see how to install the docker compose. 

1. Copy the appropriate docker-compose binary from GitHub:
sudo curl -L “https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose”

2.To get the latest version 
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose


3. Fix permissions after download:
“sudo chmod +x /usr/local/bin/docker-compose”

4. Verify if the docker compose successfully installed
“docker-compose version”




















To go to previous post, click on below link

How to install docker on EC2 instance



**************************************
How to install docker on EC2 instance
***************************************



To be continued,
This post will show how to install docker in the Ec2 server.

I have explained two ways here.

1. Install docker on EC2

8. Now let’s see how to install docker on an EC2 instance
    
1. Update the installed packages and package cache on your instance.
“sudo yum update -y”
    - Is this ok (y/d/N) : type ‘Y’ and enter

2. Install the most recent Docker.
“sudo yum install docker -y”

3. Check the docker status if the docker is active or inactive state
“sudo service docker status”

It shows the status as “Inactive(dead)”, That means docker service is not started yet.

4. To start the Docker service, run below command and check status again.
“sudo service docker start”
“sudo service docker status”

After running the above two commands docker service should start and in Active state(running state). To confirm check the below step

5. Let’s check the docker version and available images
“docker --version”


  To check the docker images, run below command.
  “sudo docker images”
  Obviously , there will not be any images running.

6. Add the ec2-user to the docker group so you can execute Docker commands without using sudo as prefix to any command.
“sudo usermod -a -G docker ec2-user”

Now let’s check docker images without using sudo command
“docker images”

Note - In case if you get ‘permission denied’ message because we need to restart ec2 instance so that the changes will of adding ec2-user to docker group changes will be reflected.

8. Restart EC2 instance
“sudo reboot”

9.Now login to ec2 instance again.
“ssh -i DockerisedSeleniumGrid.pem ec2-user@ec2_public_ip_address”

Now check docker images command without using sudo
“docker images”
Because docker service is not started yet, let’s start docker using below command
“sudo service docker start” and the check docke image "docker images". It should work.

10. Check any running container available
“docker ps -a”


Up till here, we have seen how to install docker on EC2. Now we need to install docker compose on EC2
Click on below to check how to do that.

After installing docker compose, We need to install the Java on EC2 in order to run the docker.
To check, click on below link


So far, We have EC2 instance ready and Docker and Java installed in it, Now we will configure selenium Hub and Node using docker-compose file
- This time we will launch EC2 using WinSCP, Download WinSCP
- Launch WinSCP
-Host name "Public ipv4 ip address" of Ec2
-User name as "ec2-user"
-Click on Advance
-
-Click on "OK" ->  Click on Login
-After completing the process user will be able to login to EC2 and see the below screen

- Create a file as I have created,
-Right click -> File -> name the file as docker-compose
-Double click on the file and paste the below content
- Login to Ec2 using command prompt as we did previously.-Envoke the docker-compose file using "docker-compose up"-You can access hu using "EC2 IP address:4445(Port)"
-And you can use the same URL in selenium RemoteDriver
-Selenium Hub will be triggered and Hub will delegate tests to respective node


2. Install docker on EC2

1) Create a AWS ec2 server 
2) $ sudo 
3) # apt-get update 
4) # curl -fsSL https:i!get.docker.com -o get-docker.sh 
5) # sh get-docker.sh 
6) # docker --version 
7) # docker run --name myc1 -d -p 8081:8080 <image name> 

To login to Ec2:

1) Go to the location where the pem file is downloaded
2) Right-click "git bash" (Git bash must be downloaded in the system)
3) You will be inside the Ec2 instance.





To go to previous post, Click here

 

Run Selenium tests on Dockerized Grid on EC2 step by step guide - Part 2

 

*******************************************
Run selenium test on Docker grid on EC2 server
*******************************************




To be continue,



- Select ‘Create new Key pair
- Type Key pair name ‘DockerisedASeleniumGrid
- Click on launch instance
- DockerisedASeleniumGrid.pem will be downloaded automatically to login to EC2 instance using SSH


- Success message
- That means EC2 instance successfully created


6. On EC2 dashboard you can see EC2 instance ID. I have provided name it as ‘Ec2_docker’



7. Now let’s login to EC2 instance using SSH
- Open command prompt
- Go to the location(download) where DockerisedSeleniumGrid.pem file is downloaded.
- Use below command
“ssh -i DockerisedSeleniumGrid.pem ec2-user@ec2_public_ip_address”

If you are able to see Amazon Linux 2 AMI, means you are successfully logged in to your server. - shown below


- Update packages using the command “sudo yum update”


We have successfully created and launch the EC2 successfully, Now our next job is to install docker on EC2. 
Check the below link



To go to previous post, click on below link
























Monday, August 1, 2022

Run Selenium tests on Dockerized Grid on EC2 step by step guide - Part 1




*******************************************
Run selenium test on Docker grid on EC2 server
*******************************************

It’s always being a challenging task to run parallel tests in selenium. To setup parallel run on a single machine we need to set up multiple VM’s which consumes so much memory and leads to problems like given below.
  • Makes test slow.
  • Leads to hanging browser sessions.
  • Sometimes browser crash.
To overcome this issue docker came into picture. Which is super easy solution of running selenium tests on a single machine using Docker.


Here Selenium Hub will be running(in docker) on our system and it will delegate tests to respective nodes. But why to maintain the selenium hub on local machine when we have AWS. So to make it more simpler. We are setting everything up on EC2 server itself. lets EC2 manage everything.

Follow the below steps:

1. Login to Amazon console using IAM user credentials

2. Type EC2 in search bar and Select EC2 option.



3. Select Instances option to check if there is any EC2 instance already running.
As you can see below, there is no instance is running.




4. So, let’s create a new EC2 instance. Click on ‘Launch instances




5. Now select Amazon Linux

- Under that Select "Amazon Linux AMI (HVM) of 64 Arch Server" which is marked as Free tier eligible.

Here, An Amazon Machine Image (AMI) is a master image for the creation of virtual servers -- known as EC2 instances -- in the Amazon Web Services (AWS) environment.


- Select Instance Type as T2.micro – free tier eligible
- Click on Launch Instance (Shown below)

Note – Select only free tier eligible otherwise other AMI type is paid which may cost you if you select other than Free tier eligible AMI.




To continue to next post, click on below link
 

Friday, July 8, 2022

Reading properties files made easy using OWNER library. No more boilerplate code


**************************************************
No more boilerplate code for properties files
**************************************************  


We use properties files all over for our development to store configurable data of our applications and the same is true when it comes to test automation. We store config params in properties files.

Properties files store data as key-value pairs similar to a Java map data structure. Below is an example of a properties file.

server.host.name=testing.com
parallel=true
maxThreads=100


We can use java boilerplate code to read properties files and use them during the program execution. There are disadvantages of this approach like,

·        Need to maintain a separate code to read/write values to properties file

·        Keys can get duplicated and hence values may differ

·        Type conversion has to be managed

Good news!

What do you think if someone else takes care of all the above hassle for you and you just need to create properties file, add values and then introduce an interface to load all the data.

The owners library takes care of all these things for you. Here is the official website of owners library.

OWNER

No more code to load, convert and manage properties files, just use your properties in the simplest possible way. See…

owner.aeonbits.org

 

Let’s look at the usage of the owners library to read properties files in our application. It comes as a Jar library and as well as a maven dependency. If you are using maven, you can import the below dependency and start using the greatest features of owners library.

<dependency>
        <groupId>org.aeonbits.owner</groupId>
        <artifactId>owner</artifactId>
        <version>1.0.8</version>
    </dependency>



In this article, let’s use the above example and develop our code leveraging owners library.

Next is to generate the interface to load the properties in the file.

import org.aeonbits.owner.Config;public interface ServerConfig extends Config {
    boolean parallel();    @Key("server.host.name")
    String hostname();    @DefaultValue("5")
    int maxThreads();
}


The condition is the variable name should be the same as the property name specified in the properties file. If it is different, as in hostname, you can specify the name using the @Key annotation.

Moreover, if you look closely at the maxThreads, you can specify the default value as a safety net.

Now the question is how do you map the two files, the properties file, and the java interface.

Rule 1
If both the files are in the same package, with the same name, then the owners will find and read the value of the properties file.

Rule 2


In most cases, we want to store the properties file in a separate directory and hence you need to specify the file path using @sources annotation as below.

My file is residing inside the resources folder under the test package.

@org.aeonbits.owner.Config.Sources({
        "file:./src/test/resources/config.properties"})
public interface ServerConfig extends Config {
    boolean parallel();    @Key("server.host.name")
    String hostname();    @DefaultValue("5")
    int maxThreads();
}



With all these, next is to use the values from the properties files inside our application.

We are initiating the ServerConfig via the ConfigFactory provided by the owners.

ServerConfig cfg = ConfigFactory.create(ServerConfig .class);
cfg.hostname;
cfg.maxThreads;

Final Thoughts


· The owners library helps to remove the boilerplate code used for reading properties files.

· Owners takes care of type conversion and load strategies

· Owners library is an annotation-based library easy to maintain.

 

Friday, July 1, 2022

Top 10 Intermediate GIT Interview Question and Answer



*******************************************************

Top 10 Intermediate GIT Interview Questions

********************************************************


1. Why is it considered to be easy to work on Git? 
With the help of git, developers have gained many advantages in terms of performing the development process faster and in a more efficient manner. Some of the main features of git which has made it easier to work are:
  • Branching Capabilities:
-Due to its sophisticated branching capabilities, developers can easily work on multiple branches for the different features of the project.
- It also has an easier merge option along with an efficient work-flow feature diagram for tracking it.

  • Distributed manner of development: 
- Git is a distributed system and due to this nature, it became easier to trace and locate data if it's lost from the main server.
- In this system, the developer gets a repository file that is present on the server. Along with this file, a copy of this is also stored in the developer’s system which is called a local repository.
- Due to this, the scalability of the project gets drastically improved.

  • Pull requests feature: 
- This feature helps in easier interaction amongst the developers of a team to coordinate merge-operations.
- It keeps a proper track of the changes done by developers to the code.

  • Effective release cycle:

- Due to the presence of a wide variety of features, git helps to increase the speed of the release cycle and helps to improve the project workflow in an efficient manner.


2. How will you create a git repository?

  • Have git installed in your system. 
  • Then in order to create a git repository, create a folder for the project and then run git init . 
  • Doing this will create a .git file in the project folder which indicates that the repository has been created.  

 

3. Tell me something about git stash?
Git stash can be used in cases where we need to switch in between branches and at the same time not wanting to lose edits in the current branch. Running the git stash command basically pushes the current working directory state and index to the stack for future use and thereby providing a clean working directory for other tasks.


4. What is the command used to delete a branch?
  • To delete a branch we can simply use the command git branch –d [head]
  • To delete a branch locally, we can simply run the command: git branch -d <local_branch_name>  
  • To delete a branch remotely, run the command: git push origin --delete <local_branch_name> 
  • Deleting a branching scenario occurs for multiple reasons. One such reason is to get rid of the feature branches once it has been merged into the development branch.


5. What differentiates between the commands git remote and git clone?
git remote command creates an entry in   git config that specifies a name for a particular URL. Whereas git clone creates a new git repository by copying an existing one located at the URL. 



6. What does git stash apply command do?
  • git stash apply command is used for bringing the works back to the working directory from the stack where the changes were stashed using git stash command. 
  • This helps the developers to resume their work where they had last left their work before switching to other branch.


7. Differentiate between git pull and git fetch.
git pull -  This command pulls new changes from the currently working branch located in the remote central repository.
 git fetch -  This command is also used for a similar purpose but it follows a two step process: 
    1. Pulls all commits and changes from desired branch and stores them in a new branch of the local repository. current 
    2. For changes to be reflected in the current / target branch, git fetch should be followed by git merge command.

git pull = git fetch + git merge




8.  Can you give differences between “pull request” and “branch”?
pull request - This process is done when there is a need to put a developer’s change into another person’s code branch. 
branch - A branch is nothing but a separate version of the code. 



9. Why do we not call git “pull request” as “push request”?
“Push request” is termed so because it is done when the target repository requests us to push our changes to it. 
“Pull request” is named as such due to the fact that the repo requests the target repository to grab (or pull) the changes from it.




10. Can you tell the difference between Git and GitHub?
Git 
     - This is a distributed version control system installed on local machines which allow developers to
         keep track of commit histories and supports collaborative work.
    - This is maintained by “The Linux Foundation”.
    - SVN, Mercurial, etc are the competitors
GitHub 
    - This is a cloud based source code repository developed by using git. 
    - This was acquired by “Microsoft".
    - GitLab, Atlassian BitBucket, etc are the competitors.
    - GitHub provides a variety of services like forking, user management, etc along with providing a central repository for collaborative work.































Top Git Interview Question and Answers for Automation Tester

 ****************************************************

Top 10 Basic GIT Interview Questions

*****************************************************




1. What is Git and why is it used?
Git is the most popular, open-source, widely used, and an example of distributed version control system (DVCS) used for handling the development of small and large projects in a more efficient and neat manner.
It is most suitable when there are multiple people working on projects as a team and is used for tracking the project changes and efficiently supports the collaboration of the development process.
With the help of the versioning system, the developer can identify who has made what changes and then run tests and fix bugs if any and then do necessary feature implementation. In case of any unforeseen circumstances, the code can be reverted to any of the previously working versions thereby saving huge efforts.


Scope of Git:
  •     Due to a well-established version control system and the support for collaborative work, git has garnered wide popularity not just amongst the software developers, but also among the people who do other tasks like documentation or any other collaborative work. It can seem challenging at first, but once we get the hang of git, we find that it makes our lives much simpler.
  • it has an amazing branching system that supports nonlinear development along with keeping the developers accountable for their code. This helps in making the development process efficient and faster.

2. What is a version control system (VCS)?
A VCS keeps track of the contributions of the developers working as a team on the projects. They maintain the history of code changes done and with project evolution, it gives an upper hand to the developers to introduce new code, fixes bugs, and run tests with confidence that their previously working copy could be restored at any moment in case things go wrong.


3. What is a git repository?
A repository is a file structure where git stores all the project-based files. Git can either stores the files on the local or the remote repository.


4. What does git clone do?
The command creates a copy (or clone) of an existing git repository. Generally, it is used to get a copy of the remote repository to the local repository.


5. What does the command git config do?
The git config command is a convenient way to set configuration options for defining the behavior of the repository, user information and preferences, git installation-based configurations, and many such things.
For example:
To set up your name and email address before using git commands, we can run the below commands:

  • git config --global 
          user.name “<<your_name>>” 
  • git config --global user.email “<<your_email>>”


6. Can you explain head in terms of git and also tell the number of heads that can be present in a repository?
A head is nothing but a reference to the last commit object of a branch.
For every repository, there will always be a default head referred to as “master” or now “main” (as per GitHub) but there is no restriction to the count of heads available. In other words, it can have any number of heads.
Usages:
- To go or checkout to 1 commit before the latest commit, we use git checkout HEAD~1
- To uncommit the last 3 commits without losing the changes, we first run git reset HEAD~3 . Then we can see the changes made in the last 3 commits and then update it manually and commit it finally.
- In order to uncommit the last 3 commits and also remove the changes, we can un the command: 
git reset --hard HEAD~3 . This command will completely remove all the changes.
- To look into the changes made in the last 3 commits, we can run git diff HEAD~3
- To make a new commit by reverting the last 3 commits, we can run the command: 
git revert --no-commit HEAD~3...HEAD


7. What is a conflict?
- Git usually handles feature merges automatically but sometimes while working in a team environment, there might be cases of conflicts such as: 
1. When two separate branches have changes to the same line in a file 
2. A file is deleted in one branch but has been modified in the other. These conflicts have to be solved manually a
- These conflicts have to be solved manually after discussion with the team as git will not be able to predict what and whose changes have to be given precedence 



8. What is the functionality of git ls-tree? 
This command returns a tree object representation of the current repository along with the mode and the name of each item and the SHA-1 value of the blob.


9. What does git status command do? 
git status command is used for showing the difference between the working directory and the index which is helpful for understanding git in-depth and also keep track of the tracked and non-tracked changes.


10. Define “Index”.
Before making commits to the changes done, the developer is given provision to format and review the files and make innovations to them. All these are done in the common area which is known as ‘Index’ or ‘Staging Area’.

In the above image, the “staged” status indicates the staging area and provides an opportunity for the people to evaluate changes before committing them. 


10. What does git add command do? 
  • This command adds files and changes to the index of the existing directory. 
  • You can add all changes at once using git add . command. 
  • You can add files one by one specifically using git add  <file name> command. 
  • You can add contents of a particular folder by using git add /<folder name>/ command.











How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post