我正在使用Java与Appium和Serenity一起编写硒测试自动化框架。
我在创建页面对象模型时遇到问题。
我的页面类如下:
public class MattVerifyPage extends PageObject{
private AppiumDriver driver;
public MattVerifyPage(AppiumDriver driver) {
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
@AndroidFindBy(xpath = "Androidxpath")
@iOSFindBy(xpath = "iOSxpath")
public MobileElement verifyTitle ;
public void verifyTitle(String expectedTitle){
String actualTitle =verifyTitle.getText();
}
在我的测试步骤文件中,使用以下代码实例化页面:
MattVerifyPage VerifyPage = new MattVerifyPage(driver);
但是,当我运行测试时,出现以下错误。
java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field com.xxx.test.pages.MattVerifyPage.verifyTitle to com.sun.proxy.$Proxy19
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.lambda$new$3(SmartElementProxyCreator.java:37)
at net.thucydides.core.annotations.locators.SmartElementProxyCreator.proxyElements(SmartElementProxyCreator.java:48)
at net.thucydides.core.webdriver.DefaultPageObjectInitialiser.apply(DefaultPageObjectInitialiser.java:21)
at net.serenitybdd.core.pages.PageObject.setDriver(PageObject.java:151)
at net.serenitybdd.core.pages.PageObject.setDriver(PageObject.java:155)
at net.thucydides.core.steps.PageObjectDependencyInjector.updatePageObject(PageObjectDependencyInjector.java:69)
at net.thucydides.core.steps.PageObjectDependencyInjector.instantiatePageObjectIfNotAssigned(PageObjectDependencyInjector.java:59)
at net.thucydides.core.steps.PageObjectDependencyInjector.injectDependenciesInto(PageObjectDependencyInjector.java:33)
at net.serenitybdd.core.Serenity.injectDependenciesInto(Serenity.java:61)
at net.serenitybdd.core.Serenity.initializeWithNoStepListener(Serenity.java:102)
at cucumber.runtime.SerenityObjectFactory.newInstance(SerenityObjectFactory.java:68)
at cucumber.runtime.SerenityObjectFactory.cacheNewInstance(SerenityObjectFactory.java:51)
at cucumber.runtime.SerenityObjectFactory.getInstance(SerenityObjectFactory.java:41)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:37)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:40)
at cucumber.api.TestStep.executeStep(TestStep.java:102)
at cucumber.api.TestStep.run(TestStep.java:83)
at cucumber.api.TestCase.run(TestCase.java:58)
at cucumber.runner.Runner.runPickle(Runner.java:80)
at cucumber.runtime.Runtime.runFeature(Runtime.java:119)
at cucumber.runtime.Runtime.run(Runtime.java:104)
at cucumber.api.cli.Main.run(Main.java:36)
at cucumber.api.cli.Main.main(Main.java:18)
答案 0 :(得分:0)
如果您正在使用Serenity BDD,则无需声明或管理自己的WebDriver实例-Serenity会为您处理。 https://serenity-bdd.rocket.chat上有很多人与Serenity和Appium一起工作。
答案 1 :(得分:0)
有关信息,导致问题的原因是“扩展PageObject”。 这是Serenity PageObject。 我暂时将其删除,然后Appium Page对象模型代码开始工作。