Problem with Selenium 2 (WebDriver) + Java + Maven + Eclipse Hello World

Java Hello Hello project converts to Maven project and fails

"Error: could not find or load the main class ..."

Hello to all,

I searched a lot on google but could not find the Hello World program for Selenium 2 ( WebDriver )+ Java + Maven + Eclipse installation instructions

I have below settings

  • Eclipse with Maven plugin
  • Created a Java project, "Hello World", and it worked great when run as a "Java application"
  • Then transformed it into a Marven project.
  • I tried to run the whole project, but it did not start
  • I tried to run the Hello World file, and it successively failed with the error "Error: could not find or load the main class ..."

Questions:

  • How to configure and run the basic selenium 2 program with maven inside Eclipse.
  • Why Java stopped working after converting to a Maven project.

Thanks in advance.

Regards, Vikram

+6
source share
1 answer

Unable to play.

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

  • I created a new Java Hello World project (right-click in Package Explorer -> New Java project ):

    New java project

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

    New package and class created

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

    Hello world impl

    Hello world impl result

  • I converted the project to a Maven project (right click on the project -> Configure Convert to Maven Project ) by clicking Finish

    Convert to Maven Project

  • I fixed the errors that Maven threw at me.

    He said: "Project build error:" artifactId "with a value of" Hello World "does not match a valid identifier pattern." So I realized that Hello World might be invalid due to a space. I was right. Removing space from Artifact Id and Group Id fixed the assembly.

    Before:

    Before fixing maven project

    After (do not forget to save the file using Ctrl + s ):

    After fixing maven project

  • Now everything is working as intended. The HelloWorld class at startup still displays the same as before. The project now had a slightly different folder structure (new bin and target folders, a new pom.xml file):

    Maven Project file structure

  • I added a Selena addiction. Open pom.xml , go to 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 load all the pros and dependencies of Selenium, it took some time (pay attention to the Progress toolbar in Eclipse, which does something).

    The only thing that has changed is that the project structure had a new Maven Dependencies element containing Selenium and all its dependencies.

    Maven dependencies

  • I was ready to give up with Selen:

    Selenium hello world

    When launched, Firefox opens, goes to Google and ends.

+21
source

Source: https://habr.com/ru/post/950004/


All Articles