سؤال

For instance, let's say I have class FanPage, with this annotation

@FindBy(how = How.ID, using = "ctl00__lvph_Add")
private WebElement _AddFanButton;

and then in my test code I say

fanPage = homePage.GoToFanPage()

which does

return PageFactory.initElements(driver, CC_VendorStatisticsMetadata.class);

Now if my annotation is incorrect (let's say it should be ctl00_lvph_AddFan), I would expect my call to initElements to fail. However, it doesn't and it simply returns a FanPage object to me. It only fails if I try to use _AddFanButton.

How do I get PageFactory to look for my annotations from the start?

هل كانت مفيدة؟

المحلول

You don't. The PageFactory does lazy initialization, and that's how it's designed.

Consider a Page Object where certain of your elements don't exist on the page until some action is taken. Since Page Objects are intended to encapsulate business logic and not just the elements on the page, this is a perfectly logical scenario. In that case, your initElements() call would fail on page object initialization every single time, and not give you the chance to call the business logic method that would cause the element to appear.

It's possible that the PageFactory will not work for you if this is a requirement for your test framework. In that case, you'd do well to construct your own implementation.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top