Reusing same browser - Getting Error (sessionId should not be null )

699 views
Skip to first unread message

Mohammed Sikander

unread,
Jul 2, 2010, 8:59:56 AM7/2/10
to seleniu...@googlegroups.com
I am using NetBeans with JAVA and JUnit.

I am trying to run test cases from different classes. Following are my two classes. In first class class1 i have defined oDefaultSelenium, which will launch browser, and logins to my site.
In the class2 i want to continue with the same browser, by using the same object oDefaultSelenium. But by doing this i am getting the following error message.
"Exception: sessionId should not be null; has this session been started yet?"

public class class1 extends SeleneseTestCase{
  
    DefaultSelenium oDefaultSelenium = new DefaultSelenium(sServerHost, iServerPort, sBrowserType,sBaseUrl);

         public void setUp() throws Exception {
         oDefaultSelenium.start();          
         oDefaultSelenium.setSpeed("5000");
         }

public boolean Login(){
            setUp
            oDefaultSelenium.open("testsite.com");
         }
}

public class class2 extends class1{
       
    public void verifyAdminTabLinks(){
      
        oDefaultSelenium.click(link1);
        oDefaultSelenium.waitForPageToLoad("30000");
         }

Is there any simple workaround for this?

Thanks,
Sikander

 

Aniket Deshpande

unread,
Jul 2, 2010, 9:24:11 AM7/2/10
to seleniu...@googlegroups.com
Try creating a constructor and passing the selenium object through the constructor to the other class...

Keep me posted..


- ANIKET


 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Mohammed Sikander

unread,
Jul 6, 2010, 6:58:31 AM7/6/10
to seleniu...@googlegroups.com
Tried, but got following error message - java.lang.NullPointerException

Please use the below code and explain.

Thanks,
Sikander

Raja sankar

unread,
Jul 6, 2010, 9:38:23 PM7/6/10
to seleniu...@googlegroups.com
Null pointer exception means selenium instance is not created. 

Check this thread for the answer

Mohammed Sikander

unread,
Jul 7, 2010, 1:44:05 AM7/7/10
to seleniu...@googlegroups.com
Thanks everyone who helped me getting this solved.
Those who are facing same kind of problem, please find the solution below.

Step1: Create ClassA:

package SmokeTest;
import com.thoughtworks.selenium.*;

public class ClassA extends SeleneseTestCase {

    public ClassA(Selenium selenium) {
        super.selenium = selenium;
    }

    public void test_Login() throws Exception
    {
        try{
        selenium.setTimeout("60000");
        selenium.open("codesearch");
    }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        }
}

Step2: Create ClassB

package SmokeTest;

import com.thoughtworks.selenium.*;

public class ClassB extends SeleneseTestCase {
    ClassA a;

    public void setUp() throws Exception
    {
        setUp("http://google.com", "*iexplore");
        a = new ClassA(super.selenium);
    }
    public void test_01 throws Exception
    {
        try
        {
            a.test_Login();
        }
        catch(Exception ex)
        {
            System.out.println(ex);
            ex.printStackTrace();
        }
    }
}

Step3: Execute these test cases.

package SmokeTest;

import com.thoughtworks.selenium.*;
import junit.framework.*;
import java.io.*;
import junit.textui.TestRunner;

public class CRLogin extends SeleneseTestCase {

    public static Test suiteToRun(){
           TestSuite suite = new TestSuite();
           suite.addTestSuite(ClassA.class);
           return suite;
   }

    public static void main(String[] args) {
        TestRunner.run(suiteToRun());
    }
}

Cheers,
Sikander
Reply all
Reply to author
Forward
0 new messages