Introduction to Maven

Maven Integration with Selenium

1) What is Maven?

> Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.

> Maven is a simple build automation tool which is basically used with java projects. We Software Testers can use this tool to maintain Selenium Automated Test project.

> 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.

2) Use of Maven Integration with Selenium

i) Selenium Test Environment Setup:
> Generally we setup Selenium Environment manually by downloading the required software jar files and add to Java Project,

> if we use Selenium Integration with Maven, you just add required Software dependencies (the code available in Maven Repository) in Maven POM XML file then it can download those jar files and add to the Project.

Ex: Selenium WebDriver jars, TestNG jars etc…

So, we can setup Selenium Environment easily with the Maven Integration.

ii) Maintenance of Selenium Environment:

> Generally we have to maintain Selenium Test Environment manually, if any new version of software is available then we need to download that new version and install.

> If we use Selenium Integration with Maven, add/edit new version dependencies code in Maven POM XML then it will download the new version and update…

> So Easy Maintenance of Selenium Environment

iii) Common Configuration for Team Members

> Suppose we four members working for a project, then how to maintain common configuration for all team members, first configure Selenium in one computer, share that details to all team members and using that details all team members have to configure their machines

> If we use Selenium Integration with Maven, just create Maven Project, add software dependencies to Maven POM XML file, send that details to all team members and by creating the same XML file all team members can get same configuration…

Selenium Integration with Maven Project

3) Create Maven Project

File>New>Project>Type Maven and Select Maven Project,
>Enter > Next >Next> Enter Group Id> Enter Artifact Id> Finish
Then It will create New Maven project
Note:
1) Group Id – This is an Id of project’s group.
2) Artifact Id -This is an Id of the project.

Add Software Dependencies to POM – XML

> Collet Software Dependencies from Internet for your Automated Testing in POM (Project Object Model)

> Paste the code in POM XML file between “Dependencies” tag…and Save Then it will download those dependencies jar files and add to Maven Project

4) Write & Run Selenium Test Cases in Maven Project

Create a Selenium Test Batch and Run

gcrShop Application Admin Interface:

1) Login Test Batch:
i) Lunch Application
ii) Verify important elements in Admin interface Login Page
iii) Verify “Redirect” functionality in Admin Interface (Redirect from Admin to User Interface)
iv) Verify Admin Login with valid Username and password
v) Verify Invalid Login and Error Message
Assignment:
vi) Verify Admin Login Locking Functionality
(After three failed login attempts then Admin Login is locked for 5 minutes)
.
————————————————–
i) POM – Page Object Model – to create and maintain Object Repositories
ii) POM (in Maven Project) – Project Object Model – to add software dependencies and edit
————————————————–
Create Login Test Batch
Test Environment,
Eclipse IDE – Editor to write and execute Test Scripts
Java – to write, enhance and execute Test Scripts/Cases
Selenium WebDriver – To write Test Steps/Scripts
TestNG Framework – As Test Runner
Maven – Configuration of Test Environment, Maintain common configuration for all team members and
Maintenance of Test Environment….
————————————————–
Create Maven Project:

In Eclipse IDE,
File > New > Project> Type Maven and select Maven >Project> Enter
Or
File > New >Maven Project>Enter
> Next
> Next
> Enter Group Id (this is an id of projects group in your company)
Ex: Banking
> Enter Artifact ID (this is an id of the project)
Ex: online banking
> Finish
————————————————–
Add Software dependenies to Maven POM XML file:

Note: Configure one computer using Maven Integration, add software dependencies to POM XML, and share
the XML to all Team members and by using the XML all team members can get common configuration
————————————————–
Login Test Batch Script

Create Test Cases under src/test/java> Java Package>..

@BeforeMethod
public void launchBrowser(){
System.setProperty(“webdriver.chrome.driver”, “F:/chromedriver.exe”);
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@AfterMethod
public void closeBrowser(){
driver.close();
}
@Test(priority=1)
public void launchApplication(){
driver.get(“http://www.gcrit.com/build3/admin/login.php”);
//String pageTitle = driver.getTitle();
Assert.assertEquals(“GCR Shop”, driver.getTitle());
}
@Test(priority=2)
public void verifyElements(){
driver.get(“http://www.gcrit.com/build3/admin/login.php”);
Assert.assertEquals(true, driver.findElement(By.name(“username”)).isDisplayed());
Assert.assertEquals(true, driver.findElement(By.name(“password”)).isDisplayed());
Assert.assertEquals(true, driver.findElement(By.id(“tdb1”)).isDisplayed());
}
@Test(priority=3)
public void redirectfromAdmintoUser() throws InterruptedException{
driver.get(“http://www.gcrit.com/build3/admin/login.php”);
driver.findElement(By.linkText(“Online Catalog”)).click();
Thread.sleep(3000);
Assert.assertEquals(“http://www.gcrit.com/build3/”, driver.getCurrentUrl());
}
@Test (priority=4)
public void adminLogin(){
driver.get(“http://www.gcrit.com/build3/admin/login.php”);
driver.findElement(By.name(“username”)).sendKeys(“admin”);
driver.findElement(By.name(“password”)).sendKeys(“admin@123”);
driver.findElement(By.id(“tdb1”)).click();

Assert.assertEquals(“http://www.gcrit.com/build3/admin/index.php”, driver.getCurrentUrl());
}
@Test(priority=5)
public void verifyErrorMessage(){
driver.get(“http://www.gcrit.com/build3/admin/login.php”);
driver.findElement(By.name(“username”)).sendKeys(“admin1”);
driver.findElement(By.name(“password”)).sendKeys(“admin@123”);
driver.findElement(By.id(“tdb1”)).click();

String ErrorMessage =driver.findElement(By.className(“messageStackError”)).getText();
Assert.assertEquals(“Error: Invalid administrator login attempt.”, ErrorMessage);
}
}
—————————————————————————————————

Follow me on social media: