Thursday, May 17, 2018

Page Factory in C# - Dealing with Frames and Latency

One of the issues we've been having with our new C# framework that utilizes PageFactory is that the pages did not automatically check to see if they were loaded with an IsLoaded() type method. We tried various schemes to alleviate this, but in the end after a lot of online searches I discovered that the PageFactory.InitElements() method can be overloaded in multiple ways:


This allowed us to implement the following InitElements() in our framework:

PageFactory.InitElements(DeviceMainTab, new RetryingElementLocator(Driver.SwitchToInnerFrames("main>tabPage"), AutomationConstants.DEFAULT_OBJECT_TIMEOUT));

The first argument is the object or class that is being initialized, the second parameter is another method that implements the RetryingElementLocator class. We gave it the Driver.SwitchToInnerFrames so that it would always switch to that frame set on that page in our application in order to find the defined elements.

The second parameter to RetryingElementLocator() is just a timeout, which we set to a constant that is 20 seconds.

This eliminated the majority of the latency and subsequent Element Not Found errors we were experiencing and was much simpler than trying to implement LoadableComponent pattern which we found did not work well with PageFactory.



No comments: