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:45:27 -0700 (PDT)
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]:4444 for
> > 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 {
> > > > Â Â Â Â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...-H6WVrsWKVVlWk0Htik3J/[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
> > > > testng-users+unsubscribe-/[email protected]<testng-users%[email protected]>
> > <testng-users%2Bunsubscribe-/[email protected]<testng-users%252Bunsubscribe-/[email protected]>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/testng-users?hl=en.
>
> > > --
> > > CÃdric
>
> > --
> > 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
> > testng-users+unsubscribe-/[email protected]<testng-users%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/testng-users?hl=en.
>
> --
> CÃdric
-- 
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