Appium – 无法在iPad上启动新会话

huangapple go评论107阅读模式
英文:

Appium - Could not start a new session on iPad

问题

我正在尝试在真实的iPad设备上自动化iOS应用程序。我的代码在上周之前一直工作正常,但从今天开始突然出现错误。无论是Xcodenodejsjava还是Appium都没有进行升级。代码也没有进行任何更新。

问题出现在driver = new IOSDriver(new URL("http://127.0.0.1:4723/"),options);这一行。

以下是完整的错误消息:

StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 
Host info: host: '-MacBook-Air.local', ip: 'fe80:0:0:0:1044:a4fe:6300:fc53%en0'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '13.4.1', java.version: '17.0.6'
Driver info: io.appium.java_client.ios.IOSDriver
Command: [null, newSession {capabilities=[{appium:udid=myudid, appium:xcodeOrgId=myxoceorgid, appium:wdaLaunchTimeout=20000, appium:xcodeSigningId=iPhone Developer, appium:deviceName=iPad, platformName=IOS, appium:automationName=XCuiTest, appium:platformVersion=16.5.1}], desiredCapabilities=Capabilities {appium:automationName: XCuiTest, appium:deviceName: Pritish’s iPad, appium:platformVersion: 16.5.1, appium:udid:dsssddsdssd, appium:wdaLaunchTimeout: 20000, appium:xcodeOrgId: dsdsdsdsdssd, appium:xcodeSigningId: iPhone Developer, platformName: IOS}}]
Capabilities {appium:automationName: XCuiTest, appium:deviceName: my iPad, appium:platformVersion: 16.5.1, appium:udid: sddsdsdsds, appium:wdaLaunchTimeout: 20000, appium:xcodeOrgId: ddsds, appium:xcodeSigningId: iPhone Developer, platformName: IOS}
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:536)
	at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:159)
	at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:80)
	at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
	at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:106)
	at WebPortal.IOSBaseTest.runOnRealDevice(IOSBaseTest.java:66)
	at WebPortal.IOSBaseTest.setup(IOSBaseTest.java:32)
	at WebPortal.IOSBaseTest.getDriver(IOSBaseTest.java:25)
	at stepDefinitions.TA124_ComprehensiveCI_StepDefinitions.<init>(TA124_ComprehensiveCI_StepDefinitions.java:36)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
	at io.cucumber.core.runtime.ObjectFactoryServiceLoader$DefaultJavaObjectFactory.cacheNewInstance(ObjectFactoryServiceLoader.java:141)
	at io.cucumber.core.runtime.ObjectFactoryServiceLoader$DefaultJavaObjectFactory.getInstance(ObjectFactoryServiceLoader.java:133)
	at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
	at io.cucumber.java.JavaStepDefinition.execute(JavaStepDefinition.java:29)
	at io.cucumber.core.runner.CoreStepDefinition.execute(CoreStepDefinition.java:66)
	at io.cucumber.core.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:63)
	at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10)
	at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:92)
	at io.cucumber.core.runner.TestStep.run(TestStep.java:64)
	at io.cucumber.core.runner.PickleStepTestStep.run(PickleStepTestStep.java:51)
	at io.cucumber.core.runner.TestCase.run(TestCase.java:104)
	at io.cucumber.core.runner.Runner.runPickle(Runner.java:73)
	at io.cucumber.core.runtime.Runtime.lambda$execute$5(Runtime.java:110)
	at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:117)
	at io.cucumber.core.runtime.Runtime.lambda$execute$6(Runtime.java:110)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:233)
	at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:123)
	at io.cucumber.core.runtime.Runtime.lambda$run$2(Runtime.java:86)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.SliceOps$1$1.accept(SliceOps.java:200)
	at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1602)
	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at io.cucumber.core.runtime.Runtime.run(Runtime.java:87)
	at io.cucumber.core.cli.Main.run(Main.java:92)
	at cucumber.api.cli.Main.run(Main.java:30)
	at cucumber.api.cli.Main.main(Main.java:15)
Caused by: java.lang.NoSuchMethodError: 'java.lang.String org.openqa.selenium.json.Json.toJson(java.lang.Object, int)'
	at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:126)
	at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:111)
	at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:105)
	at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:101)
	at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:194)
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:262)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
	... 48 more
英文:

I am trying to automate iOS app on real iPad device. My code was working fine till last week and suddenly started throwing error from today. Neither Xcode, nodejs, java or Appium has been upgraded. No code has been updated whatsoever.

public AppiumDriver runOnRealDevice() {
		try {
			XCUITestOptions options = new XCUITestOptions();
			options.setDeviceName(&quot;my iPad&quot;);
			options.setPlatformVersion(&quot;16.5.1&quot;);
			options.setWdaLaunchTimeout(Duration.ofSeconds(20));
			options.setCapability(&quot;xcodeOrgId&quot;,&quot;......&quot;);
			options.setCapability(&quot;xcodeSigningId&quot;,&quot;iPhone Developer&quot;);
			options.setCapability(&quot;udid&quot;,&quot;......&quot;);
			driver = new IOSDriver(new URL(&quot;http://127.0.0.1:4723/&quot;),options);
			
			driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15));
			Map&lt;String,String&gt; params = new HashMap&lt;String,String&gt;();
			params.put(&quot;bundleId&quot;, &quot;com.myapplebundleidentfier&quot;);
			driver.executeScript(&quot;mobile:launchApp&quot;,params);
		}catch (Exception e) {
			System.out.println(&quot;Here12 &quot;+e.getLocalizedMessage());
			e.printStackTrace();
		}
		return driver;
	}

The issue happens on driver = new IOSDriver(new URL(&quot;http://127.0.0.1:4723/&quot;),options);

Below is the complete error message

StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 
Host info: host: &#39;-MacBook-Air.local&#39;, ip: &#39;fe80:0:0:0:1044:a4fe:6300:fc53%en0&#39;
Build info: version: &#39;4.11.0&#39;, revision: &#39;040bc5406b&#39;
System info: os.name: &#39;Mac OS X&#39;, os.arch: &#39;aarch64&#39;, os.version: &#39;13.4.1&#39;, java.version: &#39;17.0.6&#39;
Driver info: io.appium.java_client.ios.IOSDriver
Command: [null, newSession {capabilities=[{appium:udid=myudid, appium:xcodeOrgId=myxoceorgid, appium:wdaLaunchTimeout=20000, appium:xcodeSigningId=iPhone Developer, appium:deviceName=iPad, platformName=IOS, appium:automationName=XCuiTest, appium:platformVersion=16.5.1}], desiredCapabilities=Capabilities {appium:automationName: XCuiTest, appium:deviceName: Pritish’s iPad, appium:platformVersion: 16.5.1, appium:udid:dsssddsdssd, appium:wdaLaunchTimeout: 20000, appium:xcodeOrgId: dsdsdsdsdssd, appium:xcodeSigningId: iPhone Developer, platformName: IOS}}]
Capabilities {appium:automationName: XCuiTest, appium:deviceName: my iPad, appium:platformVersion: 16.5.1, appium:udid: sddsdsdsds, appium:wdaLaunchTimeout: 20000, appium:xcodeOrgId: ddsds, appium:xcodeSigningId: iPhone Developer, platformName: IOS}
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:536)
	at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
	at org.openqa.selenium.remote.RemoteWebDriver.&lt;init&gt;(RemoteWebDriver.java:159)
	at io.appium.java_client.AppiumDriver.&lt;init&gt;(AppiumDriver.java:80)
	at io.appium.java_client.AppiumDriver.&lt;init&gt;(AppiumDriver.java:92)
	at io.appium.java_client.ios.IOSDriver.&lt;init&gt;(IOSDriver.java:106)
	at WebPortal.IOSBaseTest.runOnRealDevice(IOSBaseTest.java:66)
	at WebPortal.IOSBaseTest.setup(IOSBaseTest.java:32)
	at WebPortal.IOSBaseTest.getDriver(IOSBaseTest.java:25)
	at stepDefinitions.TA124_ComprehensiveCI_StepDefinitions.&lt;init&gt;(TA124_ComprehensiveCI_StepDefinitions.java:36)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
	at io.cucumber.core.runtime.ObjectFactoryServiceLoader$DefaultJavaObjectFactory.cacheNewInstance(ObjectFactoryServiceLoader.java:141)
	at io.cucumber.core.runtime.ObjectFactoryServiceLoader$DefaultJavaObjectFactory.getInstance(ObjectFactoryServiceLoader.java:133)
	at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
	at io.cucumber.java.JavaStepDefinition.execute(JavaStepDefinition.java:29)
	at io.cucumber.core.runner.CoreStepDefinition.execute(CoreStepDefinition.java:66)
	at io.cucumber.core.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:63)
	at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10)
	at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:92)
	at io.cucumber.core.runner.TestStep.run(TestStep.java:64)
	at io.cucumber.core.runner.PickleStepTestStep.run(PickleStepTestStep.java:51)
	at io.cucumber.core.runner.TestCase.run(TestCase.java:104)
	at io.cucumber.core.runner.Runner.runPickle(Runner.java:73)
	at io.cucumber.core.runtime.Runtime.lambda$execute$5(Runtime.java:110)
	at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:117)
	at io.cucumber.core.runtime.Runtime.lambda$execute$6(Runtime.java:110)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:233)
	at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:123)
	at io.cucumber.core.runtime.Runtime.lambda$run$2(Runtime.java:86)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.SliceOps$1$1.accept(SliceOps.java:200)
	at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1602)
	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at io.cucumber.core.runtime.Runtime.run(Runtime.java:87)
	at io.cucumber.core.cli.Main.run(Main.java:92)
	at cucumber.api.cli.Main.run(Main.java:30)
	at cucumber.api.cli.Main.main(Main.java:15)
Caused by: java.lang.NoSuchMethodError: &#39;java.lang.String org.openqa.selenium.json.Json.toJson(java.lang.Object, int)&#39;
	at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:126)
	at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:111)
	at org.openqa.selenium.remote.NewSessionPayload.create(NewSessionPayload.java:105)
	at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:101)
	at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:194)
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:262)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
	... 48 more

答案1

得分: 1

这应该意味着你的代码或者你正在使用的某个库尝试调用当前加载的库版本中不存在的方法。当库版本不匹配时,经常会出现这种错误。

由于你没有更改代码,并且Appium和其他工具的版本相同,可能你不小心更新了一些库。检查一下你项目的依赖项(库/ JAR)是否一致并且兼容。

  • 如果你使用的是Maven,请检查你的pom.xml文件。
  • 如果你使用的是Gradle,请检查你的build.gradle文件。

如果你的项目源代码使用了Git,可以通过git status命令查看是否有任何更改。

确保Appium的Java客户端和Selenium的Java客户端版本兼容。

尝试清除缓存并重新安装依赖项。

  • 如果使用Maven:
mvn clean install
  • 如果使用Gradle:
./gradlew clean build

如果你只在依赖管理工具中指定了Appium Java客户端,尝试明确指定一个兼容的Selenium版本(参见兼容性矩阵)。Appium的客户端依赖于Selenium,版本之间可能存在兼容性问题。

还要检查一下你设备的操作系统版本是否已更新,这可能会影响Appium的行为。


原帖中提到通过移除以下依赖项解决了问题:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-devtools</artifactId>
    <version>4.0.0-beta-4</version>
</dependency>

selenium-devtools 依赖项是针对Chrome和Chrome DevTools Protocol (CDP) 的。它提供了与Chrome的DevTools进行高级自动化任务交互的能力,超出了标准Selenium功能的范围。例如,操作网络条件、设置断点等。

原帖中使用的是版本 4.0.0-beta-4。如果你的其他Selenium依赖项的版本不一致,可能会导致冲突。

而且 selenium-devtools artifact 可能会引入与项目中其他依赖项冲突的传递依赖项。

根据原帖中的堆栈跟踪显示的iOS测试问题(io.appium.java_client.ios.IOSDriver),可能并不需要Chrome特定的 selenium-devtools 依赖项。Appium iOS测试不使用Chrome DevTools。

由于Java库有时会有相同名称的类,因此 selenium-devtools 依赖项可能引入了与类路径上其他类冲突的类。

英文:
Caused by: java.lang.NoSuchMethodError: &#39;java.lang.String org.openqa.selenium.json.Json.toJson(java.lang.Object, int)&#39;

That should mean your code, or one of the libraries you are using, is trying to call a method that does not exist in the version of the library that is currently loaded. It is common to see this error when there are mismatches in library versions.

Since you have not changed your code, and the versions of Appium and other tools are the same, it is possible that you might have inadvertently updated some libraries. Check if your project's dependencies (libraries/jars) are consistent and compatible.

  • If you are using Maven, check your pom.xml file.
  • If you are using Gradle, check your build.gradle file.

If your project source code with using Git, a git status should help visualize any change.

Make sure the versions of Appium's Java client and Selenium's Java client are compatible.

Try and clear the cache and reinstall dependencies.

  • If using Maven:
mvn clean install
  • If using Gradle:
./gradlew clean build

If you are only specifying the Appium Java client in your dependency management tool, try explicitly specifying a compatible Selenium version too (See Compatibility Matrix). Appium's client has a dependency on Selenium, and there might be compatibility issues between versions.

Check also if your device's OS version was updated, it might affect Appium's behavior.


The OP mentions having resolved the issue by removing:

&lt;dependency&gt;
            &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
            &lt;artifactId&gt;selenium-devtools&lt;/artifactId&gt;
            &lt;version&gt;4.0.0-beta-4&lt;/version&gt;
&lt;/dependency&gt;

The selenium-devtools dependency is specific to Chrome and the Chrome DevTools Protocol (CDP). It provides capabilities to interact with Chrome's DevTools for advanced automation tasks that go beyond the standard Selenium capabilities. Examples include manipulating network conditions, setting breakpoints, etc.

The OP was using version 4.0.0-beta-4. If your other Selenium dependencies were not of the same version, it might have caused conflicts.

And the selenium-devtools artifact might have pulled in transitive dependencies that conflicted with other dependencies in your project.

Given the OP's stack trace showed issues with iOS testing (io.appium.java_client.ios.IOSDriver), the Chrome-specific selenium-devtools dependency might not have been necessary. Appium iOS testing does not utilize Chrome DevTools.

Since Java libraries sometimes have classes with the same names, it is possible the selenium-devtools dependency introduced classes that conflicted with others on the classpath.

答案2

得分: 1

我成功解决了我的问题,方法是移除以下依赖项:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-devtools</artifactId>
    <version>4.0.0-beta-4</version>
</dependency>
英文:

I managed to resolve my issue by removing following dependency

&lt;dependency&gt;
            &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
            &lt;artifactId&gt;selenium-devtools&lt;/artifactId&gt;
            &lt;version&gt;4.0.0-beta-4&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2023年8月9日 11:43:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864429.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定