PlanetJava
Custom Search

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

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

Subject: Re: Selenium instance is NULL and 2nd class says java.lang.NullPointerException
Date: Tue, 10 Aug 2010 13:15:49 -0700 (PDT)
here is the error message i am getting -
[TestRunner]
com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Home_Page.Verify_Login_Page_Title()
[TestRunner]       on instances
[TestRunner]
null(com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Home_Page)
[TestRunner]
com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Home_Page.Verify_Walmart_Page_Title()
[TestRunner]       on instances
[TestRunner]
null(com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Home_Page)
[TestRunner]
com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Home_Page.Verify_Walmart_Page_Title1()
[TestRunner]       on instances
[TestRunner]
null(com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Home_Page)
[TestRunner]
com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Login_Page.Verify_Login_Page_Title()
[TestRunner]       on instances
[TestRunner]
null(com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Login_Page)
[TestRunner] ===
[Invoker 19712349] Invoking
com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Home_Page.Verify_Login_Page_Title
Inside method  - Verify_Login_Page_Title
java.lang.NullPointerException
        at
com.walmart.test.SelNG.mobilewalmart.tests.Walmart_Home_Page.Verify_Login_Page_Title(Walmart_Home_Page.java:
20)
        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)
On Aug 10, 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 {
>         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);
>         selenium = new DefaultSelenium("localhost", Integer.parseInt(port),
>                                 browser, "http://mobile-vqa3.walmart.com/";);
>         System.out.println("Starting Selenium Server: - " +selenium);
>          seleniumServer.start();
>          System.out.println("Started Selenium Server: - " );
>          selenium.start();
>          //selenium.setTimeout("600000");
>          selenium.setSpeed("1200");
>          selenium.open("http://mobile-vqa3.walmart.com/";);
>          selenium.windowMaximize();
>          System.out.println("selenium value from StartSelenium method"
> +selenium);
>
> }
>
> @AfterTest(groups = { "abstract" })
> public void stopSeleniumServer(){
>         selenium.close();
>     selenium.stop();
>     seleniumServer.stop();
>         }
>
> }
>
> Class 1: -
>
> package com.walmart.test.SelNG.mobilewalmart.tests;
>
> import static org.testng.Assert.assertTrue;
> import static org.testng.Assert.fail;
> import java.lang.Object.*;
> import java.io.*;
> import org.testng.annotations.*;
> import com.thoughtworks.selenium.CommandProcessor;
> import com.thoughtworks.selenium.DefaultSelenium;
> import com.thoughtworks.selenium.HttpCommandProcessor;
> import com.thoughtworks.selenium.Selenium;
>
> public class Walmart_Home_Page extends CommonTest{
>
> @Test(groups = {"abstract"}, description = "Verify Before Home Page
> login")
> public void Verify_Login_Page_Title(){
>         try {
>                 System.out.println("Inside method  - Verify_Login_Page_Title 
> ");
>                 String Walmart_title = selenium.getTitle();
>                 System.out.println("Title of the page: " +Walmart_title);
>                 //assertTrue(selenium.getTitle().equals("Please Log in!"));
>                 if (selenium.getTitle().equals("Please Log in!")){
>                         System.out.println("Title of the page: - inside if 
> statement "
> +Walmart_title);
>                         selenium.type("username", "wm12");
>                         selenium.type("password", "mobile");
>                         selenium.click("//input[@value='Log In']");
>                         selenium.waitForPageToLoad("60000");
>                         System.out.println("Levaing Method 
> -Verify_Login_Page_Title " );
>                 }
>         }catch(Throwable t){
>                 t.printStackTrace(System.out);
>                 fail();
>         }
>
> }
>
> @Test(groups = {"abstract"}, description = "Verify Walmart Home Page")
> public void Verify_Walmart_Page_Title(){
>         System.out.println("Inside method Verify_Walmart_Page_Title ");
>         String Walmart_title = selenium.getTitle();
>         System.out.println("Title of the page: " +Walmart_title);
>
>         //assertTrue(selenium.getTitle().equals("Please Log in!"));
>         if (selenium.getTitle().equals("Walmart Mobile")){
>                 System.out.println("Title of the page: - 
> Verify_Walmart_Page_Title
> inside if statement " +Walmart_title);
>         }
>         System.out.println("Levaing Method - Verify_Walmart_Page_Title " );
>
> }
> }
>
> Class 3: -
>
> package com.walmart.test.SelNG.mobilewalmart.tests;
>
> import org.testng.annotations.Test;
> import com.thoughtworks.selenium.CommandProcessor;
> import com.thoughtworks.selenium.DefaultSelenium;
> import com.thoughtworks.selenium.HttpCommandProcessor;
> import com.thoughtworks.selenium.Selenium;
> import junit.framework.TestSuite;
>
> public class Walmart_Login_Page extends CommonTest{
>     Selenium selenium;
>
> @Test(groups = {"abstract"}, description = "Verify Login Page for
> Walmart Services")
> public void Verify_Login_Page_Title(){
>
>                 System.out.println("Selenium Value from from other Class: "
> +selenium);
>                 System.out.println("Inside method Verify_LoginPageTite ****");
>                 //System.out.println("Title of the page: value of dummy int"
> +session.get());
>                 System.out.println("Title of the page: from home page"
> +selenium.getTitle());
>                 System.out.println("Inside method Verify_LoginPageTite End of
> Automation Script");
>
>                 /*selenium.click("//div[6]/div/div");
>                 selenium.type("email", 
> "mi...-H6WVrsWKVVnQFizaE/[email protected]");
>                 selenium.type("pwd", "herodevice");
>                 selenium.click("id2");
>                 verifyTrue(selenium.isTextPresent("The e-mail address and 
> password
> you entered does not match what we have in our records. Please make
> sure that you have correctly entered the e-mail address and password
> associated with your account at walmart.com."));
>             */
>         }
>
> }
>
> At the start of the Class 3 - Verify_Login_Page_Title I am getting the
> java null pointer exception
>
> Can somebody please help me with this and let me know why this is
> happeneing?
>
> Thanks in Advance
>
> Amar
-- 
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