如何在Serenity-BDD框架中的PageObject类中使用MobileElement?

时间:2015-08-27 15:39:01

标签: java appium jbehave thucydides serenity-bdd

有没有人在由Serenity BDD JBehave框架管理的PageObject类中使用MobileElement类?

这是我想要与Appium驱动程序一起使用的PageObject类:

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);
    }   
}

这就是我有点工作,这有点凌乱

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);
    }
}

这是我到目前为止所尝试的内容:

由于框架在内部使用WebDriverFacade类,因此无法通过显式将AppiumDriver传递给构造函数来实例化PageObject。

无法将找到的WebElement对象明确地转换为MobileElement对象(WebElement由WebElementFacade实现时抛出类抛出异常)。

有人可以帮忙吗?

由于

0 个答案:

没有答案