Selenium 24:Use of Maven Build Automation Tool and Maven Project Setup for Selen

2023-12-11 01:59

本文主要是介绍Selenium 24:Use of Maven Build Automation Tool and Maven Project Setup for Selen,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

http://www.softwaretestinghelp.com/maven-project-setup-for-selenium-selenium-tutorial-24/

 

In our last Selenium tutorial we learned a build tool named as “Apache Ant”. We also broadly discussed its applicability and importance besides the practical approach.

In this Selenium Testing tutorial we will learn Maven – a build automation tool which is distributed under Apache Software Foundation. It is mainly used for java projects. It makes build consistent with other project.

Maven is also used to manage the dependencies. For example if you are using selenium version 2.35 and any later point of time you have to use some other version, then same can be managed easily by Maven. You will find more examples of this later in this chapter. It works very effectively when there is huge number of Jar files with different versions.

What is a build tool?

Build tool is used to setup everything which is required to run your java code independently. This can be applied to your entire java project. 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 while handling huge project.

Maven provides pom.xml which is the core to any project. This is the configuration file where all required information’s are kept. Many of the IDEs (Integrated Development Environments) are available which makes it easy to use. IDEs are available for tools like Eclipse , NetBeans, IntelliJ etc.

Maven stores all project jars. Library jar are in place called repository which could be central, local or remote repository. Maven downloads the dependency jar from central repository. Most of the commonly used libraries are available in http://repo1.maven.org/maven2/.

Downloaded libraries are stored in local repository called m2. Maven uses the libraries available in m2 folder and if any new dependency added then maven downloads from central repository to local repository. If libraries are not available in central repository then maven looks for remote repository. User has to configure the remote repository in pom.xml to download from remote repository.

Below is the example of configuring a remote repository topom.xml file. Provide id and url of the repository where libraries are stored.

1 <repositories>
2      <repository>
3          <id>libraryId</id>
4          <url>http://comanyrepositryId</url>
5      </repository>
6 </repositories>

General Phrases used in Maven:

  • groupId: Generally groupId refers to domain id. For best practices company name is used as groupId. It identifies the project uniquely.
  • artifactId: It is basically the name of the Jar without version.
  • version: This tag is used to create a version of the project.
  • Local repository: Maven downloads all the required dependencies and stores in local repository called m2. More details regarding the same would be shared in the next topic.

Build Life Cycle:

Basic maven phases are used as below.

  • clean: deletes all artifacts and targets which are created already.
  • compile: used to compile the source code of the project.
  • test: test the compiled code and these tests do not require to be packaged or deployed.
  • package: package is used to convert your project into a jar or war etc.
  • install: install the package into local repository for use of other project.

Maven Setup:

Step 1: To setup Maven, download the maven’s latest version form Apache depending upon different OS.

Step 2: Unzip the folder and save it on the local disk.

Step 3: Create environment variable for MAVEN_HOME. Follow the below step:

Navigate to System Properties ->Advanced System Setting->Environment Variable ->System Variable ->New ->Add path of Maven folder

Maven Tutorial 1

Maven Tutorial 2

Step 4: Edit path variable and provide the bin folder path.

Maven Tutorial 3

Step 5: Now verify the maven installation using command prompt and don’t forget to setup JAVA_HOME

Use mvn –version to verify maven version and output comes like below.

Maven Tutorial 4

Install maven IDE in Eclipse:

Maven provides IDE to integrate with eclipse. I am using eclipse Juno here.

Navigate to Help->Eclipse Marketplace-> Search maven ->Maven Integration for Eclipse ->INSTALL

Maven Tutorial 5

After installation you have to restart eclipse.

Then right click on pom.xml and verify all the options are available like below.  

Maven Tutorial 6

Create Maven project:

Step 1: Navigate to File- new-others-Maven-Maven Project-Click Next

Maven Tutorial 7

Step 2: Check the Create a simple project and click Next

Maven Tutorial 8

Step 3: Provide Group Id and Artifact Id .You can change the version of Jar as per your wish. Here I am using default name. Click Finish.

Maven Tutorial 9

Step 4: After finish you will find the project structure is created like below. pom.xml is created which is used to download all dependencies.

Maven Tutorial 10
pom.xml file looks like below:

------------

1 <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2 <modelVersion>4.0.0</modelVersion>
3 <groupId>com.softwaretestinghelp.test</groupId>
4 <artifactId>com.softwaretestinghelp.selenium</artifactId>
5 <version>0.0.1-SNAPSHOT</version>
6 </project>

Step 5: Add dependencies for Selenium.

All selenium Maven artifacts are available in below central repository

http://repo1.maven.org/maven2/org/seleniumhq/selenium/

Add following dependencies in pom.xml for selenium

1 <dependency>
2        <groupId>org.seleniumhq.selenium</groupId>
3        <artifactId>selenium-java</artifactId>
4        <version>2.41.0</version>
5  </dependency>

Similarly, following is the dependency for Junit :

1 <dependency>
2       <groupId>junit</groupId>
3       <artifactId>junit</artifactId>
4       <version>4.4</version>
5  </dependency>

If you want to add other third party jar then add those dependencies in pom.xml

Step 6: Final pom.xml will be like below:

1 <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2 <modelVersion>4.0.0</modelVersion>
3 <groupId>com.softwaretestinghelp.test</groupId> <artifactId>com.softwaretestinghelp.selenium</artifactId>
4 <version>0.0.1-SNAPSHOT</version>
5 <dependencies>
6 <dependency>
7        <groupId>org.seleniumhq.selenium</groupId>
8        <artifactId>selenium-java</artifactId>
9        <version>2.41.0</version>
10    </dependency>
11    </dependencies>
12 </project>

Step 7: Maven will download all the dependency jars in to local repository called .m2.

M2 folder is basically inside Users->username->m2

All the jars will be placed in a folder called repository which is inside .m2 folder. Maven will create separate folders for different version and different group id.

Maven Tutorial 11

Step 8: If m2 folder does not populate in Maven dependencies, then you can populate those jars manually.

– Eclipse Windows ->Preference
– Navigate Java->Build Path->Classpath Variables

Maven Tutorial 12

– Click New Button ->Define M2_REPO and provide the path of m2 folder.

Step 9: Upon successful setup you will find Maven Dependencies folder like below which will have the required dependency jar for the project

Maven Tutorial 13

Build the Project:

Project can be built by both using IDE and command prompt.

Using IDE you have to right click on POM-Run As-Maven Build

Maven Tutorial 14

Enter goals like clean install etc. and click Run.
Same can be done using command prompt. Navigate to project folder where pom.xml lies.
And use below commands to clean, compile and install

For clean: mvn clean
For compile: mvn compile
For Install: mvn install

Below is the info which is displayed when you clean any project and shows “BUILD SUCCESS”.

1[INFO] Scanning for projects...
2[INFO]
3[INFO] ------------------------------------------------------------------------
4[INFO] Building com.softwaretestinghelp.0.0.1-SNAPSHOT
5[INFO] ------------------------------------------------------------------------
6[INFO]
7  [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ com.softwaretestinghelp ---[INFO] Deleting C:\Users\rshwus\WORKSPACE\com.softwaretestinghelp\target
8[INFO] ------------------------------------------------------------------------
9[INFO] BUILD SUCCESS
10[INFO] ------------------------------------------------------------------------
11[INFO] Total time: 0.702s
12[INFO] Finished at: Sat May 24 18:58:22 IST 2014
13[INFO] Final Memory: 2M/15M
14[INFO] ------------------------------------------------------------------------

Conclusion:

Maven simplifies the code handling and process of building the project. Most of the projects follow maven structure.

Download all dependencies provided the dependencies are available in maven central repository. If any of the dependency is not available in maven central repository then you have to add repository path in pom.xml explicitly.

There are many other build tools available in like ant. But it is better to use maven while dealing with different versions and different dependencies. Maven even can manage the dependencies of dependencies. Other tools may not provide such flexibility like maven. Please post your queries anything related to maven here.

Next Tutorial #25: In the upcoming tutorial, we would discuss aboutcontinuous integration tool known as Hudson. We would study about its importance, role and benefits into Test Automation Framework. We would look at the Hudson straight from the beginning, from its installation to its working

这篇关于Selenium 24:Use of Maven Build Automation Tool and Maven Project Setup for Selen的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/479065

相关文章

每天认识几个maven依赖(ActiveMQ+activemq-jaxb+activesoap+activespace+adarwin)

八、ActiveMQ 1、是什么? ActiveMQ 是一个开源的消息中间件(Message Broker),由 Apache 软件基金会开发和维护。它实现了 Java 消息服务(Java Message Service, JMS)规范,并支持多种消息传递协议,包括 AMQP、MQTT 和 OpenWire 等。 2、有什么用? 可靠性:ActiveMQ 提供了消息持久性和事务支持,确保消

30常用 Maven 命令

Maven 是一个强大的项目管理和构建工具,它广泛用于 Java 项目的依赖管理、构建流程和插件集成。Maven 的命令行工具提供了大量的命令来帮助开发人员管理项目的生命周期、依赖和插件。以下是 常用 Maven 命令的使用场景及其详细解释。 1. mvn clean 使用场景:清理项目的生成目录,通常用于删除项目中自动生成的文件(如 target/ 目录)。共性规律:清理操作

在cscode中通过maven创建java项目

在cscode中创建java项目 可以通过博客完成maven的导入 建立maven项目 使用快捷键 Ctrl + Shift + P 建立一个 Maven 项目 1 Ctrl + Shift + P 打开输入框2 输入 "> java create"3 选择 maven4 选择 No Archetype5 输入 域名6 输入项目名称7 建立一个文件目录存放项目,文件名一般为项目名8 确定

MCU7.keil中build产生的hex文件解读

1.hex文件大致解读 闲来无事,查看了MCU6.用keil新建项目的hex文件 用FlexHex打开 给我的第一印象是:经过软件的解释之后,发现这些数据排列地十分整齐 :02000F0080FE71:03000000020003F8:0C000300787FE4F6D8FD75810702000F3D:00000001FF 把解释后的数据当作十六进制来观察 1.每一行数据

maven 编译构建可以执行的jar包

💝💝💝欢迎莅临我的博客,很高兴能够在这里和您见面!希望您在这里可以感受到一份轻松愉快的氛围,不仅可以获得有趣的内容和知识,也可以畅所欲言、分享您的想法和见解。 推荐:「stormsha的主页」👈,「stormsha的知识库」👈持续学习,不断总结,共同进步,为了踏实,做好当下事儿~ 专栏导航 Python系列: Python面试题合集,剑指大厂Git系列: Git操作技巧GO

Maven创建项目中的groupId, artifactId, 和 version的意思

文章目录 groupIdartifactIdversionname groupId 定义:groupId 是 Maven 项目坐标的第一个部分,它通常表示项目的组织或公司的域名反转写法。例如,如果你为公司 example.com 开发软件,groupId 可能是 com.example。作用:groupId 被用来组织和分组相关的 Maven artifacts,这样可以避免

Maven(插件配置和生命周期的绑定)

1.这篇文章很好,介绍的maven插件的。 2.maven的source插件为例,可以把源代码打成包。 Goals Overview就可以查看该插件下面所有的目标。 这里我们要使用的是source:jar-no-fork。 3.查看source插件的example,然后配置到riil-collect.xml中。  <build>   <plugins>    <pl

maven发布项目到私服-snapshot快照库和release发布库的区别和作用及maven常用命令

maven发布项目到私服-snapshot快照库和release发布库的区别和作用及maven常用命令 在日常的工作中由于各种原因,会出现这样一种情况,某些项目并没有打包至mvnrepository。如果采用原始直接打包放到lib目录的方式进行处理,便对项目的管理带来一些不必要的麻烦。例如版本升级后需要重新打包并,替换原有jar包等等一些额外的工作量和麻烦。为了避免这些不必要的麻烦,通常我们

Jenkins构建Maven聚合工程,指定构建子模块

一、设置单独编译构建子模块 配置: 1、Root POM指向父pom.xml 2、Goals and options指定构建模块的参数: mvn -pl project1/project1-son -am clean package 单独构建project1-son项目以及它所依赖的其它项目。 说明: mvn clean package -pl 父级模块名/子模块名 -am参数

Science|癌症中三级淋巴结构的免疫调节作用与治疗潜力|顶刊精析·24-09-08

小罗碎碎念 Science文献精析 今天精析的这一篇综述,于2022-01-07发表于Science,主要讨论了癌症中的三级淋巴结构(Tertiary Lymphoid Structures, TLS)及其在肿瘤免疫反应中的作用。 作者类型作者姓名单位名称(中文)通讯作者介绍第一作者Ton N. Schumacher荷兰癌症研究所通讯作者之一通讯作者Daniela S. Thomm