Skip to main content

Install Maven and use it with TestNG

Steps to use install Maven and use it with TestNG Selenium

For this tutorial, we will use Eclipse (Juno) IDE for Java Developers to set up Selenium WebDriver Project. Additionally, we need add m2eclipse plugin to Eclipse to facilitate the build process and create pom.xml file.
Let's add m2eclipse plugin to Eclipse with following steps:
Step1) In Eclipse IDE, select Help | Install New Software from Eclipse Main Menu.
Step 2) On the Install dialog, select Work with and m2e plugin as shown in the following screenshot:
Step 3)Click on Next button and finish installation.

Configure Eclipse with Maven
With m2e plugin is installed, we now need create Maven project.
Step 1) In Eclipse IDE, create a new project by selecting File | New | Other from Eclipse menu.
Step 2) On the New dialog, select Maven | Maven Project and click Next
Step 3) On the New Maven Project dialog select the Create a simple project and click Next
Step 4) Enter WebdriverTest in Group Id: and Artifact Id: and click finish
Step 5) Eclipse will create WebdriverTest with following structure:
Step 6) Right-click on JRE System Library and select the Properties option from the menu.
On the Properties for JRE System Library dialog box, make sure Workspace default JRE is selected and click OK
Step 7). Select pom.xml from Project Explorer..


pom.xml file will Open in Editor section
Step 8).Add the Selenium and TestNG, JUnit dependencies to pom.xml in the <project> node:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    <dependencies>           
        <dependency>             
             <groupId>junit</groupId>                              
             <artifactId>junit</artifactId>                            
             <version>3.8.1</version>                              
             <scope>test</scope>                               
        </dependency>            
        <dependency>             
            <groupId>org.seleniumhq.selenium</groupId>                             
            <artifactId>selenium-java</artifactId>                             
            <version>2.45.0</version>                              
        </dependency>            
        <dependency>             
            <groupId>org.testng</groupId>                              
            <artifactId>testng</artifactId>                            
            <version>6.8</version>                             
            <scope>test</scope>                                    
       </dependency>             
</dependencies>
Step 9) Create a New TestNG Class. Enter Package name as "example" and "NewTest" in the Name: textbox and click on the Finish button as shown in the following screenshot:
Step 10). Eclipse will create the NewTest class as shown in the following screenshot:
Step 11) Add the following code to the NewTest class:
This code will verify the title of Guru99 Selenium Page
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package example;       
import org.openqa.selenium.By;     
import org.openqa.selenium.WebDriver;      
import org.openqa.selenium.firefox.FirefoxDriver;      
import org.testng.Assert;      
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;  
import org.testng.annotations.AfterTest;       
public class NewTest {     
        private WebDriver driver;      
        @Test              
        public void testEasy() {   
            driver.get("http://www.guru99.com/selenium-tutorial.html"); 
            String title = driver.getTitle();               
            Assert.assertTrue(title.contains("Free Selenium Tutorials"));      
        }  
        @BeforeTest
        public void beforeTest() { 
            driver = new FirefoxDriver(); 
        }      
        @AfterTest
        public void afterTest() {
            driver.quit();         
        }      
}  
Step 12) Right-click on the WebdriverTest and select TestNG | Convert to TestNG.
Eclipse will create testng.xml which says that you need to run only one test with the name NewTest as shown in the following screenshot:
Update the project and make sure that file appears in the tree Package Explorer (right click on the project - Refresh).
Step 13) Now you need to run test through this testng.xml.
So, go to the Run Configurations and create a new launch TestNG, select the project and field Suite astestng.xml and click Run
Make sure that build finished successfully.
Step 14). Additionally, we need to add
  1. maven-compiler-plugin
  2. maven-surefire-plugin
  3. testng.xml
to pom.xml.
The maven-surefire-plugin is used to configure and execute tests. Here plugin is used to configure the testing.xml for TestNG test and generate test reports.
The maven-compiler-plugin is used to help in compiling the code and using the particular JDK version for compilation. Add all dependencies in the following code snippet, to pom.xml in the <plugin> node:
Step 15) To run the tests in the Maven lifecycle, Right-click on the WebdriverTest and select Run As | Maven test. Maven will execute test from the project.
Make sure that build finished successfully.



Maven Learning

1.  Archetype : Used to create Project with same pattern like Hibernate Project, Web project etc.
command : mvn archetype :generate
2. Compile Project  : Go to folder where POM is place
command : mvn compile
3. Compile and Run Test (Unit Test)
command : mvn test
4. How to compile just test resources
command : mvn test-compile
5. How to create jar file using maven
command : mvn package
6. What are POM files
POM Contains :
·         Information about project
·         Project description
·         Versioning
·         Dependencies
7. List objectives provided by Maven
·         Provide Quality Information
·         Transparent Migration to new features
·         Makes build process easy
·         Uniform building system

8. Maven's Order of inheritance
·         Parent POM
·         Project POM
·         Settings
·         CLI Parameters
9. What are two main subdirectory folder of Maven
·         src
·         target
10. What is target directory used?
                House all output of build
11. What is Groupid
                Entity or organization responsible for producing the artifact
12. What is Artifact id
                Name of artifact
13. What is version
                Version number of artifact


Comments

Popular posts from this blog

Testing Types

         Installation testing Main article: Installation testing An installation test assures that the system is installed correctly and working at actual customer's hardware. Compatibility testing Main article: Compatibility testing A common cause of software failure (real or perceived) is a lack of its compatibility with other application software, operating systems (or operating system versions, old or new), or target environments that differ greatly from the original (such as a terminal or GUI application intended to be run on the desktop now being required to become a web application, which must render in a web browser). For example, in the case of a lack of backward compatibility, this can occur because the programmers develop and test software only on the latest version of the target environment, which not all users may be running. This results in the unintended cons...

What really happens when you navigate to a URL

As a software developer, you certainly have a high-level picture of how web apps work and what kinds of technologies are involved: the browser, HTTP, HTML, web server, request handlers, and so on. In this article, we will take a deeper look at the sequence of events that take place when you visit a URL. 1. You enter a URL into the browser It all starts here: 2. The browser looks up the IP address for the domain name   The first step in the navigation is to figure out the IP address for the visited domain. The DNS lookup proceeds as follows: Browser cache –  The browser caches DNS records for some time. Interestingly, the OS does not tell the browser the time-to-live for each DNS record, and so the browser caches them for a fixed duration (varies between browsers, 2 – 30 minutes). OS cache  – If the browser cache does not contain the desired record, the browser makes a system call (gethostbyname in Windows). The OS has its own cache....

Clickjacking

Clickjacking Clickjacking  ( User Interface redress attack ,  UI redress attack ,  UI redressing ) is a  malicious technique  of tricking a  Web   user  into clicking on something different from what the user perceives they are clicking on, thus potentially revealing  confidential  information or taking control of their computer while clicking on seemingly innocuous  web pages . It is a  browser security  issue that is a  vulnerability  across a variety of  browsers  and  platforms . A clickjack takes the form of embedded  code  or a script that can execute without the user's knowledge, such as clicking on a  button  that appears to perform another function. [5]  The term "clickjacking" was coined by Jeremiah Grossman and Robert Hansen in 2008. [ citation needed ]  Clickjacking can be understood as an instance of the  confused deputy problem . [6] ...