| 1 | = 10 Minutos com Maven, TestNG e Selenium = |
| 2 | |
| 3 | 1. Criar um novo projeto Maven no Eclipse: |
| 4 | |
| 5 | maven1.png |
| 6 | |
| 7 | maven2.png |
| 8 | |
| 9 | maven3.png |
| 10 | |
| 11 | 2. Editar pom.xml para adicionar as dependencias do projeto logo abaixo da tag <name> do projeto |
| 12 | |
| 13 | {{{ |
| 14 | <dependencies> |
| 15 | <dependency> |
| 16 | <groupId>org.testng</groupId> |
| 17 | <artifactId>testng</artifactId> |
| 18 | <version>5.14.1</version> |
| 19 | <scope>test</scope> |
| 20 | </dependency> |
| 21 | <dependency> |
| 22 | <groupId>org.seleniumhq.selenium</groupId> |
| 23 | <artifactId>selenium</artifactId> |
| 24 | <version>2.0b1</version> |
| 25 | </dependency> |
| 26 | </dependencies> |
| 27 | }}} |
| 28 | |
| 29 | Automaticamente o maven baixará todos as dependências e colocará no path do projeto. |
| 30 | |
| 31 | 3. Criar uma classe para testar a configuração: |
| 32 | |
| 33 | {{{ |
| 34 | import org.openqa.selenium.By; |
| 35 | import org.openqa.selenium.WebDriver; |
| 36 | import org.openqa.selenium.WebElement; |
| 37 | import org.openqa.selenium.firefox.FirefoxDriver; |
| 38 | import org.testng.annotations.Test; |
| 39 | |
| 40 | |
| 41 | public class FirefoxDriverExample { |
| 42 | |
| 43 | @Test |
| 44 | public void testIt() { |
| 45 | // Create a new instance of the firefox driver |
| 46 | WebDriver driver = new FirefoxDriver(); |
| 47 | |
| 48 | // And now use this to visit Google |
| 49 | driver.get("http://www.google.com"); |
| 50 | |
| 51 | // Find the text input element by its name |
| 52 | WebElement element = driver.findElement(By.name("q")); |
| 53 | |
| 54 | // Enter something to search for |
| 55 | element.sendKeys("Cheese!"); |
| 56 | |
| 57 | // Now submit the form. WebDriver will find the form for us from the element |
| 58 | element.submit(); |
| 59 | |
| 60 | // Check the title of the page |
| 61 | System.out.println("Page title is: " + driver.getTitle()); |
| 62 | |
| 63 | driver.close(); |
| 64 | } |
| 65 | |
| 66 | } |
| 67 | }}} |
| 68 | |
| 69 | 4. Rodar o teste usando o TestNG. |