My test suite is organized into two parts: a library of test data, xpath locations for WebElements, .click()
commands, etc. I also have a test suite.
This is an example test that shares the package it deals with for experimentation purposes. As of right this second I'm not worried about outputting results (I know how to do that), the code simply needs to work.
package LoginPage;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.openqa.selenium.*;
public class FunctionCheck {
private WebDriver driver;
private String baseUrl;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.XXXXXXXXXXX.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws Exception {
driver.get(baseUrl + "XXXXXXXXXXXX");
Thread.sleep(600);
LoginPage.enterValidCredentials myins = new LoginPage.enterValidCredentials();
myins.run();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
This is the class "enterValidCredentials" that sits in the same package.
package LoginPage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class enterValidCredentials { // This class enters in a valid username and valid password on the login page.
public void run() {
WebDriver driver;
driver.findElement(By.cssSelector("input[type=\"text\"]")).sendKeys("XXXXXX");
driver.findElement(By.cssSelector("input[type=\"password\"]")).sendKeys("XXXXXX");
}
}
I got two problems:
- In the class "enterValidCredentials", it wants me to "initialize" the driver variable. The autofix for this in Eclipse sets line 8 to
WebDriver driver = null;
. - Doing the above has my test throw a
NullPointerException
.
I've been searching through documentation for a while now. I'm really stumped as to what is going on. All I want is the run()
method to literally run, and plug in the info to the page. That's the goal.