Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Wednesday, 5 February 2014

Installing m2eclipse – Maven Plugin for Eclipse

In this tutorial, we will see how to install m2eclipse plugin which provides Maven integration in Eclipse IDE.


Before installing eclipse plugin in ellipse. its better to install maven in your machine  look at this post Maven installation

Environment Used

  • Java SE 6
  • Eclipse Juno for Java EE Developers  IDE
  • Maven Eclipse Plugin – m2eclipse version 1.2


    Before going forward make sure you have set the JDK path as JAVA_HOME in your environmental variables.

 



Online Installation (From Update Site) of Maven Plugin m2eclipse:

Step 1:

Installing m2eclipse is fairly simple. Start Eclipse then go to:
Help -> Install New Software…
Copy this link http://download.eclipse.org/technology/m2e/releases for the latest Stable Release into Eclipse and hit Enter.


When the site loads, select the features to install, or click the Select All button. For our requirement select “Maven Integration for Eclipse” as shown above.
Checking [x] Contact all update sites during install to find required software might take sometime and this is optional.

Step 2:

  • Click Next to view Installation Details.
  • Click Next to agree the license terms, and click Finish.

Step 3:

If you get any warning message when installing, click OK to continue.

This will take few minutes to install the Maven plugin and once done restart the Eclipse.


Creating New Maven Project in Eclipse


After installing the Maven plugin for Eclipse, you can check if the installation is successful by creating a new Maven project.
You should see a Maven folder in the New project wizard as shown below



Now you have successfully installed “Maven plugin – m2eclipse” in Eclipse IDE.


Other popular posts:


How to install Maven on Windows

All possible ways for handling DragAndDrop using Selenium

All Possible ways for switching frames in Selenium

Automating tables tags using Selenium

Selenium Webdriver Integration with JBheave (BDD)















How to install Maven on Windows


Maven Installation is quite straight forward please have look at the following procedure and do comment if you get any issues while installing maven

Apache Maven is not require to install on Windows as a service component, you just need to download the Maven’s zip file, extract it and configure the Windows environment path variable.
Tools Used :
  1. JDK 1.6 or newer version
  2. Maven 2.2.1 or newer version
  3. Windows xp or  7

    1. JDK and JAVA_HOME


    Make sure JDK is installed, and “JAVA_HOME” variable is added in Windows environment variable, and point to the JDK folder.

    2. Download Apache Maven

    Visit this Maven official website, choose a version and click on the download link, e.gapache-maven-3.1.1-bin.zip


    3. Extract It

    Extract the downloaded zip file. In this case, we extracted to d driver and renamed the folder, e.g D:\mavenNote:
    That’s all, just folders and files, installation is NOT required on Windows.

    4. Add MAVEN_HOME

    Add a new "MAVEN_HOME" variable to the Windows environment, and point it to your Maven folder.




    5. Add PATH

    Update "PATH" variable, append “Maven bin folder” path, so that you can run the Maven’s command everywhere.





    6. Verification

    Done, to verify it, in command prompt, type “mvn –version“.





    If you see similar message, means your Apache Maven is installed successfully on Windows.


    Other popular posts:


    All possible ways for handling DragAndDrop using Selenium

    All Possible ways for switching frames in Selenium

    Automating tables tags using Selenium

    Selenium Webdriver Integration with JBheave (BDD)

Tuesday, 4 February 2014

Webdriver Integration with Jbehave (BDD)




JBehave is a framework for Behaviour-Driven Development (BDD). BDD is an evolution of test-driven development (TDD) and acceptance-test driven design, and is intended to make these practices more accessible and intuitive to newcomers and experts alike. It shifts the vocabulary from being test-based to behaviour-based, and positions itself as a design philosophy.

In this post i will be explaining, how to create sample Maven Jbehave project for Selenium.For this i am assuming that you have maven installed in your system and maven plugin for eclipse, if not you can have a look at this posts, this is pretty straight forward.



How to install Maven on Windows .

Installing m2eclipse – Maven Plugin for Eclipse
.

Creating Maven Jbeave project form the command line:

Execute following maven command in the command line

mvn archetype:generate -Dfilter=org.jbehave:jbehave

when you execute this command, maven will list out all the available of Jbehave atchetypes(simple project, groovy, web e.t.c)
As an example i am entering 5 (i.e Jbehave-Simple-archetype) as a input.

Then cmd line will ask for entering groupid .
what is groupid?
    groupId will identify your project uniquely across all projects, so we need to enforce a naming schema. It has to follow the package name rules, what means that has to be at least as a domain name you control, and you can create as many subgroups as you want. Look at More information about package names.
eg. org.apache.maven, org.jbehave.selenium

I am entering com.jbehave.selenium




Then cmd requests for artifactid

What is artifactid?
   artifactId
is the name of the jar without version. If you created it then you can choose whatever name you want with lowercase letters and no strange symbols. If it's a third party jar you have to take the name of the jar as it's distributed.
  •      eg. maven, jbehave-selenium

I am entering jbehave-selenium



Then cmd requests for versionwhat is version?
     version if you distribute it then you can choose any typical version with numbers and dots (1.0, 1.1, 1.0.1, ...). Don't use dates as they are usually associated with SNAPSHOT (nightly) builds. If it's a third party artifact, you have to use their version number whatever it is, and as strange as it can look.






Then cmd requests for package enter , after entering the package name cmd requests for Confirm properties configuration: where you need to enter Y





And finally you will getting a conformation message that Build Success as like bellow.




Configuring maven setup form the command line:

After creating the maven project you need to configure this project with the eclipse . For that you need to add the eclipse resource (jars) in order to do that we need to execute the following command by navigating to the maven project ( In our example i need to navigate to
jbehave-selenium i.e artifactid )

mvn eclipse:eclipse






Open the Project in Eclipse :

Now Jbehave Maven project is created , open the eclipse set the workspace as created project's parent directory( In my case i have created the project in C:\Document and Settings\smedarapu\jbejave-selenium , so i am setting workspace at C:\Document and Settings\smedarapu )Now in eclipse click on New --> Other ---> java --> java project-->Next then enter the project name what you have created (in my case it is jbehave-selenium ), Finally click on Finish .

Then project will be opened with the default code and in the following structure.


Now open the pom.xml file and add the selenium dependency under the <dependencies> tag

Selenium maven dependency:
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.39.0</version>
        </dependency>
Now will try to look at the coding part

Open the  my.story file and replace existing content with following content


Scenario: A sample scenario for Jbeahve with selenium

Given I am in FF
And I navigate to google
Then I verify search field



in the MySteps.java add the following code



import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Pending;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MySteps {
   
    static WebDriver driver;
    @Given("I am in FF")
    public void invokeBrowser()
    {
         driver = new FirefoxDriver();
    }
   
    @Given("I navigate to google")
    public void navigate()
    {
        driver.get("http://www.google.co.in");
    }
   
    @Given("I verify search field")
    public void verify()
    {// verifying search element in google home page
        driver.findElement(By.id("gs_htif0")).isDisplayed();
        driver.quit();
       
    }
}



Now right click on pom.xml Run As--> Maven Clean then Run As --> Maven install , you can see the test cases execution starts where the FF invoke then navigates to the google finally search for the searchfield in google field .

How it works...

For creating tests in JBehave, we will need to first implement stories as the .story file using
the Given, When, and Then structures. We need to  describe the purpose of the story in the Scenario section, which contains the actual steps. We also
pass the required test data from these steps:

Scenario: A sample scenario for Jbeahve with selenium

Given I am in FF
And I navigate to google
Then I verify search field

Next, we map these steps using a step definition class(i.e in MySteps ).


For each step, we use an annotation and implement a method to run that step. For example,
for the step Given I am in FF we have defined the invokeBrowser()
method as follows:

@Given("I am in FF")
    public void invokeBrowser()
    {
         driver = new FirefoxDriver();
    }
Along with a story file and a step definition class, a Configuration class needs to be
created, which will be based on the JUnitStory class from the JBehave framework:
public abstract class MyStories extends JUnitStory

It also provides other configuration information, like the location of the story files and report
settings, and format the JBehave framework. In this case, the .story files will be located
using the path of the story or step definition classes:
 @Override
    public Configuration configuration() {
        Class<? extends Embeddable> embeddableClass = this.getClass();

        // Start from default ParameterConverters instance
        ParameterConverters parameterConverters = new ParameterConverters();

        // factory to allow parameter conversion and loading from external resources (used by StoryParser too)
        ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), new LoadFromClasspath(embeddableClass), parameterConverters);

        // add custom converters
        parameterConverters.addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")),
                new ExamplesTableConverter(examplesTableFactory));
        return new MostUsefulConfiguration()
            .useStoryLoader(new LoadFromClasspath(embeddableClass))
            .useStoryParser(new RegexStoryParser(examplesTableFactory))
            .useStoryReporterBuilder(new StoryReporterBuilder()                .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass))
                .withDefaultFormats()
                .withFormats(CONSOLE, TXT, HTML, XML))
            .useParameterConverters(parameterConverters);
    }
We used the JUnitStory class so that we can execute these tests with JUnit Test Runner.
At the end of the execution, JBehave generates an HTML report with a detailed status of the
stories executed, stories passed, or failed.