Olá boa noite!
Pessoal, estou tendo problema com o código de teste criado na Selenium IDE, quando este é exportado para o Java. Antes de criar o projeto eu adiciono todos os jars do Selenium e mesmo assim não consigo rodar o teste usando o netbeans. Observação; a IDE do Selenium e os testes rodados firefox funcionam corretamente.
Ocorre um erro no alwayRun:
cannot find symbol
symbol: method alwaysRun()
Além de um erro na referencia verificationErrorString:
reference to fail is ambiguous both method fail(String) in org.junit.Assert and method fail(String) in org.testng.Assert match
Segue abaixo o código:
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class TestePaginaSoma {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://localhost:8080/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testEPaginaSoma() throws Exception {
driver.get(baseUrl + "/SomarParcelas/index.html");
driver.findElement(By.name("p1")).clear();
driver.findElement(By.name("p1")).sendKeys("");
driver.findElement(By.name("p1")).clear();
driver.findElement(By.name("p1")).sendKeys("21");
driver.findElement(By.name("p2")).clear();
driver.findElement(By.name("p2")).sendKeys("12");
driver.findElement(By.name("calcular")).click();
assertEquals(driver.findElement(By.cssSelector("h1")).getText(), "O resultado foi 33");
}
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}