This is a migrated thread and some comments may be shown as answers.

Use of added elements in Utility class

23 Answers 114 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chandresh
Top achievements
Rank 1
Chandresh asked on 02 Jun 2015, 09:35 AM

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

Sort by
0
Cody
Telerik team
answered on 03 Jun 2015, 10:50 PM
Hi Chandresh,

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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Chandresh
Top achievements
Rank 1
answered on 04 Jun 2015, 05:34 AM

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

0
Cody
Telerik team
answered on 04 Jun 2015, 04:36 PM
Hi 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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Chandresh
Top achievements
Rank 1
answered on 05 Jun 2015, 09:06 AM

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

0
Cody
Telerik team
answered on 05 Jun 2015, 08:09 PM
Hello 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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Chandresh
Top achievements
Rank 1
answered on 09 Jun 2015, 05:28 AM

Cody,

PFA is the details related to failure and Find expression for UserNeme text.

Thanks,

Chandresh

0
Cody
Telerik team
answered on 09 Jun 2015, 02:36 PM
Hi 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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Chandresh
Top achievements
Rank 1
answered on 10 Jun 2015, 09:39 AM

Hi Cody,

I have created a support ticket for this. Hope it can fix my problem.

Thanks,

Chandresh

0
Chandresh
Top achievements
Rank 1
answered on 10 Jun 2015, 09:40 AM

Hi Cody,

I have created a support ticket for this. Hope it can fix my problem.

Thanks,

Chandresh

0
Cody
Telerik team
answered on 10 Jun 2015, 01:28 PM
Hi 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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Chandresh
Top achievements
Rank 1
answered on 10 Jun 2015, 01:45 PM

Hi Cody,

It's 160815.

Thanks,

Chandresh

0
Cody
Telerik team
answered on 10 Jun 2015, 01:55 PM
Hello 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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Chandresh
Top achievements
Rank 1
answered on 11 Jun 2015, 06:55 AM

Hi Cody,

Oops! My mistake.Attached is the screenshot.

Thanks,

Chandresh

0
Accepted
Cody
Telerik team
answered on 11 Jun 2015, 03:38 PM
Hi 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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Chandresh
Top achievements
Rank 1
answered on 12 Jun 2015, 03:47 AM

Hi Cody,

Thank you. It works now. :)

Thanks, 

Chandresh

0
Cody
Telerik team
answered on 12 Jun 2015, 07:12 PM
Hello,

Excellent! Thank you for the update.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Matthew
Top achievements
Rank 1
answered on 28 Sep 2016, 07:40 PM
I'm trying to do something similar in a shared utility class and I'm running into the same error.  I'm not sure how to properly define an object of Type Manager in a coded file that is separate from a Test.  Can you please share what was done to resolve this error?
0
Chandresh
Top achievements
Rank 1
answered on 29 Sep 2016, 06:24 AM

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

0
Matthew
Top achievements
Rank 1
answered on 29 Sep 2016, 09:20 PM

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); 
        }
    }
}

0
Chandresh
Top achievements
Rank 1
answered on 30 Sep 2016, 08:00 AM

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

0
Matthew
Top achievements
Rank 1
answered on 30 Sep 2016, 07:57 PM
That worked like a charm!  Thank you so much Chandresh!
0
Chandresh
Top achievements
Rank 1
answered on 03 Oct 2016, 04:35 AM

Great Matthew! Let me know if you need any other help.

Thanks,

Chandresh Parmar     

0
Elena
Telerik team
answered on 03 Oct 2016, 03:22 PM
Hi,

@ 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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Chandresh
Top achievements
Rank 1
Answers by
Cody
Telerik team
Chandresh
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Elena
Telerik team
Share this question
or