Selenium 2 (WebDriver) + Java + Maven + Eclipse Hello World Program issue

20,390

Cannot reproduce.

Here's how I did it (Eclipse 4.3 Kepler, Oracle JDK 7u25):

  1. I made a new Hello World Java project (right click in the Package Explorer -> New -> Java project):

    New Java project

  2. I named it Hello World and clicked Finish. I created a new package in the src folder named hello and a new class HelloWorld in it:

    New package and class created

  3. I implemented the HelloWorld class and ran it (F11):

    Hello World impl

    Hello world impl result

  4. I converted the project to a Maven Project (right click on the project -> Configure -> Convert to Maven Project), clicked Finish

    Convert to Maven Project

  5. I fixed the errors Maven was throwing at me.

    It said "Project build error: 'artifactId' with value 'Hello World' does not match a valid id pattern.", so I figured Hello World might be invalid because of the space. I was right. Removing the space from Artifact Id and Group Id fixed the build.

    Before:

    Before fixing Maven project

    After (don't forget to save the file via Ctrl+s):

    After fixing Maven project

  6. Right now, everything worked as intended. The HelloWorld class, when ran, still output the same thing as before. The project now had a slightly different folder structure (new bin and target folders, new pom.xml file):

    Maven Project file structure

  7. I added Selenium dependancy. Open pom.xml, click the Dependencies tab, click Add..., find Selenium-java, specify version 2.33.0.

    Add Selenium dependancy

    After I clicked OK and saved the POM file, I had to wait for Maven to download all the Selenium goodies and dependencies, that took a while (observe the Progress toolbar in Eclipse doing something).

    The only thing that changed was that the project structure had a new Maven Dependencies item containing Selenium and all of its depenedencies.

    Maven Dependencies

  8. I was ready to roll with Selenium:

    Selenium Hello World

    When run, this opens Firefox, goes to Google and finishes.

Share:
20,390
vikramvi
Author by

vikramvi

Updated on July 05, 2022

Comments

  • vikramvi
    vikramvi almost 2 years

    Java "Hello World" project convert to Maven Project and it stopped working with error

    "Error: Could not find or load main class...."

    Hi All,

    I did lot of search in google but couldn't find any Hello World program for Selenium 2 ( WebDriver )+ Java + Maven + Eclipse setup instructions

    I'm having below setup

    1. Eclipse with Maven plugin
    2. Created a Java project "Hello World" and it worked fine when ran as "Java Application"
    3. Then converted this to Marven Project.
    4. Tried to run whole project but it didn't run
    5. Tried to run Hello World file and it's consistently failed with error "Error: Could not find or load main class...."

    Questions:

    1. How to setup and run basis selenium 2 program with maven inside Eclipse
    2. Why java stopped working after converting to Maven project.

    Thanks in advance.

    Regards, Vikram