Calling Library functions from scripts demand passing Manager object

6 posts, 0 answers
  1. VVP
    VVP avatar
    26 posts
    Member since:
    Sep 2015

    Posted 11 Nov 2015 Link to this post

    Hi,

    We are creating a library and Scripts layer for our project

    We observed that from scripts, if we want to call library functions we need to pass Manager object as well.Else scripts fail.

    Is there any way where we can call functions with parameters only.

    eg 
    In scripts 

    objCommonLib.Login(username,password,Manager) ;

    In library
    public bool Login( string username,string password,Manager Manager)
    {

    Logic here..
    }​

    In scripts created instance like  objCommonLib = new CommonActions(this);

    I tried creating  constructor for library like below. 

            BaseWebAiiTest activeTest;

        public CommonActions(BaseWebAiiTest callingTest)
            {
                 activeTest = callingTest;
            }

     

    Kindly let me know. Our main objective is to have layered approach.

     Thanks,

    VVP

  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 11 Nov 2015 Link to this post

    Hi Vishnu,

    You have two options:
    1. In the constructor for your utility class pass in the Manager object and save it as a class member.
    2. In your code use Manager.Current. This is a static function that always returns the currently active Manager object.


    Regards,
    Cody
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  3. VVP
    VVP avatar
    26 posts
    Member since:
    Sep 2015

    Posted 12 Nov 2015 in reply to Cody Link to this post

    Hi Cody,

    Thanks for suggestion.

    I tried using Manager.Current (2nd option ) and was able to execute the test. Thanks for that.

    But i didn't get the first suggestion.

    1) I passed Manager object as a  parameter ​in library function constructor.How can i assign to a Class member. I tried creating an object of Manager class and assigned the parameter. But was getting "object refernce not set to instance " error.​

     Please let me know.

     

    Thanks,

    VVP

  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 12 Nov 2015 Link to this post

    Hi Vishnu,

    Create yourself a class libaray similar to this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ArtOfTest.WebAii;
    using ArtOfTest.WebAii.Core;
     
    namespace ClassLibrary1
    {
        public class Class1
        {
            public Manager MyManager { get; set; }
     
            public Class1(Manager mgr)
            {
                MyManager = mgr;
            }
     
            public void method1(string param1)
            {
                MyManager.LaunchNewBrowser();
            }
        }
    }


    Then use it in your tests like this:

    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;
    using Telerik.TestingFramework.Controls.KendoUI;
    using Telerik.WebAii.Controls.Html;
    using Telerik.WebAii.Controls.Xaml;
    using ClassLibrary1;
     
     
    namespace TestStudioProject1
    {
        public class WebTest1 : BaseWebAiiTest
        {
            #region [ Dynamic Pages Reference ]
     
            private Pages _pages;
     
            /// <summary>
            /// Gets the Pages object that has references
            /// to all the elements, frames or regions
            /// in this project.
            /// </summary>
            public Pages Pages
            {
                get
                {
                    if (_pages == null)
                    {
                        _pages = new Pages(Manager.Current);
                    }
                    return _pages;
                }
            }
     
            #endregion
     
            public Class1 utility;
     
            public override void OnBeforeTestStarted()
            {
                utility = new Class1(this.Manager);
            }
     
            [CodedStep(@"New Coded Step")]
            public void WebTest1_CodedStep()
            {
                Log.WriteLine(this.ExecutionContext.DeploymentDirectory);
            }
        }
    }


    Regards,
    Cody
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  5. VVP
    VVP avatar
    26 posts
    Member since:
    Sep 2015

    Posted 13 Nov 2015 in reply to Cody Link to this post

    Hi Cody,

     I had tried similar method only.

    I copied your code into a separate project and it worked perfectly.

    So i think it is some problem with my project. I am happy with "Manager.Current" object and will be using that.  

    Thanks for the support once again.

     

    Thanks,

    VVP

     

  6. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 13 Nov 2015 Link to this post

    Hi,

    I am glad I could help.

    Regards,
    Cody
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top