We have an existing UI automation framework in C# and based on knowledge at the time we used PageFactory to initialize the elements within the page files. Recently I've read more on the subject and there appears to be no real benefit to using PageFactory in C# so I'm attempting to re-write the pages using fields instead. One thing I'm having an issue with now those is getting my extended methods to work.
For example: In the current implementation I have an element identified like this: [FindsBy(How = How.LinkText, Using = "Authenticate")] private IWebElement BstHomePageHeader;
public IWebElement getBstHomePageHeader()
{
return BstHomePageHeader;
}
There is a helper method which checks if the element exists in certain cases and it's called like this from within a test:
home.getBstHomePageHeader().DoesElementExist().Should().BeTrue("User was not taken to the home page.");
The code within the "DoesElementExist" method has a 5 second wait applied, continually validating the element.Displayed check and it's ignoring the NoSuchElementException, ElementNotVisibleExpection and WebDriverTimeoutException. If the element is not returned within 5 seconds a false is returned to the main call and the fluent assertion message is thrown.
When I remove PageFactory the element is now created like below (in the same page file): public IWebElement getBstHomePageHeader => driver.FindElement(By.LinkText("Authenticate"));
If I try to apply the same helper method to it like below the DoesElementExist part of the line of code no longer applies. The NoSuchElementException is thrown directly in my page file and therefore the fluent assertion message isn't returned. home.getBstHomePageHeader.DoesElementExist().Should().BeTrue("User was not taken to the home page.");
Is it possible in a non-PageFactory design to not have the page class throw the NoSuchElementException so the test can handle the failure?