You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by msalman <mo...@yahoo.com> on 2011/06/02 18:24:25 UTC

WicketTester and the rendered page

I am testing an application that starts with a login page.  After logging in
the user is taken to the home page.   


	@Test
	public void test()
	{
		
		QuickStartApplication app = new QuickStartApplication();
		
		
		Class clazz = app.getHomePage();
				
		WicketTester tester = new WicketTester(new QuickStartApplication());

     	WebPage loginPage = null;
		try 
		{
			loginPage = (WebPage) app.getHomePage().newInstance();
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		} 

		// Start out with the login Page
		
		tester.startPage(loginPage);		
		tester.assertRenderedPage(LoginPage.class);  	

		
   		tester.assertComponent("form:name", TextField.class);   		
   		tester.assertComponent("form:password", PasswordTextField.class);

		
   		
   		
   		// login form
		FormTester formTester = tester.newFormTester("form");
		
		formTester.setValue("name", "1");
		formTester.setValue("password", "1");

		// click button to login
		tester.executeAjaxEvent("form:submit", "onclick");		
		formTester.submit("submit");
		
		
		
		// Successfully logged in.  On the HomePage now		
		tester.assertRenderedPage(HomePage.class);  	

	
		
   		tester.assertComponent("form:text1", TextField.class);   		

		
		formTester = tester.newFormTester("form");
		
		formTester.setValue("text1", "1");
		

		// submit the home page form
		tester.executeAjaxEvent("form:submit", "onclick");		
		formTester.submit("submit");
		
		
		tester.assertRenderedPage(HomePage.class);
		// Fails here.  
		// junit.framework.AssertionFailedError: expected:<HomePage> but
was:<LoginPage>

		// Why is that?  It has already asserted earlier that it is the home
page..

	}


Am I doing this thing right?  Do I understand the Wicket tester right.  

I am attaching a quickstart project that includes the above test.

As always, I would appreciate any help.  

Thanks.


-Mohammad

http://apache-wicket.1842946.n4.nabble.com/file/n3568766/WicketTesterTest.zip
WicketTesterTest.zip 






--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WicketTester-and-the-rendered-page-tp3568766p3568766.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: WicketTester and the rendered page

Posted by Martin Grigorov <mg...@apache.org>.
See inline

On Thu, Jun 2, 2011 at 7:24 PM, msalman <mo...@yahoo.com> wrote:
> I am testing an application that starts with a login page.  After logging in
> the user is taken to the home page.
>
>
>        @Test
>        public void test()
>        {
>
>                QuickStartApplication app = new QuickStartApplication();
>
>
>                Class clazz = app.getHomePage();
>
>                WicketTester tester = new WicketTester(new QuickStartApplication());
>
>        WebPage loginPage = null;
>                try
>                {
>                        loginPage = (WebPage) app.getHomePage().newInstance();
>                }
>                catch (Exception e)
>                {
>                        e.printStackTrace();
>                }
>
>                // Start out with the login Page
>
>                tester.startPage(loginPage);
Replace above with: tester.startPage(tester.getApplication.getHomePage());
>                tester.assertRenderedPage(LoginPage.class);
>
>
>                tester.assertComponent("form:name", TextField.class);
>                tester.assertComponent("form:password", PasswordTextField.class);
>
>
>
>
>                // login form
>                FormTester formTester = tester.newFormTester("form");
>
>                formTester.setValue("name", "1");
>                formTester.setValue("password", "1");
>
>                // click button to login
>                tester.executeAjaxEvent("form:submit", "onclick");
>                formTester.submit("submit");
the second call here is not needed. you submit the form with AjaxButton
>
>
>
>                // Successfully logged in.  On the HomePage now
>                tester.assertRenderedPage(HomePage.class);
>
>
>
>                tester.assertComponent("form:text1", TextField.class);
>
>
>                formTester = tester.newFormTester("form");
>
>                formTester.setValue("text1", "1");
>
>
>                // submit the home page form
>                tester.executeAjaxEvent("form:submit", "onclick");
>                formTester.submit("submit");
the same as #2
>
>
>                tester.assertRenderedPage(HomePage.class);
>                // Fails here.
>                // junit.framework.AssertionFailedError: expected:<HomePage> but
> was:<LoginPage>
>
>                // Why is that?  It has already asserted earlier that it is the home
> page..
Put a breakpoint in your authorization code and see why it believes
that there is no logged in user.
>
>        }
>
>
> Am I doing this thing right?  Do I understand the Wicket tester right.
>
> I am attaching a quickstart project that includes the above test.
>
> As always, I would appreciate any help.
>
> Thanks.
>
>
> -Mohammad
>
> http://apache-wicket.1842946.n4.nabble.com/file/n3568766/WicketTesterTest.zip
> WicketTesterTest.zip
>
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/WicketTester-and-the-rendered-page-tp3568766p3568766.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: WicketTester and the rendered page

Posted by msalman <mo...@yahoo.com>.
Thanks for the quick response.

Well, I want it to stay at the Home Page.  How did it go back to loginPage??

Thanks again.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WicketTester-and-the-rendered-page-tp3568766p3568826.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: WicketTester and the rendered page

Posted by John Owen <jo...@globalscape.com>.
You submitted the HomePage form. Where do you expect the app to go from there?

-----Original Message-----
From: msalman [mailto:mohammad_salman@yahoo.com] 
Sent: Thursday, June 02, 2011 11:24 AM
To: users@wicket.apache.org
Subject: WicketTester and the rendered page

I am testing an application that starts with a login page.  After logging in
the user is taken to the home page.   


	@Test
	public void test()
	{
		
		QuickStartApplication app = new QuickStartApplication();
		
		
		Class clazz = app.getHomePage();
				
		WicketTester tester = new WicketTester(new QuickStartApplication());

     	WebPage loginPage = null;
		try 
		{
			loginPage = (WebPage) app.getHomePage().newInstance();
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		} 

		// Start out with the login Page
		
		tester.startPage(loginPage);		
		tester.assertRenderedPage(LoginPage.class);  	

		
   		tester.assertComponent("form:name", TextField.class);   		
   		tester.assertComponent("form:password", PasswordTextField.class);

		
   		
   		
   		// login form
		FormTester formTester = tester.newFormTester("form");
		
		formTester.setValue("name", "1");
		formTester.setValue("password", "1");

		// click button to login
		tester.executeAjaxEvent("form:submit", "onclick");		
		formTester.submit("submit");
		
		
		
		// Successfully logged in.  On the HomePage now		
		tester.assertRenderedPage(HomePage.class);  	

	
		
   		tester.assertComponent("form:text1", TextField.class);   		

		
		formTester = tester.newFormTester("form");
		
		formTester.setValue("text1", "1");
		

		// submit the home page form
		tester.executeAjaxEvent("form:submit", "onclick");		
		formTester.submit("submit");
		
		
		tester.assertRenderedPage(HomePage.class);
		// Fails here.  
		// junit.framework.AssertionFailedError: expected:<HomePage> but
was:<LoginPage>

		// Why is that?  It has already asserted earlier that it is the home
page..

	}


Am I doing this thing right?  Do I understand the Wicket tester right.  

I am attaching a quickstart project that includes the above test.

As always, I would appreciate any help.  

Thanks.


-Mohammad

http://apache-wicket.1842946.n4.nabble.com/file/n3568766/WicketTesterTest.zip
WicketTesterTest.zip 






--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WicketTester-and-the-rendered-page-tp3568766p3568766.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org