How to Use Predefined Elements in a Utility Class

I would like to use elements previously defined in the Elements repository in my stand alone class file.

Solution

In general it is not recommended to work with predefined elements in a standalone class file. If there is a specific scenario that can not be avoided at certain development stage of the project the following example could shade some light on such approach. References to ArtOfTest.WebAii.Core and ArtOfTest.WebAii.Design has to be set. The Utility class has to inherit from BaseWebAiiTest and to has a 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();
        }
    }
}
Imports ArtOfTest.WebAii.Core
Imports ArtOfTest.WebAii.Design

Namespace SomeTestProject
    Public Class Utility
        Inherits BaseWebAiiTest
        #Region "[ Dynamic Pages Reference ]"

        Private _pages As Pages

        Public ReadOnly Property Pages() As Pages
            Get
                If _pages Is Nothing Then
                    _pages = New Pages(Manager.Current)
                End If
                Return _pages
            End Get
        End Property
        #End Region

        Public Sub DoSomething()
            Pages.Bing.SbFormQSearch.Text = "Cat"
            Pages.Bing.SbFormGoSubmit.Click()
        End Sub
    End Class
End Namespace

In a test script coded step an instance of this class has to be created in order to call its methods as shown below:

// create an instance of the class
var MyClass = new Utility();
// call a method of this class
MyClass.DoSomething();

Dim [MyClass] = New Utility()

[MyClass].DoSomething()