vikramvi / AppiumSerenityPOC

POC showing native android app automation with Appium & Serenity BDD framework
https://www.linkedin.com/pulse/managing-automation-projects-efficiently-one-best-bdd-v-ingleshwar/
36 stars 26 forks source link

Use custom field decorator #14

Open mattokar opened 5 years ago

mattokar commented 5 years ago

Hi. This is not issue with your project. I am trying to use custom field decorator for page objects and there is not much information out there how to do it. Your project is one of fews that shows the way. However I am still half-way successful.

class StartPage(driver: WebDriver) : FrameworkPage(driver, Predicate {
    PageFactory.initElements(CustomFieldDecorator(ElementLocatorFactorySelector(ConfiguredEnvironment.getConfiguration()).getLocatorFor(driver), driver, it!!), it)
    true
}) {

I am getting this exception, but if I debug my code, no exception happens at PageFactory.java:117

Caused by: net.serenitybdd.core.exceptions.StepInitialisationException: Failed to create step library for AtCommonPage:Can not set com.xxx.framework.android.ButtonComponent field com.xxx.framework.android.xxx.pages.StartPage.btnLoginComponent to com.sun.proxy.$Proxy48
    at net.thucydides.core.steps.StepFactory.getNewStepLibraryFor(StepFactory.java:92)
    at net.thucydides.core.steps.IndividualInstancesByDefaultStepCreationStrategy.initiateStepsFor(IndividualInstancesByDefaultStepCreationStrategy.java:16)
    at net.thucydides.core.steps.StepAnnotations.instantiateAnyUnitiaializedSteps(StepAnnotations.java:76)
    at net.thucydides.core.steps.StepAnnotations.instanciateScenarioStepFields(StepAnnotations.java:60)
    at net.thucydides.core.steps.StepAnnotations.injectNestedScenarioStepsInto(StepAnnotations.java:52)
    at net.thucydides.core.steps.StepFactory.instantiateAnyNestedStepLibrariesIn(StepFactory.java:316)
    at net.thucydides.core.steps.StepFactory.instantiateNewStepLibraryFor(StepFactory.java:154)
    at net.thucydides.core.steps.StepFactory.instantiateNewStepLibraryFor(StepFactory.java:139)
    at net.thucydides.core.steps.StepFactory.getNewStepLibraryFor(StepFactory.java:86)
    ... 23 more
Caused by: java.lang.IllegalArgumentException: Can not set com.xxx.framework.android.ButtonComponent field com.xxx.framework.android.xxx.pages.StartPage.btnLoginComponent to com.sun.proxy.$Proxy48
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
    at java.lang.reflect.Field.set(Field.java:764)
    at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:117)
    at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
    at net.thucydides.core.annotations.locators.SmartElementProxyCreator.proxyElements(SmartElementProxyCreator.java:22)
    at net.thucydides.core.webdriver.DefaultPageObjectInitialiser.apply(DefaultPageObjectInitialiser.java:19)
    at net.serenitybdd.core.pages.PageObject.setDriver(PageObject.java:166)
    at net.serenitybdd.core.pages.PageObject.setDriver(PageObject.java:170)
    at net.thucydides.core.steps.PageObjectDependencyInjector.updatePageObject(PageObjectDependencyInjector.java:69)
    at net.thucydides.core.steps.PageObjectDependencyInjector.injectDependenciesInto(PageObjectDependencyInjector.java:31)
    at net.thucydides.core.steps.PageObjectDependencyInjector.instantiatePageObjectIfNotAssigned(PageObjectDependencyInjector.java:56)
    at net.thucydides.core.steps.PageObjectDependencyInjector.injectDependenciesInto(PageObjectDependencyInjector.java:33)
    at net.thucydides.core.steps.StepFactory.injectOtherDependenciesInto(StepFactory.java:166)
    at net.thucydides.core.steps.StepFactory.instantiateNewStepLibraryFor(StepFactory.java:156)
    at net.thucydides.core.steps.StepFactory.instantiateNewStepLibraryFor(StepFactory.java:139)
    at net.thucydides.core.steps.StepFactory.getNewStepLibraryFor(StepFactory.java:86)
    ... 31 more

I think StartPage is created twice, first with my decorator (no exception) and second time with default decorator when exception happens. What am I doing wrong? Thanks for any help