我收到错误“java.lang.illegalargumentexception:cannot set io.appium.java\u client.mobileelement field”
错误详细信息
java.lang.illegalargumentexception:无法将io.appium.java\u client.android.androidelement field test.pageobjectlogin.insertuserid设置为org.openqa.selenium.remote.remotewebelement$$enhancerByGlib$$d27c0df4
在sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl。java:167)在sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl。java:171)在sun.reflect.unsafeobjectfieldaccessorimpl.set(unsafeobjectfieldaccessorimpl。java:81)在java.lang.reflect.field.set(field。java:764)在org.openqa.selenium.support.pagefactory.proxyfields(pagefactory。java:117)在org.openqa.selenium.support.pagefactory.initelements(pagefactory。java:105)在test.basepage.(basepage。java:25)在test.pageobjectlogin.(pageobjectlogin。java:13)在test.testtologin.testlogin(testtologin。java:12)在sun.reflect.nativemethodaccessorimpl.invoke0(本机方法)在sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl。java:62)在sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:43)在java.lang.reflect.method.invoke(方法。java:498)在org.testng.internal.methodinvocationhelper.invokemethod(methodinvocationhelper。java:134)在org.testng.internal.testinvoker.invokemethod(testinvoker。java:597)在org.testng.internal.testinvoker.invoketestmethod(testinvoker。java:173)在org.testng.internal.methodrunner.runinsequence(methodrunner。java:46)在org.testng.internal.testinvoker$methodinvocationagent.invoke(testinvoker。java:816)在org.testng.internal.testinvoker.invoketestmethods(testinvoker。java:146)在org.testng.internal.testmethodworker.invoketestmethods(testmethodworker。java:146)在org.testng.internal.testmethodworker.run(testmethodworker。java:128)在java.util.arraylist.foreach(arraylist。java:1257)在org.testng.testrunner.privaterun(testrunner。java:766)在org.testng.testrunner.run(testrunner。java:587)在org.testng.suiterunner.runtest(suiterunner。java:384)访问org.testng.suiterunner.access$000(suiterunner。java:28)在org.testng.suiterunner$suiteworker.run(suiterunner。java:425)在org.testng.internal.thread.threadutil.lambda$execute$0(threadutil。java:68)在java.util.concurrent.futuretask.run(futuretask。java:266)位于java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor。java:1149)在java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor。java:624)在java.lang.thread.run(线程。java:748)
使用如下构造函数
基本页.java
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class BasePage {
public static AppiumDriver<MobileElement> driver;
public BasePage(AppiumDriver<MobileElement> driver){
this.driver = driver;;
PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(10)), this);
}
public void waitForVisibility(AndroidElement e){
WebDriverWait wait = new WebDriverWait(driver, TestUtils.WAIT);
wait.until(ExpectedConditions.visibilityOf(e));
}
public String getAttribute(AndroidElement e, String attribute){
waitForVisibility(e);
return e.getAttribute(attribute);
}
public void sendKeys(AndroidElement e, String txt){
waitForVisibility(e);
e.sendKeys(txt);
}
}
1条答案
按热度按时间s4n0splo1#
这称为页面对象模型。首先,使用mobileelement和androidlement这是错误的一步,mobileelement是最值得推荐的,因为它适用于android和ios。此源有更清晰的概念,请访问https://blog.testproject.io/2018/07/31/page-object-model-appium-java-android/ 检查点编号