gpt4 book ai didi

java - org.openqa.selenium.json.JsonOutput.write(Ljava/lang/Object;)Lorg/openqa/selenium/json/JsonOutput;由于 java.io.IOException : Incomplete document

转载 作者:行者123 更新时间:2023-11-30 02:00:21 27 4
gpt4 key购买 nike

我正在使用 Spring Boot 2 和 Appium 从头开始​​创建一个新的测试框架。为了编写测试,我使用了 JUnit,它已经包含在 Spring Boot 的 spring-boot-starter-test 中。 POM 以及许多其他的。我将 Appium 添加到我的 POM 中,现在看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.automationexperiment</groupId>
<artifactId>one</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

对于我的测试,我有一个 DriverSetup 类,如下所示:

@RunWith(SpringRunner.class)
@SpringBootTest
public class DriverSetup {

protected AndroidDriver<AndroidElement> driver;

@Before
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0.1");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "DeviceName");
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.google.android.gm");
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".ConversationListActivityGmail");
URL myUrl = new URL("http://127.0.0.1:4723/wd/hub");
this.driver = new AndroidDriver<AndroidElement>(myUrl, capabilities);
this.driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
}

最后,我有另一个从 DriverSetup 扩展的类,以确保在每次测试之前完成驱动程序初始化。它看起来像这样:

@RunWith(SpringRunner.class)
@SpringBootTest
public class FirstTryTest extends DriverSetup {

public FirstTryTest() { }

@Test
public void test() {
System.out.println("test");
}
}

我只是想确保我能够通过我的 FirstTryTest 中的测试,但每次代码都会使用 URL 初始化 AndroidDriver和 DesiredCapabilities ,我收到以下错误:

java.lang.NoSuchMethodError: org.openqa.selenium.json.JsonOutput.write(Ljava/lang/Object;)Lorg/openqa/selenium/json/JsonOutput;
at io.appium.java_client.remote.NewAppiumSessionPayload.writeTo(NewAppiumSessionPayload.java:265)
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:175)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:209)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:93)
at com.automationexperiment.one.driversetup.DriverSetup.setUp(DriverSetup.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at com.microsoft.java.test.runner.JUnit4TestReference.run(JUnit4TestReference.java:51)
at com.microsoft.java.test.runner.CustomizedJUnitCoreRunner.run(CustomizedJUnitCoreRunner.java:45)
at com.microsoft.java.test.runner.JUnitLauncher.execute(JUnitLauncher.java:26)
at com.microsoft.java.test.runner.JUnitLauncher.main(JUnitLauncher.java:15)
Suppressed: java.io.IOException: Incomplete document
at com.google.gson.stream.JsonWriter.close(JsonWriter.java:559)
at org.openqa.selenium.json.JsonOutput.close(JsonOutput.java:39)
at io.appium.java_client.remote.NewAppiumSessionPayload.writeTo(NewAppiumSessionPayload.java:288)
... 41 more

我尝试使用旧版本的 Appium (5.0.4),但它不起作用。我想强调一下 StackTrace 的结尾。安IOException在其他具有类似错误的问题中提到,脚本由于以下原因而失败 org.openqa.selenium.json.JsonException`。

最佳答案

此错误消息:

java.lang.NoSuchMethodError: org.openqa.selenium.json.JsonOutput.write(Ljava/lang/Object;)Lorg/openqa/selenium/json/JsonOutput;
.
Suppressed: java.io.IOException: Incomplete document

...暗示 java.lang.NoSuchMethodError 是由 JVM 引发的。

您提到过使用旧版本的Appium v​​5.0.4

如果缺乏与您的测试环境相关的以下信息,则很难分析错误:

  • Appium 服务器版本
  • 桌面操作系统/版本
  • 正在测试的移动平台/版本
  • 真实设备或仿真器/模拟器

根据讨论Error while running Appium script with AndroidDriveriOS :Could not initialize the ios capabilities with 6.0.0 此错误似乎来自 NumberCoercer 类,该类已在 Selenium RemoteDriver v3.12.0 中修改为接受 Port 作为 整数,而之前它接受字符串

解决方案

  • 更新至最新的 Appium Java 客户端 v6.1.0
  • 更新到最新(至少)Selenium v​​3.12.0
  • @SrinivasanTarget 提到了一个重要的方面:

    • Appium's Java client comes along with Selenium Dependency so we don't recommend to exclude selenium and add as separate dependency as it may raise conflicts at times.

在这里您可以找到关于 java.lang.NoSuchMethodError: org.openqa.selenium.json.JsonOutput.write(Ljava/lang/Object;Ljava/lang/reflect/Type;) 的相关讨论

关于java - org.openqa.selenium.json.JsonOutput.write(Ljava/lang/Object;)Lorg/openqa/selenium/json/JsonOutput;由于 java.io.IOException : Incomplete document,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53086405/

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