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

  • Home
  • SEARCH
  • 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 674159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:40:30+00:00 2026-05-14T00:40:30+00:00

I want to group the common methods in one file and use it. For

  • 0

I want to group the common methods in one file and use it. For example, login to a page using selenium may be used in multiple times. Define that in class A and call it in class B. However, it throws null pointer exception.

class A has

public void test_Login() throws Exception
    {
        try{
        selenium.setTimeout("60000");
        selenium.open("http://localhost");
        selenium.windowFocus();
        selenium.windowMaximize();
        selenium.windowFocus();
        selenium.type("userName", "admin");
        selenium.type("password", "admin");
        Result=selenium.isElementPresent("//input[@type='image']");
        selenium.click("//input[@type='image']");
        selenium.waitForPageToLoad(Timeout);
        }
        catch(Exception ex)
        {   
            System.out.println(ex);
            ex.printStackTrace();
        }
    }

with all other java syntax

in class B

public void test_kk() throws Exception
    {

        try
        {
            a.test_Login();
        }
        catch(Exception ex)
        {
            System.out.println(ex);
            ex.printStackTrace();
        }
    }

with all syntax.

When I execute class B, I got this error,

java.lang.NullPointerException
        at A.test_Login(A.java:32)
        at B.test_kk(savefile.java:58)
        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 junit.framework.TestCase.runTest(TestCase.java:168)
        at junit.framework.TestCase.runBare(TestCase.java:134)
        at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.j
ava:212)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:124)
        at junit.framework.TestSuite.runTest(TestSuite.java:232)
        at junit.framework.TestSuite.run(TestSuite.java:227)
        at junit.textui.TestRunner.doRun(TestRunner.java:116)
        at junit.textui.TestRunner.doRun(TestRunner.java:109)
        at junit.textui.TestRunner.run(TestRunner.java:77)
        at B.main(B.java:77)

I hope someone must have tried this before. I may miss something here.

  • 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-05-14T00:40:31+00:00Added an answer on May 14, 2026 at 12:40 am

    The way we do it is, we have helper classes with static methods on them. In the actual test cases we set up our selenium object and pass the object into the static method so it can operate on it.

    public BaseHelper
    {
        public static login( final String username, final String password, final DefaultSelenium selenium )
        {
         selenium.type("userName", username);
         selenium.type("password", password);
         selenium.click("loginbutton");
        }
    }
    
    
    public LoginTest
    {
        DefaultSelenium selenium;
    
        onSetup()
        {
          selenium = new DefaultSelenium(...);
        }  
    
        public testLogin()
        {
          BaseHelper.login( "admin", "admin", selenium);
          // assert that this passed
          BaseHelper.login( "foo", "bar", selenium);
          // assert this failed because no user 'foo'
          BaseHelper.login( "admin", "bar", selenium);
          // assert this failed because admin's password was incorrect
        }
    }
    

    Hope this illustrates the point.

    Besides the better readability and easier maintenance, you are also able to test multiuser behavior by creating two (or more) selenium objects and pass those around in the tests.

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

Sidebar

Related Questions

How can I using group by with union in T-SQL? I want to group
I want to use an existing user and user group table that the forums
I want to define some common post-construction behavior for a group of classes. When
I want to group results of query by the item id and count number
I want to group by on dict key >>> x [{'a': 10, 'b': 90},
I am trying to create a conversations based messaging system. I want to group
I have some data that has various attributes and I want to hierarchically group
I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
I want only a (faculty) group of users to be able to access a
I want to insert a group box in the form and put in 3

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.