473,379 Members | 1,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

NUnitASP testing for asp:Login control

I've been searching for a way to test this control with my NUnitASP tests for awhile now and have yet to come up with anything. I have all of my tests written, but until I can get past the initial login page, all my tests fail.

Here is some of the login page code:

Expand|Select|Wrap|Line Numbers
  1. <asp:Login ID="Login1" runat="server" Height="134px" 
  2.         OnAuthenticate="Login1_Authenticate" 
  3.         OnLoginError="OnLoginError" Width="336px" CreateUserText="Create a new account" CreateUserUrl="CreateUser.aspx" DestinationPageUrl="~/Main.aspx" MembershipProvider="SqlProvider" PasswordRecoveryText="Retrieve Password" PasswordRecoveryUrl="PasswordRecovery.aspx">
  4.         </asp:Login>
On my NUnit tests, this is the code I have written so far...

Expand|Select|Wrap|Line Numbers
  1. Browser.GetPage(MyPageURL);
  2. // This is where I need to know the control tester for my login control
  3. // in order to use it instead of CurrentWebForm for the following
  4. TextBoxTester user = new TextBoxTester("UserName", CurrentWebForm);
  5. TextBoxTester password = new TextBoxTester("Password", CurrentWebForm);
  6. ButtonTester logon = new ButtonTester("LoginButton", CurrentWebForm);
  7.  
  8. user.Text = "validusername";
  9. password.Text = "validpassword";
  10. logon.Click();
I put a writeline into my unit test right after the getpage call and it was returning the correct page, but the error message given when I run the unit test is:
NUnit.Extensions.Asp.HtmlTag+ElementNotVisibleExce ption : Couldn't find 'UserName' on ' '.

Thanks,
Heather
Dec 22 '06 #1
3 6375
For future reference if someone else runs into this problem, here was the hack solution I came up with:

In the web.config file for my main program, I commented out the line
Expand|Select|Wrap|Line Numbers
  1. <deny users="?"/>
just for the duration of when I want to run my unit tests. This way, when I want to release from my localhost to my server, I can just take out the comments and everything still has the security that I needed for the main page.

Also, on all of my URLs for the Browser.GetPage() calls, I made sure to set them to read to my http://localhost:port#/....aspx instead of calling to the main server.

After doing that, all of the unit tests passed. This probably isn't the best solution to the problem, but it does give you a single point of control when you want to run your unit tests, just make sure to comment out the deny users line in the config file, but don't forget to take out the commenting before releasing it back to the server!

--This was simply the solution I came up with, and I posted it here should anyone else arrive at the same problem and look for a solution--

Heather

I've been searching for a way to test this control with my NUnitASP tests for awhile now and have yet to come up with anything. I have all of my tests written, but until I can get past the initial login page, all my tests fail.

Here is some of the login page code:

Expand|Select|Wrap|Line Numbers
  1. <asp:Login ID="Login1" runat="server" Height="134px" 
  2.         OnAuthenticate="Login1_Authenticate" 
  3.         OnLoginError="OnLoginError" Width="336px" CreateUserText="Create a new account" CreateUserUrl="CreateUser.aspx" DestinationPageUrl="~/Main.aspx" MembershipProvider="SqlProvider" PasswordRecoveryText="Retrieve Password" PasswordRecoveryUrl="PasswordRecovery.aspx">
  4.         </asp:Login>
On my NUnit tests, this is the code I have written so far...

Expand|Select|Wrap|Line Numbers
  1. Browser.GetPage(MyPageURL);
  2. // This is where I need to know the control tester for my login control
  3. // in order to use it instead of CurrentWebForm for the following
  4. TextBoxTester user = new TextBoxTester("UserName", CurrentWebForm);
  5. TextBoxTester password = new TextBoxTester("Password", CurrentWebForm);
  6. ButtonTester logon = new ButtonTester("LoginButton", CurrentWebForm);
  7.  
  8. user.Text = "validusername";
  9. password.Text = "validpassword";
  10. logon.Click();
I put a writeline into my unit test right after the getpage call and it was returning the correct page, but the error message given when I run the unit test is:
NUnit.Extensions.Asp.HtmlTag+ElementNotVisibleExce ption : Couldn't find 'UserName' on ' '.

Thanks,
Heather
Dec 28 '06 #2
Not sure if anybody will see this, but here is a better solution...

The problem is that NUnitAsp "Tester" objects look for a control by it's HtmlID. And ASP builds control IDs by appending all parent container names with an '_'. So, the ASP.NET Login control has the following controls:

UserName
Password
LoginButton

But, the login control itself is called "Login1". So, the UserName control's htmlid would be "Login1_UserName". If you have a masterpage, webpart, or anything else, you will also need to append those names. Here is a sample of the code I am using to test one of my login controls:

Expand|Select|Wrap|Line Numbers
  1. Browser.GetPage(AppPath + "Default.aspx"); //AppPath previously defined
  2. UserControlTester master = new UserControlTester("ctl00", CurrentWebForm); // master page
  3. UserControlTester webPart = new UserControlTester("wpMgr", master); // web part manager
  4. UserControlTester panel = new UserControlTester("gwppanLogin", webPart); // web part container
  5. UserControlTester login = new UserControlTester("Login1", panel); // Login control
  6. TextBoxTester txtUserName = new TextBoxTester("UserName", login);
  7. TextBoxTester txtPassword = new TextBoxTester("Password", login);
  8. ButtonTester btnLogin = new ButtonTester("LoginButton", login);
  9.  
  10. AssertVisibility(txtUserName, true);
  11. AssertVisibility(txtPassword, true);
  12. AssertVisibility(btnLogin, true);
  13.  
  14. txtUserName.Text = "username";
  15. txtPassword.Text = "password";
  16. btnLogin.Click();
Alternatively, you can pull up the source code, and find the full id of the control you want to grab. (ex. "ctl00_wpMgr_gwppanLogin_Login1_UserName").
Jul 11 '07 #3
Hi, there everyone. Currently I have just started working on NUnit ASP. For the past two weeks I have been working on it.

The problem I am facing now is with the visibility of the controls in NUnit.

When I tried to run the test case for validator testing, i was getting an webassertionexception where unexpectedly not visible error was coming out for all the asp controls i used. I found out that all the controls were nested in ASP:Content . Can you suggest me the way to include asp:content in unit testing in NUnit.
Oct 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: R.A.M. | last post by:
I have a problem with logging in implementation in ASP.NET 2.0. I decided to use asp:Login control (which is enough), but I cannot find solution for handling logging in. I have an .aspx: <%@...
2
by: Sasquatch | last post by:
I'm having trouble creating a simple login page using the asp:login control. I followed some instructions in a WROX book, "Beginning ASP.NET 2.0," and the instructions are very straight forward,...
2
by: Sasquatch | last post by:
I'm still having trouble creating a simple login page using the asp:login control. I followed some instructions in a WROX book, "Beginning ASP.NET 2.0," and the instructions are very straight...
0
by: R.A.M. | last post by:
Hello, I have created asp:Login control on default.aspx page. In Page_Load() I wanted to initialize login name and password: LoginControl.UserName = ...; LoginControl.Password = ...; but I...
0
by: Maxus | last post by:
Hi People, I have written a custom membership and custom roles classes for my application. Then added a asp:Login control to the page. I then hooked into the LoggedIn method of the asp:login...
1
by: Formentz | last post by:
Hi guys, I have a problem that should be quite simple, but I can't figure out: I have an asp:Login control on the web form, but in the same form there are, before the login control, other...
3
by: =?Utf-8?B?RHVrZSAoQU4yNDcp?= | last post by:
The majority of pages on our site need authentication (forms auth against the aspnetdb database). I created an '~/auth' folder with its own config file forcing authentication for any pages in the...
1
by: i_robot73 | last post by:
I've got a login control that pre-populates the username using: TextBox txtUserName = (TextBox)Login1.FindControl("UserName"); string requestor = WindowsIdentity.GetCurrent().Name; string...
3
by: zaifi | last post by:
i am working on asp.net project.but i want use asp login control with oracle database.e.g when i login match user id and password with oracle database. .please give me explain..
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.