gpt4 book ai didi

java - 如何修复 Can not set io.appium.java_client.android.AndroidElement 错误

转载 作者:行者123 更新时间:2023-12-02 03:03:52 30 4
gpt4 key购买 nike

我正在尝试使用页面工厂将元素与我的基本测试和测试运行程序分开,但是当我运行它时,它返回一个错误。有人可以帮助我编写代码吗?

我已经尝试在谷歌上搜索修复程序,但没有任何效果

公共(public)类 BaseTest {

private final String URL_STRING = "http://127.0.0.1:7622/wd/hub";
protected URL url;
public AndroidDriver<AndroidElement> driver;

private final static String APP_PACKAGE_NAME = "com.android.chrome";
private final static String APP_ACTIVITY_NAME = "com.google.android.apps.chrome.Main";

public AndroidDriver<AndroidElement> init() throws MalformedURLException {
url = new URL(URL_STRING);
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(AndroidMobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);
caps.setCapability(MobileCapabilityType.UDID, "emulator-5554");
caps.setCapability(MobileCapabilityType.NO_RESET, true);
caps.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, APP_PACKAGE_NAME);
caps.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, APP_ACTIVITY_NAME);
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Samsung");


driver = new AndroidDriver<AndroidElement>(url, caps);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


return driver;
}

}

公共(public)类 HomePage 扩展 BaseTest {

@AndroidFindBy(id = "com.android.chrome:id/search_box_text")
public AndroidElement searchTxt;

public HomePage() {
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}

公共(public)类 SampleGoogle 扩展了 BaseTest {

@Test
public void Sample() throws MalformedURLException {

HomePage homePage = new HomePage();

homePage.init();
homePage.setSearch("Test");

预期结果应该是 Chrome 将在我的模拟器上打开,然后测试将写入搜索栏中,但是当我运行代码时返回错误。

FAILED: Sample java.lang.IllegalArgumentException: Can not set io.appium.java_client.android.AndroidElement field com.google.HomePage.searchTxt to org.openqa.selenium.remote.RemoteWebElement$$EnhancerByCGLIB$$d27c0df4 at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source) at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source) at java.lang.reflect.Field.set(Unknown Source) at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:117) at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105) at com.google.HomePage.(HomePage.java:21) at com.testcases.SampleGoogle.Sample(SampleGoogle.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.Invoker.invokeMethod(Invoker.java:661) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:744) at org.testng.TestRunner.run(TestRunner.java:602) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

最佳答案

我也遇到了同样的问题我的错误:我在 appium URL 的 wd 中使用了大写“W”(所需功能)。将其更改为小“w”(wd),现在工作正常

关于java - 如何修复 Can not set io.appium.java_client.android.AndroidElement 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57033878/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com