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

Calling Library functions from scripts demand passing Manager object

5 Answers 48 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
VVP
Top achievements
Rank 2
VVP asked on 11 Nov 2015, 11:15 AM

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

5 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 12 Nov 2015, 01:22 AM
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!
0
VVP
Top achievements
Rank 2
answered on 12 Nov 2015, 02:44 PM

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

0
Cody
Telerik team
answered on 12 Nov 2015, 08:39 PM
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!
0
VVP
Top achievements
Rank 2
answered on 13 Nov 2015, 06:22 AM

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

 

0
Cody
Telerik team
answered on 13 Nov 2015, 09:09 PM
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!
Tags
General Discussions
Asked by
VVP
Top achievements
Rank 2
Answers by
Cody
Telerik team
VVP
Top achievements
Rank 2
Share this question
or