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: - <asp:Login ID="Login1" runat="server" Height="134px"
-
OnAuthenticate="Login1_Authenticate"
-
OnLoginError="OnLoginError" Width="336px" CreateUserText="Create a new account" CreateUserUrl="CreateUser.aspx" DestinationPageUrl="~/Main.aspx" MembershipProvider="SqlProvider" PasswordRecoveryText="Retrieve Password" PasswordRecoveryUrl="PasswordRecovery.aspx">
-
</asp:Login>
On my NUnit tests, this is the code I have written so far... - Browser.GetPage(MyPageURL);
-
// This is where I need to know the control tester for my login control
-
// in order to use it instead of CurrentWebForm for the following
-
TextBoxTester user = new TextBoxTester("UserName", CurrentWebForm);
-
TextBoxTester password = new TextBoxTester("Password", CurrentWebForm);
-
ButtonTester logon = new ButtonTester("LoginButton", CurrentWebForm);
-
-
user.Text = "validusername";
-
password.Text = "validpassword";
-
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
3 6387
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
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: - <asp:Login ID="Login1" runat="server" Height="134px"
-
OnAuthenticate="Login1_Authenticate"
-
OnLoginError="OnLoginError" Width="336px" CreateUserText="Create a new account" CreateUserUrl="CreateUser.aspx" DestinationPageUrl="~/Main.aspx" MembershipProvider="SqlProvider" PasswordRecoveryText="Retrieve Password" PasswordRecoveryUrl="PasswordRecovery.aspx">
-
</asp:Login>
On my NUnit tests, this is the code I have written so far... - Browser.GetPage(MyPageURL);
-
// This is where I need to know the control tester for my login control
-
// in order to use it instead of CurrentWebForm for the following
-
TextBoxTester user = new TextBoxTester("UserName", CurrentWebForm);
-
TextBoxTester password = new TextBoxTester("Password", CurrentWebForm);
-
ButtonTester logon = new ButtonTester("LoginButton", CurrentWebForm);
-
-
user.Text = "validusername";
-
password.Text = "validpassword";
-
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
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: - Browser.GetPage(AppPath + "Default.aspx"); //AppPath previously defined
-
UserControlTester master = new UserControlTester("ctl00", CurrentWebForm); // master page
-
UserControlTester webPart = new UserControlTester("wpMgr", master); // web part manager
-
UserControlTester panel = new UserControlTester("gwppanLogin", webPart); // web part container
-
UserControlTester login = new UserControlTester("Login1", panel); // Login control
-
TextBoxTester txtUserName = new TextBoxTester("UserName", login);
-
TextBoxTester txtPassword = new TextBoxTester("Password", login);
-
ButtonTester btnLogin = new ButtonTester("LoginButton", login);
-
-
AssertVisibility(txtUserName, true);
-
AssertVisibility(txtPassword, true);
-
AssertVisibility(btnLogin, true);
-
-
txtUserName.Text = "username";
-
txtPassword.Text = "password";
-
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").
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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" action="Menu.aspx"
style="vertical-align: middle;" runat="server">
|
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 properties
3. Created two new web form pages, /testlogin/default.aspx and
/testlogin/login.aspx...
|
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...
1. Created a new folder named "testlogin"
2. Turned that folder into an application using the...
|
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
|
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 the whole thing
is empty including the actual user itself (Although I appear to be
authenticated)....
| |
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 that one of the other UseSubmitBehavior button fired.
|
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, which is
carried out by ~/pub/login.aspx which has a standard asp:login control.
I set up the...
|
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
'attributeMapUsername' setting (if there is one) from the web.config.
|
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..
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |