Installing Selenium 2.0, maven,testng and eclipse.

I think I did struggle a bit to have this installed, and by trial and error I finally got it working on my mac. Here is what worked for me, if while installing you come across any problems please feel free to leave me a comment. Check if java is installed by typing java -version, if java does exist no error is displayed. Else install java before proceeding.

1. Start out by installing eclipse.( I have Indigo installed)

2. Launch eclipse, now within eclipse go to help->install new software and plug-in http://m2eclipse.sonatype.org/sites/m2e in the URL and follow the process to install maven.

3. Similarly install testng with  http://beust.com/eclipse

4. Now click on File->new->java project.

If you see a warning like

Description Resource Path Location Type
Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment. another project Build path JRE System Library Problem then to fix it , right click on the java library , build path and remove it. RIght click on the project->build path->configure build path ->add library->JRE system library->next, and pick the default java library

5. Right click on the project ->maven ->enable dependency. Observe that maven dependencies library and bin/source folders are created.

 5. Right click on the pom.xml file that is present and open with a text editor, replace with

<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>MySel20Proj</groupId>
        <artifactId>MySel20Proj</artifactId>
        <version>1.0</version>
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>2.14.0</version>
            </dependency>
        </dependencies>
</project>

make sure that the version is the latest as displayed here

6. Right click on the project and go to maven->update dependencies.

7. Click on File->new->source folder. Create structure /src/test/java.

8. Create new package (example) and class (google) paste the following test example:

package example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class google {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();

// And now use this to visit Google
driver.get("http://www.google.com");
// Alternatively the same thing can be done like this
// driver.navigate().to("http://www.google.com");

// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));

// Enter something to search for
element.sendKeys("Cheese!");

// Now submit the form. WebDriver will find the form for us from the element
element.submit();

// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());

// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});

// Should see: "cheese! - Google Search"
System.out.println("Page title is: " + driver.getTitle());

//Close the browser
driver.quit();
}
}

9. Now select project and click the play button.

10. VIOLA!

I have added testng functionality to the project but have not utilized it yet. I referred to jc webconcepts and the selenium site to help me with the installation. So thanks!

This is what my view looks like