Hi,
I am creating Global function for Login which can be executed for different user types. I have added UserName & Password input field under required pages which I can see in Elements treeview. Now I am trying to use them in Utility class to input username & password and it is not working. I have added using ProjectName; and tried as per this article but my elements doesn't appear for page. It only shows three properties like Equals, ExpressionDefinitions and ReferenceEqual.
Can some one help me on this ?
Thanks,
Chandresh
23 Answers, 1 is accepted
Please share with us your code, your utility DLL, showing us how you're trying to implement this functionality along with how you're trying to exercise this functionality in the test. We will then be able to guide you on why the approach you are trying to take isn't working properly and how to fix it.
Regards,
Cody
Telerik
Cody,
Here is my code for a Login function in Utility Class.
//Project Name = DemoProject
public static void Login(String UserName,String Password)
{
Manager.Current.LaunchNewBrowser(BrowserType.InternetExplorer, true);
Browser IE = Manager.Current.ActiveBrowser;
IE.NavigateTo(Utility.URL, true);
IE.Actions.SetText(DemoProject.Pages.DemoSite0Page.UserNameText, UserName);
IE.Actions.SetText(DemoProject.Pages.DemoSite0Page.Password, Password);
DemoProject.Pages.DemoSite0Page.Login.Click(false);
}
I want to call this function for different users from different webtests.
Thanks,
Chandresh
Do you plan to call Login from a coded step of a Test Studio test (you did not explain exactly where and how you plan to call this function)? If true the browser will already be launched. You should pass in the browser as a parameter like this:
[CodedStep(@
"New Coded Step"
)]
public
void
Scratch_HTML_Test_CodedStep1()
{
Login(ActiveBrowser,
"username"
,
"password"
);
}
public
static
void
Login(Browser ActiveBrowser, String UserName, String Password)
{
ActiveBrowser.NavigateTo(Utility.URL,
true
);
ActiveBrowser.Actions.SetText(DemoProject.Pages.DemoSite0Page.UserNameText, UserName);
ActiveBrowser.Actions.SetText(DemoProject.Pages.DemoSite0Page.Password, Password);
DemoProject.Pages.DemoSite0Page.Login.Click(
false
);
}
Regards,
Cody
Telerik
Cody,
Yes, I need to call Login function from coded step in more than one webtests. I tried your code but it didn't work.
Here is the error I am getting.
An object reference is required for the non-static field, method, or property 'DemoProject.Pages.DemoSite0Page.UserNameText.get'
Thanks,
Chandresh
That particular error message means that Test Studio was unable to find the target element. Maybe the browser is on the wrong page, or there's a dynamically changing ID causing the problem, or soemthing similar. What is the find expression for DemoProject.Pages.DemoSite0Page.UserNameText? Also please let the test fail then go to Step Failure Details, find and click Export then attach the generated .zip file. It contains valuable information we need to diagnose this type of failure.
Regards,
Cody
Telerik
Cody,
PFA is the details related to failure and Find expression for UserNeme text.
Thanks,
Chandresh
I'm sorry but I cannot fix compile errors based on screen shots and the compile log alone. I must have the entire test project so I can review ALL of the code at once to determine what is the root cause so I can fix it. Please put your test project into a .zip file and attach the .zip file. If the .zip file is larger than 20MB let me know and I'll provide an alternate location to upload it to. Also, since this is a public forum, if you're concerned about security (and rightly so) I encourage you to create your own support ticket (which are private and confidential) and attach your test project to the support ticket.
Regards,
Cody
Telerik
Hi Cody,
I have created a support ticket for this. Hope it can fix my problem.
Thanks,
Chandresh
Hi Cody,
I have created a support ticket for this. Hope it can fix my problem.
Thanks,
Chandresh
I am looking for your support ticket, but I'm not finding it. Can you send me the ticket number that I can look up?
Regards,
Cody
Telerik
Hi Cody,
It's 160815.
Thanks,
Chandresh
I'm afraid ticket 160815 can't be right. That ticket was created many years ago, on 09-Sep-2008 about "Modal Window IE Problem - Gray Screen On Close". Would you share with me a screen shot where you got this ticket number from?
Regards,
Cody
Telerik
Hi Cody,
Oops! My mistake.Attached is the screenshot.
Thanks,
Chandresh
Thank you your screen shot really helped. I found the problem report you filed and fixed your sample project that was attached. The fixed version is attached to your problem report.
Regards,
Cody
Telerik
Hi Cody,
Thank you. It works now. :)
Thanks,
Chandresh
Excellent! Thank you for the update.
Regards,
Cody
Telerik
Hi Matthew,
You are receiving error because there is no reference to the element in Utility Class. Kindly add below code to at the start in your Utility Class and try again.
#region [ Dynamic Pages Reference ]
private
static
Pages _pages;
/// <summary>
/// Gets the Pages object that has references
/// to all the elements, frames or regions
/// in this project.
/// </summary>
public
static
Pages Pages
{
get
{
_pages =
new
Pages(Manager.Current);
return
_pages;
}
}
#endregion
Let me know if you still get same error.
Thanks,
Cahndresh Parmar
Thanks Chandresh,
I tried this, but still seem to be getting the same error. My simplified utility class to test this can be seen below. If I attempt to call this from a coded step via Utils.test(); I see the following error:
c:\workspace\acs_web\ACS\common.cs(50,13) : error CS0120: An object reference is required for the non-static field, method, or property 'ArtOfTest.WebAii.Core.Manager.Desktop.get'
c:\workspace\acs_web\ACS\common.cs(51,13) : error CS0120: An object reference is required for the non-static field, method, or property 'ArtOfTest.WebAii.Core.Manager.Desktop.get'
using Telerik.TestingFramework.Controls.KendoUI;
using Telerik.WebAii.Controls.Html;
using Telerik.WebAii.Controls.Xaml;
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using ArtOfTest.Common.UnitTesting;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using ArtOfTest.WebAii.Design;
using ArtOfTest.WebAii.Design.Execution;
using ArtOfTest.WebAii.ObjectModel;
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.Silverlight.UI;
namespace AaaS
{
public static class Utils
{
#region [ Dynamic Pages Reference ]
private static Pages _pages;
/// <
summary
>
/// Gets the Pages object that has references
/// to all the elements, frames or regions
/// in this project.
/// </
summary
>
public static Pages Pages
{
get
{
_pages = new Pages(Manager.Current);
return _pages;
}
}
#endregion
public static void test()
{
Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.E);
Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter);
}
}
}
Hi Matthew,
Thanks for sharing the sample code. It helped in understanding the problem. The problem is Manager is not available directly in your static class so you'll need to pass browser object reference to access it. Here is the updated code which should solve your problem.
using
Telerik.TestingFramework.Controls.KendoUI;
using
Telerik.WebAii.Controls.Html;
using
Telerik.WebAii.Controls.Xaml;
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Linq;
using
ArtOfTest.Common.UnitTesting;
using
ArtOfTest.WebAii.Core;
using
ArtOfTest.WebAii.Controls.HtmlControls;
using
ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using
ArtOfTest.WebAii.Design;
using
ArtOfTest.WebAii.Design.Execution;
using
ArtOfTest.WebAii.ObjectModel;
using
ArtOfTest.WebAii.Silverlight;
using
ArtOfTest.WebAii.Silverlight.UI;
namespace
AaaS
{
public
static
class
Utils
{
#region [ Dynamic Pages Reference ]
private
static
Pages _pages;
/// <summary>
/// Gets the Pages object that has references
/// to all the elements, frames or regions
/// in this project.
/// </summary>
public
static
Pages Pages
{
get
{
_pages =
new
Pages(Manager.Current);
return
_pages;
}
}
#endregion
public
static
void
test(Browser _ActiveBrowser)
{
_ActiveBrowser.Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.E);
_ActiveBrowser.Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter);
}
}
}
In your test from where you are calling this function pass the current ActiveBrowser object like below.
Utils.test(ActiveBrowser);
Let me know if you still face any issue.
Thanks,
Chandresh Parmar
Great Matthew! Let me know if you need any other help.
Thanks,
Chandresh Parmar
@ Matthew: I am glad to hear you figured out how to proceed. Please feel free to contact Test Studio Support Team in case of any further queries.
@ Chandresh: Thanks a lot for you involvement. We appreciate your help on the topic!
Regards,
Elena Tsvetkova
Telerik by Progress