Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:24:19+00:00 2026-06-08T01:24:19+00:00

I use Selenium Web Driver with JUnit in Eclipse. I want diminish my code

  • 0

I use Selenium Web Driver with JUnit in Eclipse. I want diminish my code by creating new classes for repitable steps. I want store this classes in separate files for convenience. For example this one of such classes:

import org.openqa.selenium.ie.InternetExplorerDriver;

 //Login
public class Login {
private InternetExplorerDriver driver;

String url;
String name;
String password;
String language;
public Login (String ur, String nam, String pass, String lang){
    url=ur;
    name=nam;
    password=pass;
    language=lang;
}
 public void log_in (){
 driver.get(url);
 driver.findElement(By.name("username")).sendKeys(name);    
 driver.findElement(By.name("password")).sendKeys(password);    
 driver.findElement(By.name("language")).sendKeys(language);    
 driver.findElement(By.name("logon_action")).click(); 
  }  
  }

This is my main test:

package bobsworld;

import init.Login;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;


public class WebTest {
private WebDriver driver;


@Test
public void testUnit() throws Exception {

//Open new window
System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
driver = new InternetExplorerDriver();

//Login 
init.Login login = new init.Login ("myurl", "log","pas","English");
  login.log_in();
}

The problem is with object driver. I get java.lang.NullPointerException and can’t execute test. How should I organize call to Login and code to make my test work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:24:21+00:00Added an answer on June 8, 2026 at 1:24 am

    What you try to achieve is a quite popular approach called “PageObjects”.

    Your issues:

    1. Use some checkstyle tool to improve code quality

    2. Do a whole lot of research about Java in general

    3. The Login Class or “init.Login” (it’s quite unusual to have a part of the package as prefix for the class) is not able to use the same WebDriver instance because you don’t forward it. Normally you would have opened a second WebDriver instance but that seems to be impossible though I don’t know your setup. You have to forward the “driver” as a parameter to the constructor of the Login class.

    4. Try to use real PageObjects as described here inluding PageFactory to improve readability and maintainability

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i use selenium web driver with junit in Eclipse. This is begining of my
We are using JUnit - Selenium for our web tests. We use Maven to
Do most people use there selenium (in my case selenium 2 with web driver)
I'm creating tests using Selenium 2 Web Driver with C#.Net. After reading through a
I have a written a Code in Selenium Web driver to test the health
I'm using Selenium WebDriver with Java. I want to use Safari browser. Does Selenium
When I use Selenium 2 code (Java) to open Firefox (or any other browser)
For integration testing I want to use selenium, also for my TDD/BDD workflow but
I am facing an issue in automating a web application using selenium web driver.
I use Selenium to test some web-product in my company. Product has button, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.