Use of added elements in Utility class

24 posts, 1 answers
  1. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 02 Jun 2015 Link to this post

    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

  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 03 Jun 2015 Link to this post

    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!
  3. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 04 Jun 2015 in reply to Cody Link to this post

    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

  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 04 Jun 2015 Link to this post

    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!
  5. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 05 Jun 2015 in reply to Cody Link to this post

    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

  6. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 05 Jun 2015 Link to this post

    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!
  7. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 09 Jun 2015 in reply to Cody Link to this post

    Cody,

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

    Thanks,

    Chandresh

  8. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 09 Jun 2015 Link to this post

    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!
  9. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 10 Jun 2015 in reply to Cody Link to this post

    Hi Cody,

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

    Thanks,

    Chandresh

  10. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 10 Jun 2015 in reply to Cody Link to this post

    Hi Cody,

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

    Thanks,

    Chandresh

  11. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 10 Jun 2015 Link to this post

    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!
  12. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 10 Jun 2015 in reply to Cody Link to this post

    Hi Cody,

    It's 160815.

    Thanks,

    Chandresh

  13. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 10 Jun 2015 Link to this post

    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!
  14. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 11 Jun 2015 in reply to Cody Link to this post

    Hi Cody,

    Oops! My mistake.Attached is the screenshot.

    Thanks,

    Chandresh

  15. Answer
    Cody
    Admin
    Cody avatar
    3360 posts

    Posted 11 Jun 2015 Link to this post

    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!
  16. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 11 Jun 2015 in reply to Cody Link to this post

    Hi Cody,

    Thank you. It works now. :)

    Thanks, 

    Chandresh

  17. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 12 Jun 2015 Link to this post

    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!
  18. Matthew
    Matthew avatar
    10 posts
    Member since:
    Oct 2015

    Posted 28 Sep Link to this post

    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?
  19. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 29 Sep in reply to Matthew Link to this post

    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

  20. Matthew
    Matthew avatar
    10 posts
    Member since:
    Oct 2015

    Posted 29 Sep in reply to Chandresh Link to this post

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

  21. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 30 Sep in reply to Matthew Link to this post

    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

  22. Matthew
    Matthew avatar
    10 posts
    Member since:
    Oct 2015

    Posted 30 Sep in reply to Chandresh Link to this post

    That worked like a charm!  Thank you so much Chandresh!
  23. Chandresh
    Chandresh avatar
    41 posts
    Member since:
    May 2015

    Posted 02 Oct in reply to Matthew Link to this post

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

    Thanks,

    Chandresh Parmar     

  24. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    251 posts

    Posted 03 Oct Link to this post

    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!
Back to Top