0
Good afternoon.
I am trying to use Selenium IDE Webdriver and noticed that Baseurl is coming null. I saw some examples on the internet, but I can’t understand why this is happening. You don’t even open Firefox. Thank you all.
import static org.junit.Assert.*;
import Static org.testng.Assert.assertEquals; import Static org.testng.Assert.fail;
import java.util.Concurrent.Timeunit;
import org.junit.Test; import org.openqa.Selenium.Alert; import org.openqa.Selenium.By; import org.openqa.Selenium.Noalertpresentexception; import org.openqa.Selenium.Nosuchelementexception; import org.openqa.Selenium.Webdriver; import org.openqa.Selenium.firefox.Firefoxdriver; import org.testng.Annotations.Afterclass; import org.testng.Annotations.Beforeclass;
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 testE1() throws Exception {
System.out.println("BaseURL:" + baseUrl);
driver.get(baseUrl + "/SomarParcelas/");
driver.findElement(By.name("p1")).clear();
driver.findElement(By.name("p1")).sendKeys("12");
driver.findElement(By.name("p2")).clear();
driver.findElement(By.name("p2")).sendKeys("21");
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;
}
}
}
Stacktrace
java.lang.NullPointerException
at TestePaginaSoma.testE1(TestePaginaSoma.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
I just lowered the jars.
– Fernando
need to download the application, Linux or Windows , or map what you have correctly on your machine
– Marcelo Ferreira