Error: can not set io.appium.java_client.MobileElement field is thrown in the framework

浪子不回头ぞ 提交于 2020-05-15 05:56:07

问题


I am using a page factory for my appium framework. The problem is arising when I am trying to run testng5.xml where I want to run 2 classes one after another.

I get an error like "can not set io.appium.java_client.MobileElement field ".

I get this error at my constructor level.

public Homepage(WebDriver driver) {
    super(driver);
    PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}

Not sure what the issue is in testng5.xml. First, the class runs all fine, but problems occur when the 2nd class initiates.

testng5.xml:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Regression Suit2">
    <test name="Sanity Tests">
        <parameter name="device" value="Nexus4" />
        <parameter name="port" value="4723" />
        <classes>
            <class name="au.com.intelematics.mobileautomation.settings.SettingsPageTest" />
            <class name="au.com.intelematics.mobileautomation.destinationdownload.DestinationDownloadPageTest" />
        </classes>
    </test>
</suite>
<!-- Suite -->

回答1:


Thanks all, I got this issue resolved by putting proper life cycle for each test. Earlier i was initializing the driver (ios or android)under @BeforeClass. I changed that to @BeforeMethod and mentioned @AfterMethod for logout action(wherever required) and driver.quit(); Now the the driver is setup before start of each test method. Also casted my WebDriver to AppiumDriver for driver initialization.




回答2:


Instead of using pure WebDriver, try using AppiumDriver <MobileElement>. Or more specific, if you are working on Android device, then use AndroidDriver <MobileElement> or if on IOS device then use IOSDriver <MobileElement>. This should solve your issue.




回答3:


This issue is generated when you pass null value in PageFactory. For example

AppiumDriver<MobileElement> driver=null;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
// this will throw **can not set io.appium.java_client.MobileElement field**

The solution is to pass not null value of in AppiumFieldDecorator.

Make sure your driver is not null while calling PageFactory



来源:https://stackoverflow.com/questions/51129181/error-can-not-set-io-appium-java-client-mobileelement-field-is-thrown-in-the-fr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!