wiki:ExpressoTestCenter/auto/tutorial

Version 3 (modified by luiz-fernando, 13 years ago) (diff)

--

10 Minutos com Maven, TestNG e Selenium

  1. Criar um novo projeto Maven no Eclipse:

  1. Editar pom.xml para adicionar as dependencias do projeto logo abaixo da tag <name> do projeto
<dependencies>
	<dependency>
	  <groupId>org.testng</groupId>
	  <artifactId>testng</artifactId>
	  <version>5.14.1</version>
	  <scope>test</scope>
	</dependency>
		<dependency>
		<groupId>org.seleniumhq.selenium</groupId>
		<artifactId>selenium</artifactId>
		<version>2.0b1</version>
	</dependency>
</dependencies>

Automaticamente o maven baixará todos as dependências e colocará no path do projeto.

  1. Criar uma classe para testar a configuração:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;


public class FirefoxDriverExample {
	   
	@Test
	public void testIt() {
	        // Create a new instance of the firefox driver
	        WebDriver driver = new FirefoxDriver();

	        // And now use this to visit Google
	        driver.get("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());
		
		driver.close();
	    }

}
  1. Rodar o teste usando o TestNG.

Attachments