473,567 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NUnitASP testing for asp:Login control

3 New Member
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.Extension s.Asp.HtmlTag+E lementNotVisibl eException : Couldn't find 'UserName' on ' '.

Thanks,
Heather
Dec 22 '06 #1
3 6384
HeatherBMI
3 New Member
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.Extension s.Asp.HtmlTag+E lementNotVisibl eException : Couldn't find 'UserName' on ' '.

Thanks,
Heather
Dec 28 '06 #2
wainwrightwt
1 New Member
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_UserNam e". 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_gw ppanLogin_Login 1_UserName").
Jul 11 '07 #3
roshworld
1 New Member
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 webassertionexc eption 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
3371
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: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="DefaultPage" %> .... <form id="LoginForm" method="post"...
2
4218
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, but it won't work for me. Here's what I did. 1. Created a new folder named "testlogin" 2. Turned that folder into an application using the IIS...
2
2450
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 forward, but it won't work for me. I've got a little better troubleshooting information for everyone now. First, here's how I set this stuff up... ...
0
1003
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 received error: Cannot assign value to 'System.Web.UI.WebControls.Login.Password -- it is
0
1289
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 control. From there I want to direct my users to diffrent pages depending on the role thier in. When I try to access the Context.User.IsInRole method...
1
1558
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 buttons that have the UseSubmitBehavior set to True. If I enter username and password, then hit RETURN, the page does not the login, but it seems...
3
4328
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 folder. The default.aspx sits in the root folder and just does a Response.Redirect to an ~/auth/home.aspx page. The config forces authentication,...
1
3391
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 paramsLogin = requestor..Split('\\'); txtUserName.Text = paramsLogin.ToString(); I'm wondering if there's an easy way to read the...
3
2078
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..
0
7688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7590
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7651
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5216
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3648
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3630
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.