1

Has anyone used the MobileElement class in their PageObject classes that are managed by the Serenity BDD JBehave framework?

Here's the PageObject class that I would like to use with my Appium driver:

public class Benning extends PageObject {

    @iOSFindBy(id = "iosThingId")
    @AndroidFindBy(id = "androidThingId")
    private MobileElement thing;

    @iOSFindBy(id = "iosOtherThingId")
    @AndroidFindBy(id = "androidOtherThingId")
    private MobileElement otherThing;

    public void doStuff(){
        thing.swipe(SwipeElementDirection.DOWN, 3);
    }   
}

And here's what I've got sort of working, which is a bit messy

public class Benning extends PageObject {

    @iOSFindBy(id = "iosThingId")
    @AndroidFindBy(id = "androidThingId")
    private WebElement thing;

    @iOSFindBy(id = "iosOtherThingId")
    @AndroidFindBy(id = "androidOtherThingId")
    private WebElement otherThing;

    private String androidThingId = "androindThingId";
    private String iosThingId = "iosThingId";
    private String androidOtherThingId = "androidOtherThingId";
    private String iosOtherThingId = "iosOtherThingId";

    public Benning (WebDriver driver) {
            super(driver);
        //This allows us to use the @Android and @IosFindBy annotations
            PageFactory.initElements(new AppiumFieldDecorator(getDriver()), this);
        }

    public void doStuff(){
        String iosOrAndroid = ((WebDriverFacade) driver).getProxiedDriver().toString();

        AppiumDriver<MobileElement> wazz = ((AppiumDriver<MobileElement>) ((WebDriverFacade) getDriver()).getProxiedDriver());

        MobileElement mobileElementThing;
        if (iosOrAndroid.containsIgnoreCase("Android")){
            mobileElementThin = wazz.findElementById(androidThingId);
        } else {
            mobileElementThing = wazz.findElementById(iosThingId);
        }                       

        mobileElementThing.swipe(SwipeElementDirection.DOWN, 3);
    }
}

Here's what I've tried so far:

It is not possible to instantiate the PageObject by explicitly passing in a AppiumDriver to the constructor, as the framework is using a WebDriverFacade class internally.

It's not possible to explictly cast the found WebElement objects to MobileElement objects (a class cast exception thrown as the WebElement is implemented by WebElementFacade).

Can anyone help?

Thanks

Verhagen
  • 3,885
  • 26
  • 36
Wazzer
  • 11
  • 4

0 Answers0