Friday, May 15, 2020

Maven Interview questions with Answers


Maven Interview questions with Answers

What is Maven?

-Apache Maven is a Software Project Management tool.
-It is also known as Build Management tool.
-Maven is used to manage dependencies, maintain right version of jar files.
-It is used to set up everything which is required to run our selenium code independently.
-Maven provides pom.xml file which is the core of maven project.
- pom.xml is the configuration file where all the required information is kept.

-Maven downloads dependencies/ jars from central repository- "mvnrepository" .
-Maven has its own repository where it keeps all plug-ins and jar files, etc.
-Maven's own repository is known as .m2 repository.
-Downloaded jar files are kept or stored in local repository called .m2 repository.
-When maven project is created it provides organized project structure.
-We can create maven project for writing selenium script and create dependencies using pom.xml file. (Project Object Model)
-Once dependencies are set, maven will download all dependent jar files automatically and in future if any update comes from selenium, testNG, apache poi, or any side, it will simply update all the required changes with right version.


Who owns Maven tool?

-Apache Software Foundation.


Why Maven is used in Selenium project?

-Maven is used to manage dependencies, maintain right version of jar files.
-It is used to set up everything which is required to run our selenium code independently.
-When maven project is created it provides organized project structure.
- Example: To avoid version compatibility issues in future. New software tools with old jar files, and vice-versa.


How will you download the Maven? Explain all downloading steps?

Download:
-Go to Google.com and search for "Maven download".
-Click on below link- https://maven.apache.org/download.cgi
-Once you are above webpage search for "Files" options.
-Click on Binary zip archive "apache-maven-3.6.3-bin.zip" .
-It will start downloading.
-Extract it in your folder.

What are the benefit of using Maven?

-It will download right version of the jar files.
-We tester need not to take care of downloading jar files and maintain it.
-When Maven project is created, it provides organized project structure.


What is the procedure to install maven in your machine?

Install:
-Right Click on MyComputer > Properties > Advanced system settings > Environment Variables >
-Under "System Variables"
-Set below as -

MAVEN_HOME : E:\[Testing]\[Software Data]\apache-maven-3.6.3-bin\apache-maven-3.6.3

Path : path of jdk bin folder; path of maven bin folder
C:\Program Files\Java\jdk1.8.0_131\bin;E:\[Testing]\[Software Data]\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin

JAVA_HOME : C:\Program Files\Java\jdk1.8.0_131

-Click OK > OK > OK.


How will you check Maven version installed, also if it is successfully installed or not?

-Go to command prompt and check version.
cmd prompt> mvn -version
-It will show which version is installed along with java version.
-If it does not show, it means maven is not installed properly in your machine.



Why Maven is called Build Automation tool?

-Maven also manage plug-ins, configuration under <build> tag.
-It also generate build of maven project, nothing but jar file.
-It generates source code, compiling code, packaging code to a jar etc.
-Maven provides a common platform to perform these activities which makes programmer’s life easier.

Explain all steps to create a maven project in eclipse?

How will you create a maven project in selenium?

-Open Eclipse
-Go to File > New  > Other > Maven Folder > click on "Maven Project" > Next.
"New Maven Project" window comes > Tick to "Create a simple project"
-Tick to "Use default workspace location" and location text box should be empty.
-Clck on Next.

-It will ask below details-
GroupID : Enter GroupID as any name. Exmple: GIDSample
This GroupID is just a folder which will be created under  .m2 > repository > GroupID folder > Artifact Folder(Project Folder)
ArtifactD : Enter Artifact ID as any name. Example: AIDSampleMavenProject
Version : 0.0.1-SNAPSHOT
Packaging : jar
Name : Any Name which describe about project.
Description: Description about project.
Finally click on "Finish".

As soon as you click on Finish button, immediately bottom right corner you will see progress of project creation.
Once 100% done, you can check in project explorer that maven project has been created successfully.

Maven Project Structure:

ProjectName
-src\main\java
-src\main\resources
-src\test\java
-src\test\resources
-JRE System Library
-Maven Dependencies
-src
-target
-pom.xml


Explain GroupID, ArtifactID, Version, Packaging, Name, Description while creating a maven project?

GroupID : Enter GroupID as any name. Exmple: GIDSample
This GroupID is just a folder which will be created under .m2 as below-
.m2 > repository > GroupID folder > Artifact Folder(Project Folder)
ArtifactD : Enter Artifact ID as any name. Example: AIDSampleMavenProject
Version : 0.0.1-SNAPSHOT
Packaging : jar
Name : Any Name which describe about project. This is optional.
Description: Description about project. This is optional.


Where will you manage pom.xml to update dependencies, plugins?

-Under Maven Project you will see POM.xml file.
-Open it by double click.
-It is having below tabs to manage POM Files and many more.
-Overview
-Dependencies
-Dependency Hierarchy
-Effective POM
-pom.xml


What is pom.xml file?

-It is a Project Object Model file.
-The pom. xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.
- Maven reads the pom file.
-It is created automatically when you create a maven project.
-It is a file where we have to add dependencies and plug-ins and manage the same.
-It is a core file or configuration file of maven project to manage maven project.
-Once dependencies are set, maven will download all dependent jar files automatically and in future if any update comes from selenium, testNG, Apache poi side, it will simply update all the required changes.


Tell me what folders will be created once you have created a maven project successfully? 

List all project structure.

ProjectName
-src\main\java
-src\main\resources
-src\test\java
-src\test\resources
-JRE System Library
-Maven Dependencies
-src
-target
-pom.xml

Also

.m2 > repository > GroupID folder > Artifact Folder(Project Folder)


What is use of pom.xml file? 


-It is a Project Object Model file.
-The pom. xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.
- Maven reads the pom file.
-It is created automatically when you create a maven project.
-It is a file where we have to add dependencies and plug-ins and manage the same.
-It is a core file or configuration file of maven project to manage maven project.
-Once dependencies are set, maven will download all dependent jar files automatically and in future if any update comes from selenium, testNG, Apache poi side, it will simply update all the required changes.


What Tabs you can see related with pom.xml to manage dependencies?

It is having below tabs to manage POM Files and many more.
-Overview
-Dependencies
-Dependency Hierarchy
-Effective POM
-pom.xml



How will you download dependencies and plugins,and from where will you download them?

-Visit to mvnrepository site.
-Search for dependencies for tools and plug-ins.
-Copy dependencies and paste as it is in pom.xml.
-dependency will be put under <dependencies> tag.
-plug-ins will be put under <build> <plugins> tag.



Generally what dependencies are updated inside pom.xml file?

-selenium dependencies
-testNG dependencies
-apache poi dependencies
-junit dependencies
-dependency for any tool which you want to integrate with maven.



After adding dependencies in pom.xml file and saving file,what will happen exactly?
Which folder will be created?

ProjectName
-src\main\java
-src\main\resources
-src\test\java
-src\test\resources
-JRE System Library
-Maven Dependencies
-src
-target
-pom.xml
Also
.m2 > repository > GroupID folder > Artifact Folder(Project Folder).


What is the main/root tag of pom.xml file?

- <project> tag.
-Inside <project> tag we have <dependencies> and <build> tags, and many more.


What two section we can see inside pom.xml file?

Dependencies part: where dependencies for all required tools will be maintained.
Plug-ins part: where plugins will be maintained.

If you download or copy dependency, in which tag is it enclosed?

- <dependency>
- And all <dependency> tags will be present inside <dependencies> tag.

Exactly where will you update dependencies in pom.xml file?

- Inside <project> tag, within <dependencies> tag.

What plugins we use in pom.xml?

- Maven compiler plug-in.
- Maven surefire plug-in.


Explain compiler plugin? what is it for?

-Maven compiler plug-in is for compiling the project source code.


Explain surefire plugin? what is it for?

-Maven surefire plugin is used to run the project tests.
-It also allows us to configure which XML suites to execute when we build our project.


How many repositoy Maven is having? What are they?

- Central repository: mvnrepository, from where we download dependencies and plug-ins.
- Own repository: .m2, where all jars, dependencies, plug-ins, other files are stored.


Explain mvnrepository website? why we visit there?

- Central repository: mvnrepository, from where we download dependencies and plug-ins.
-Once all dependencies and plug-in are copied and pasted in pom.xml file. Automatically all required jar files will be downloaded for maven project and always maintain right version.


Once you added dependencies and plugins, installed jars, you will see red error mark on maven project- how will you rectify it?

To rectify it-
just right click on project
> Maven
> Update Project
> Select Maven Project
> Tick to Force update of....
> Ok.
> Refresh project.

What is SNAPSHOT in Maven?

Its a special version which indicates current development copy. Unlike regular versions, Maven checks for a new SNAPSHOT version in a remote repository after every build.

Why profile is used in Maven?

To provide portability to projects ( e.g. windows, linux etc).


What and explain maven bild life cycle?

Clean :clean target folder.
Compile :compile source code of project.
Test :test the compiled code.
Package :convert your project into jar file or war file.
Install :install the package into local repository for use of another project.

How many pom.xml file a proect can have?

-One maven maven project can have only one pom.xml file.

Can we parameterize the value through pom.xml file? How?

-Yes, we can parameterize some value through pom.xml file.

-We need to use <systemPropertyVariables> tag within <configuration> tag. Here we can set parameter.
-Also we need to use annotation @Parameters("parameterName") in association with test method.
-And right click on pom.xml >
Run As >
Maven build >
Edit Configuration window will open >
Here click on "Add" >
Set ParamterName and its value >
Ok >
Ok.

How will you run maven project?

One Way>>
Right click on project > Run As > Maven Clean : It should be BUILD SUCCESS.
Right click on project > Run As > Maven Install : It should be BUILD SUCCESS.
Right click on project > Run As > Maven Test : It should be BUILD SUCCESS.

OR

Second Way>>
Right click on pom.xml > Run As > Maven commands(clean, test, install..).
It will work same as above, will return same result as above.

OR

Third Way>>
Generally, We run testng.xml file as below-

Right click on testng.xml > Run As > testNG Suite


What and explain maven bild life cycle?

validate
- validate the project is correct and all necessary information is available
compile
- compile the source code of the project
test
- test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package
- take the compiled code and package it in its distributable format, such as a JAR.
verify
- run any checks on results of integration tests to ensure quality criteria are met
install
- install the package into the local repository, for use as a dependency in other projects locally
deploy
- done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.


Can we integrate maven with testng, jenkin, cucumber, data driven framework?

-Yes, we can.


Note: All above question Answers are not only written by me but collected by different groups.

1 comment:

Maven Interview questions with Answers

Maven Interview questions with Answers What is Maven? -Apache Maven is a Software Project Management tool. -It is also known as Bui...