PlanetJava
Custom Search

java-testng-user
[Top] [All Lists]

Re: Selenium instance is NULL and 2nd class says java.lang.NullPointerEx

Subject: Re: Selenium instance is NULL and 2nd class says java.lang.NullPointerException
Date: Wed, 11 Aug 2010 10:15:04 -0700 (PDT)
Thanks John. Even after taking the Selenium selenium from the other
class it was giving me error.
I debugged  & the issue was that for Each class it was creating a new
selenium instance. So 1st class would run properly but the 2nd class
would have 2 instance's (1st & 2 class) so it was taking the null
instance that it created.
I resolved this by doing static Selenium selenium;
so now it reuses the selenium instance for other classes.
I dont know if its the correct approach but its working :)
Cheers,
Amar
On Aug 10, 6:16Âpm, JohnMc 
<j.mcguinn...-bzGI/[email protected]> wrote:
> Hi Amar,
>
> Try removing the "Selenium selenium" declaration in "public class
> Walmart_Login_Page" it is stopping the class from seeing the same
> variable in the super class "CommonTest". And it does not seem to be
> getting initialized in the Walmart_Login_Page class.
>
> On Aug 11, 9:27Âam, aktestng <[email protected]> 
> wrote:
>
> > I removed the 3rd class and ran, it works fine
>
> > I removed the selenium.getTitle() from the 3rd class and it works fine
>
> > The only problem comes when I start to use the selenium handle.
>
> > Here how I have defined in the setup class -
>
> > public class CommonTest extends SeleneseTestCase {
>
> > Â Â Â Â public static final int waitTimeInSeconds = 50;
> > Â Â Â Â Selenium selenium;
> > Â Â public static final String MAX_WAIT_TIME_IN_MS="60000";
> > Â Â private SeleniumServer seleniumServer;
> > Â Â public int amar=12;
>
> > @Parameters({"selenium.host","selenium.port","selenium.browser","__POOLNAME__"})
> > @BeforeTest(groups = { "abstract"})
> > public void startSeleniumServer(String host, String port, String
> > browser , String
> > _POOLNAME__ ) throws Exception {
>
> > Â Â Â Â System.out.println("Starting Selenium Server Method:");
> > Â Â Â Â RemoteControlConfiguration rc = new RemoteControlConfiguration();
> > Â Â Â Â rc.setAvoidProxy(true);
> > Â Â Â Â rc.setPort(4444);
> > Â Â Â Â rc.setTrustAllSSLCertificates(true);
> > Â Â Â Â rc.setSingleWindow(false);
> > Â Â Â Â rc.setReuseBrowserSessions(true);
> > Â Â Â Â seleniumServer = new SeleniumServer(rc);
> > Â Â seleniumServer.start();
> > Â Â Â Â selenium = new DefaultSelenium("localhost", Integer.parseInt(port),
> > browser, "http://mobile-vqa3.walmart.com/";);
> > Â Â Â Â selenium.start();
> > Â Â Â Â selenium.open("http://mobile-vqa3.walmart.com/";);
> > Â Â Â Â selenium.setSpeed("1200");
> > Â Â Â Â selenium.windowMaximize();
> > Â Â Â Â System.out.println("selenium value from StartSelenium method"
> > +selenium);
>
> > }
>
> > thats it. works with one class and not with the other class. as soon
> > as i make a reference to selenium it throws a null exception.
>
> > Weired
>
> > Please advise
>
> > Thanks,
> > Amar
>
> > On Aug 10, 3:38Âpm, CÃdric Beust â 
> > <[email protected]> wrote:
>
> > > On Tue, Aug 10, 2010 at 3:32 PM, aktestng 
> > > <[email protected]> wrote:
> > > > The exception is thrown at the start of the 3 class.
>
> > > I understand that but what exactly is null?
>
> > > --
> > > CÃdric
>
> > > > 15:28:12.027 INFO - Got result: OK,false on session
> > > > 6be499a0a0da476394827edee1c667c3
> > > > Leveaing Method - Dummy method Verify_Walmart_Page_Title
> > > > [Invoker 26440236] Invoking
>
> > > > com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Login_Page_Test.Verify_Login_Page_Title
> > > > Inside method Â- Verify_Walmart_Login_Page_Test - Other Class
> > > > java.lang.NullPointerException
> > > > Â Â Â Âat
>
> > > > com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Login_Page_Test.Verify_Login_Page_Title(Walmart_Login_Page_Test.java:
> > > > 21)
> > > > Â Â Â Â 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 
> > > > org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:
> > > > 640)
> > > > Â Â Â Âat org.testng.internal.Invoker.invokeMethod(Invoker.java:627)
> > > > Â Â Â Âat org.testng.internal.Invoker.invokeTestMethod(Invoker.java:798)
> > > > Â Â Â Âat 
> > > > org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1102)
> > > > Â Â Â Âat
>
> > > > org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:
> > > > 137)
> > > > Â Â Â Âat 
> > > > org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:
> > > > 121)
> > > > Â Â Â Âat org.testng.TestRunner.runWorkers(TestRunner.java:1010)
> > > > Â Â Â Âat org.testng.TestRunner.privateRun(TestRunner.java:684)
> > > > Â Â Â Âat org.testng.TestRunner.run(TestRunner.java:554)
> > > > Â Â Â Âat org.testng.SuiteRunner.runTest(SuiteRunner.java:311)
> > > > Â Â Â Âat org.testng.SuiteRunner.runSequentially(SuiteRunner.java:306)
> > > > Â Â Â Âat org.testng.SuiteRunner.privateRun(SuiteRunner.java:268)
> > > > Â Â Â Âat org.testng.SuiteRunner.run(SuiteRunner.java:217)
> > > > Â Â Â Âat org.testng.TestNG.runSuite(TestNG.java:1062)
> > > > Â Â Â Âat org.testng.TestNG.runSuitesLocally(TestNG.java:956)
> > > > Â Â Â Âat org.testng.TestNG.run(TestNG.java:874)
> > > > Â Â Â Âat org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:75)
> > > > Â Â Â Âat org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:127)
>
> > > > is there a way to get the current selenium handle and start working
> > > > with it?
>
> > > > Thanks
>
> > > > On Aug 10, 2:04 pm, CÃdric Beust â 
> > > > <[email protected]> wrote:
> > > > > I'm not seeing anything immediately wrong. You are correctly putting 
> > > > > all
> > > > > your tests in the same <test> tag, which guarantees that whatever code
> > > > you
> > > > > run in @BeforeTest should have initialized anything you need there.
>
> > > > > Where exactly is the NPE happening? Are you sure that this variable is
> > > > > initialized in @BeforeTest and not elsewhere?
>
> > > > > Also, any reason to suspect that groups might be causing some of your
> > > > code
> > > > > not to be executed?
>
> > > > > --
> > > > > CÃdric
>
> > > > > On Tue, Aug 10, 2010 at 1:45 PM, aktestng 
> > > > > <[email protected]> wrote:
> > > > > > no problem. Can you please help see what I am doing wrong? thanks
>
> > > > > > On Aug 10, 1:42 pm, CÃdric Beust â <[email protected]> wrote:
> > > > > > > Ok then you're using @BeforeTest correctly (I can never tell right
> > > > away
> > > > > > but
> > > > > > > it's a common error so that's usually my first suggestion).
>
> > > > > > > --
> > > > > > > CÃdric
>
> > > > > > > On Tue, Aug 10, 2010 at 1:27 PM, aktestng 
> > > > > > > <[email protected]> wrote:
> > > > > > > > Hi Cedric,
>
> > > > > > > > Â ÂThanks for the reply. I want the execution just like you 
> > > > > > > > explain
> > > > > > > > in this thread:
>
> > > >http://groups.google.com/group/testng-users/browse_thread/thread/ec29.
> > > > > > ..
>
> > > > > > > > <test>
> > > > > > > > Â<classes>
> > > > > > > > Â Â<class name="A" /> Â<-- contains tests a1() and a2()
> > > > > > > > Â Â<class name="B" /> Â <-- contains tests b1() and b2()
> > > > > > > > Â</classes>
> > > > > > > > </test>
>
> > > > > > > > In this case, you will see:
>
> > > > > > > > @BeforeTest
> > > > > > > > Â@BeforeMethod
> > > > > > > > Â Âa1()
> > > > > > > > Â@AfterMethod
> > > > > > > > Â@BeforeMethod
> > > > > > > > Â Âa2()
> > > > > > > > Â@AfterMethod
> > > > > > > > Â@BeforeMethod
> > > > > > > > Â Âb1()
> > > > > > > > Â@AfterMethod
> > > > > > > > Â@BeforeMethod
> > > > > > > > Â Âb22()
> > > > > > > > Â@AfterMethod
> > > > > > > > @AfterTest
>
> > > > > > > > I tried to use the beforeMethod but then its giving me this 
> > > > > > > > error:
>
> > > > > > > > Failed to invoke @Configuration method
>
> > > > com.walmart.test.SelNG.mobilewalmart.tests.CommonTest.startSeleniumServer:Selenium
> > > > > > > > is already running on port 4444. Or some other service is.
> > > > > > > > 13:21:43.126 WARN - Failed to start: 
> > > > > > > > [email protected]:4444for
> > > > > > > > the 3 class
>
> > > > > > > > I want the setup method to start the selenium server only once 
> > > > > > > > and
> > > > > > > > then create the selenium only once.
>
> > > > > > > > All subsequent classes should use the same server started in
> > > > > > > > setupclass and same selenium handle
>
> > > > > > > > Please Help
>
> > > > > > > > Thanks,
> > > > > > > > Amar
>
> > > > > > > > On Aug 10, 1:15 pm, CÃdric Beust â <[email protected]> wrote:
> > > > > > > > > You probably want to use @BeforeMethod and not @BeforeTest.
>
> > > > > > > > > --
> > > > > > > > > CÃdric
>
> > > > > > > > > On Tue, Aug 10, 2010 at 1:12 PM, aktestng <[email protected]>
> > > > wrote:
> > > > > > > > > > I have 3 classes in my test. 1 is the setup class. other 2 
> > > > > > > > > > are
> > > > 2
> > > > > > > > > > features for my website and each have n methods.
>
> > > > > > > > > > When I run the first class it runs correctly using the 
> > > > > > > > > > selenium
> > > > var
> > > > > > > > > > but the 2nd complains that there is no instance.
>
> > > > > > > > > > Setup Class code:
>
> > > > > > > > > > package com.walmart.test.SelNG.mobilewalmart.tests;
>
> > > > > > > > > > import org.testng.annotations.*;
> > > > > > > > > > import com.thoughtworks.selenium.CommandProcessor;
> > > > > > > > > > import com.thoughtworks.selenium.DefaultSelenium;
> > > > > > > > > > import com.thoughtworks.selenium.HttpCommandProcessor;
> > > > > > > > > > import com.thoughtworks.selenium.Selenium;
> > > > > > > > > > import java.io.File;
> > > > > > > > > > import com.thoughtworks.selenium.*;
> > > > > > > > > > import org.openqa.selenium.server.SeleniumServer;
> > > > > > > > > > import 
> > > > > > > > > > org.openqa.selenium.server.RemoteControlConfiguration;
> > > > > > > > > > import org.testng.annotations.*;
>
> > > > > > > > > > /**
> > > > > > > > > > Â* @author : Amar Kale
> > > > > > > > > > Â*/
>
> > > > > > > > > > public class CommonTest extends SeleneseTestCase {
>
> > > > > > > > > > Â Â Â Âpublic static final int waitTimeInSeconds = 50;
> > > > > > > > > > Â Âpublic Selenium selenium;
>
> > > > > > > > > > Â Âpublic static final String MAX_WAIT_TIME_IN_MS="60000";
> > > > > > > > > > Â Âprivate SeleniumServer seleniumServer;
> > > > > > > > > > Â Âpublic int amar=12;
>
> > > > @Parameters({"selenium.host","selenium.port","selenium.browser","__POOLNAME__"})
> > > > > > > > > > @BeforeTest(groups = { "abstract"})
> > > > > > > > > > public void startSeleniumServer(String host, String port,
> > > > String
> > > > > > > > > > browser , String
> > > > > > > > > > _POOLNAME__ ) throws Exception {
> > > > > > > > > > Â Â Â
>
> ...
>
> read more Â
-- 
You received this message because you are subscribed to the Google Groups 
"testng-users" group.
To post to this group, send email to 
testng-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/testng-users?hl=en.
msgmiddle
<Prev in Thread] Current Thread [Next in Thread>
Current Sitemap | © 2012 planetjava | Contact | Privacy Policy