Getting a fully working Maven install up-and-running is beyond the scope of this book, but it shouldn't be too hard. Apache has a guide to setting Maven up in 5 minutes at the following link:
http://maven.apache.org/guides/getting-started/maven-in-five-minutes. html
If you are running the Debian derivative of Linux, it is as easy as:
sudo apt-get install maven
Or, if you are running a Mac with homebrew, it is just:
brew install maven
Once you have Maven installed and working, we will start our Selenium project with a basic POM le. We are going to start out by creating a basic Maven directory structure and then creating a le called pom.xml in it. The directory structure is displayed here:
There are two main testing frameworks that you will come across in a Java environment: jUnit and TestNG. I personally nd TestNG to be easier to get up-and-running out-of-the-box, but I nd jUnit to be more extensible. TestNG certainly seems to be popular on the Selenium mailing list with many threads asking questions about it; you don't often see jUnit questions any more.
I'm not going to suggest either one as the right choice as they are both capable frameworks that you will probably come across in the enterprise world. Since TestNG seems to be the more popular option, we will focus on a TestNG implementation in this chapter.
In this chapter, we will implement the same base project, but we will use jUnit instead of TestNG. This means that, instead of worrying about which one is the best, you can have a look at a TestNG implementation and a jUnit implementation. You can then choose which one you prefer and read the relevant section.
So to start off with, let's have a look at a basic POM for a TestNG-based Maven project:
<?xml version="1.0" encoding="UTF-8"?> <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">
<groupId>com.masteringselenium.demo</groupId> <artifactId>mastering-selenium-testng</artifactId> <version>1.0-SNAPSHOT</version> <modelVersion>4.0.0</modelVersion>
<name>Mastering Selenium TestNG</name>
<description>A basic Selenium POM file</description> <url>http://www.masteringselenium.com</url>
<properties> <project.build.sourceEncoding>UTF-8
</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8 </project.reporting.outputEncoding> <!-- Dependency versions --> <selenium.version>2.45.0</selenium.version>
</properties>
<dependencies> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>${selenium.version}</version> <scope>test</scope>
</dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-remote-driver</artifactId> <version>${selenium.version}</version>
</dependency> <dependency>
<groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8</version> <scope>test</scope>
</dependency> </dependencies>
</project>
What you are seeing here is mainly Maven boilerplate code. The groupId,
artifactId, and version properties are subject to the standard naming conventions:
-
groupId: This should be a domain that you own/control and is entered
in reverse
-
artifactId: This is the name that will be allocated to your JAR file, so remember to make it what you want your JAR file to be called
-
version: This should always be a number with -SNAPSHOT appended to the end; this shows that it is currently a work in process
Comments
0 comments
Please sign in to leave a comment.