首页 > 解决方案 > 使用 WireMock 模拟 Appium 的行为时无法创建会话

问题描述

我正在尝试使用 WireMock 来模拟 Appium 的行为。

我面临的问题是:我的 POST 存根能够使用我设置的响应代码(我使用 Wireshark 进行监控)来响应我,但它会引发与会话创建相关的异常。

我尝试创建会话以供参考的 POST 存根:

- 试验 1:

wireMockRule.stubFor(post(urlEqualTo("/wd/hub/session”)).

withRequestBody(matching(“JSON representation of set of desired capabilities specific to application"))

.willReturn(aResponse().
withStatus(200).

withHeader("Content-Type", "application/json”).

withBody("{\"sessionId\":\"e523dc70-c068-46e7-b966-8462401119b4\",\"status\":0,\"value\":\"Created Session\"}")));

结果:“无法创建新会话,因为未找到需要 HttpClient、InputStream 和 long 的 'createSession' 或无法访问”异常。

试验 2:刚刚从上面的存根中删除了请求正文

wireMockRule.stubFor(post(urlEqualTo("/wd/hub/session”))

.willReturn(aResponse().

withStatus(200).

withHeader("Content-Type", "application/json”).

withBody("{\"sessionId\":\"e523dc70-c068-46e7-b966-8462401119b4\",\"status\":0,\"value\":\"Created Session\"}")));

结果

org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话”异常。

环境参考:

Appium 的 Java 客户端:6.0.0

Selenium 独立服务器:3.12.0

Java 的 Selenium 客户端:3.12.0

请帮忙。

标签: automationmockingappiumjunit5wiremock

解决方案


This does not really seem to related to WireMock?

Maybe you can switch to the .NET version from WireMock to simulate your calls?


推荐阅读