Creation of Window object in every test methods

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Creation of Window object in every test methods

Krithi
Hi Tarun,

I have a question when we create multiple test cases in a class file. In our last session, We have created a method testRegistrationNew() which takes value from data provider, input the values and checks the Account creation page. Suppose If i want to add another test to verify some other functionality in the Registration page ( Eg. not entering some value and check the error page is displayed instead of account creation page), should I initialize the Registration object again ( ie) In that method I have to initialize with Registration registration = new Registration(driver);?

I tried by using this initialization in the constructor of the class, but it says the null pointer exception. My idea is to initialize it once and I can use that object for multiple verification. Similiar to any java program.

Thanks
Krithi
Reply | Threaded
Open this post in threaded view
|

Re: Creation of Window object in every test methods

softwaretestingforum
Administrator
Could you please post code sample of what you have tried? It helps me in debugging the failure and help you better.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Creation of Window object in every test methods

Krithi
Hi Tarun,

Please refer the attached files.


My Test class. PageObjectExample.java
It has the test method "testRegistrationNew" which takes the value from the data provider class. We have created the object Registration object. Suppose If I have another test scenario in the same Homepage, with different sets of data provider ( Eg. Some fields blank), the verification should be checking the error page. I need to write a separate test method for this verification. For this , do I need to create a new Registration object as defined in the first verify method?

I tried to initialize the Registration object in the constructor of PageObject, which can be used across multiple test methods as we do in normal java programs. Am I not allowed to do that ?

Let me know If I am not clear in my question or need any other .java files for your reference.

Thanks
Krithi
Reply | Threaded
Open this post in threaded view
|

Re: Creation of Window object in every test methods

softwaretestingforum
Administrator
I think you have pasted the example of previous session, is not it?
Where is the method which gets you null pointer exception?
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Creation of Window object in every test methods

Krithi
Hi Tarun,

I pasted the corrected code. Here it is.

PageObjectExample.java
MercuryTestCase.java
Registration.java

Thanks
Krithi
Reply | Threaded
Open this post in threaded view
|

Re: Creation of Window object in every test methods

softwaretestingforum
Administrator
I suppose your null pointer exception is this -

@Test(groups ="group1")
public void testPageObject()
{
		//Registration registration = new Registration(driver);
		registration.registerNewUser();
		assert driver.findElement(By.tagName("body")).getText().contains("Thank you for registering. You may now sign-in using the user name and password you've just entered.");
}

Now when you have not initialized the registration object, you are bound to get null pointer exception
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Creation of Window object in every test methods

Krithi
Hi Tarun,

I agree. But When I created this object in constructor of PageObjectExample, that object is visible to all the methods defined in the class. When I run the test method, this constructor should have called and we have the Registration object initialized in the constructor.

This was my assumption. Please let me know If I am wrong.

Thanks
Krithi
Reply | Threaded
Open this post in threaded view
|

Re: Creation of Window object in every test methods

softwaretestingforum
Administrator
Because you did not instantiate PageObjectExample constructor. Do you see my point?
I yet find it unconvincing to instantiate page object this way.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Creation of Window object in every test methods

Krithi
Yes. I understand the point. Sorry for the late response. 


Thanks 
Krithi


Sent from my Mobile


On Oct 17, 2012, at 9:59, "tarunkumar [via Manual and Automated Testing]" <[hidden email]> wrote:

Because you did not instantiate PageObjectExample constructor. Do you see my point?
I yet find it unconvincing to instantiate page object this way.

No Automated Testing




To unsubscribe from Creation of Window object in every test methods, click here.
NAML