Null in Baseurl - Selenium IDE - Junit

Asked

Viewed 42 times

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)

1 answer

0

Downloaded the driver, configured?

Ai can use, Example with the Chrome

public WebDriver getChromeDriver()
{
    LOG.info("getChromeDriver");
    System.setProperty("webdriver.chrome.driver", "E:\\drivers\\chromedriver.exe");
    final WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(8, TimeUnit.SECONDS);
    return driver;
}
  • I just lowered the jars.

  • need to download the application, Linux or Windows , or map what you have correctly on your machine

Browser other questions tagged

You are not signed in. Login or sign up in order to post.