Extend the Adapter Class

Class library usage, coding and language questions.
macgowan
Posts: 14
Joined: Mon Jun 23, 2014 9:20 pm

Extend the Adapter Class

Post by macgowan » Fri Sep 19, 2014 11:05 pm

Hi ...

We are wondering if this might be a good case to extend the Adapter Class. We have developed a method called waitForVisible() that is called each time we execute an operations (i.e. Click(), DoubleClick() ...) that will open a new window.

We've been thinkin' - maybe we should add this functionality into the Adapter Class.

What do you think?

Here is a sample use case for the waitForVisible()

Code: Select all

Report.Info("Open the LibraryReference in the Trademark Editor"); 
repo.JSA.Features.LibraryReference.LibraryReferenceArtifact.DoubleClick();

if (!SummaryHelper.waitForVisible(repo.JSA.LibraryReference.X, 
                                 WAIT_FOR_VISIBLE_TIMEOUT_MS, 
                                 "LibraryReference Editor didn't open"))
{ 
    Report.Failure("LibraryReference Editor didn't open");
}
else
{ 
    repo.JSA.LibraryReference.SaveAndCloseButton.Click();
}                

Now - if we extended the Adapter Class - we could add the waitForVisible() functionality into the Click() method.

Code: Select all

public class AdapterExt : Adapter
{

    private string[] requiredCapabilities; 

    public AdapterExt()
    {
        requiredCapabilities = new string[] {}; 
    }

    protected override string[] RequiredCapabilities
    {
        get { return requiredCapabilities; } 
        // set { requiredCapabilities = value; }
    }

    // This method will extent the Click() method that is found in the 
    // Adapter class
    public void Click()
    {

        Click(); 

        // Add some extended functionality here
    }

}

One question would be how to implement the new AdapterExt Class with the RanorexPath ???

Would I need to do something like this t to initialize the AdapterExt ??

Looking at the code below how sure how to implement AdapterExt ??

Code: Select all

    // Create Text adapter from RanoreXPath  
    Text textBox = "/form[@controlname='TestedApp']/text[@controlname='label3']";  
    // Set text value of text box  
    textBox.TextValue = "12";  
      
    // Check on of the 'General' properties  
    if (textBox.Enabled)  
      Report.Info("Text is enabled");  

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Extend the Adapter Class

Post by Support Team » Thu Sep 25, 2014 7:33 am

Hello macgowan,

In order to wait for a specific element to become visible I would suggest following approach.
  • • Adapt the RxPath of your element as shown below:
    • o Add “Visible” property to the RxPath

      Code: Select all

      element[@title='title' and @visible='True']
    • Add a new “WaitForExists” method to your recording
    WaitForExists.png
    WaitForExists.png (31.77 KiB) Viewed 1492 times
This allows you to wait for an element to become visible.

If you want to use your own “CheckVisiblity” method in combination with the “Click” method, which is provided from the adapter class I would suggest using “Extension Methods” .

I have created a sample solution which illustrates a possible implementation of the previously mentioned functionality.

Please note that this solution is just for illustrating purposes. We do neither support this solution, nor are we able to guarantee for any side-effects.
Attachments
ExtendedAdapterSolution.zip
(146.96 KiB) Downloaded 188 times
.
Image