We have implemented the Selenium Grid (Distributed Test) Concept with our existing framework, while implemented its produce an Null Pointer Exception as of now i have an single package, with three class file (Baseclass, Loginclass, testcase)
Baseclass - getting my desired driver and navigate to application
class Baseclass {
public WebDriver myDriver;
public static String baseUrl;
// Explicit Constructors
public Baseclass() {
baseUrl = "https://example.com/";
}
public void Navigate(String url) {
String navigateToThisUrl = baseUrl + url;
myDriver.navigate().to(navigateToThisUrl);
}
public void GetDriver() throws MalformedURLException {
threadDriver = new ThreadLocal<RemoteWebDriver>();
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
FirefoxProfile fp = new FirefoxProfile();
desiredCapabilities.setCapability(FirefoxDriver.PROFILE, fp);
desiredCapabilities.setBrowserName(DesiredCapabilities.firefox()
.getBrowserName());
myDriver = new RemoteWebDriver(new URL(
"http://localhost:5555/wd/hub"), desiredCapabilities);
}
}
and in Loginclass navigate to the location (either QA or UAT etc.,)
public class Loginclass extends Baseclass {
public Loginclass navigateToLogin() {
Navigate("qa");
return new Loginclass();
}
}
Testcase we have an test case and executed the same
public class TestcaseSearch extends Loginclass {
@BeforeTest
public final void Startup() throws MalformedURLException {
Baseclass baseClass = new Baseclass();
baseClass.GetDriver;
}
@Test
public void fieldsSearch(String username, String password)
throws Exception {
Loginclass loginClass = new Loginclass();
navigateToLogin();
}
}
While Execute the above its produce an Null Pointer Exception
Baseclass: idsDriver.navigate().to(navigateToThisUrl);
Loginclass :Navigate("qa");
Let me know how can i rectify this
Exception output
java.lang.NullPointerException
at com.Baseclass.Navigate(Baseclass.java:11)
at com.Loginclass.Navigate(Loginclass.java:1)
at com.TestcaseSearch.Navigate(TestcaseSearch.java:1)
at com.Loginclass.navigateToLogin(Loginclass.java:4)
at com.TestcaseSearch.fieldsSearch(TestcaseSearch.java:11)