New to Telerik Test Studio? Download free 30-day trial

How to Use Elements From Repository In A Utility Class

I would like to use elements recorded in the Elements repository in my standalone code class file.

Solution

We do not recommend using elements from the repository in a standalone class file. If there is a specific scenario you could not avoid you could refer to the example below. You would need to add references to ArtOfTest.WebAii.Core.dll and ArtOfTest.WebAii.Design.dll and include using statements for these in the code file. The Utility class inherits the BaseWebAiiTest and requires definition for region [Dynamic Pages Reference].

using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.Design;

namespace SomeTestProject
{
    public class Utility : BaseWebAiiTest 
    {
        #region [ Dynamic Pages Reference ]

        private Pages _pages;

        public Pages Pages
        {
            get
            {
                if (_pages == null)
                {
                    _pages = new Pages(Manager.Current);
                }
                return _pages;
            }
        }
        #endregion

        public void DoSomething()
        {
            Pages.Bing.SbFormQSearch.Text = "Cat" ;
            Pages.Bing.SbFormGoSubmit.Click();
        }
    }
}

In a coded step you would need to create an instance of this class in order to use its methods as shown below:

// create an instance of the class
var MyClass = new Utility();

// call a method of this class
MyClass.DoSomething();
In this article