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
You have two options:
- In the constructor for your utility class pass in the Manager object and save it as a class member.
- In your code use Manager.Current. This is a static function that always returns the currently active Manager object.
Regards,
Cody
Telerik
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
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
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
I am glad I could help.
Regards,
Cody
Telerik