简体   繁体   English

org.openqa.selenium.SessionNotCreatedException:消息:无法启动新的 session。使用 Appium Java 时出现响应代码 500 错误

[英]org.openqa.selenium.SessionNotCreatedException: Message: Could not start a new session. Response code 500 error using Appium Java

I am still very new to UI test automation.我对 UI 测试自动化还是很陌生。 When I run the code up to line 27 ("String session ID..."), my APK starts on the emulator and my Appium server also runs smoothly.当我运行代码到第 27 行(“String session ID...”)时,我的 APK 在模拟器上启动并且我的 Appium 服务器也运行顺利。 Now when I want to run a Simple UI test, I get the following error message:现在,当我想运行一个简单的 UI 测试时,我收到以下错误消息:

 Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 404. Message: The session identified by 72bf293f-5423-4430-b126-96be60d37a2c is not known

Code:代码:

package setup;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;

public class CapabilityBase {

    public static void main(String[] args) throws MalformedURLException {

        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"android");
        desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "12");
        desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel");
        desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
        desiredCapabilities.setCapability("autoGrantPermissions", true);
        desiredCapabilities.setCapability(MobileCapabilityType.APP, "/Users/firstname.lastname/eclipse-workspace/BMUI_testAutomation/src/test/resources/SystemUnderTest/app-staging.apk");

        URL url = new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver driver = new AndroidDriver(url, desiredCapabilities);
        String sessionId = driver.getSessionId().toString();

        //driver.findElement(By.id("com.google.android.permissioncontroller/com.android.permissioncontroller.permission.ui.GrantPermissionsActivity/permission_allow_button")).click();

        driver.findElement (new By.ByXPath("//android.widget.TextView[contains(@text,'Your Login']")).click();
        //driver.findElement (new By.ByXPath("//android.widget.TextView[contains(@text,'Your Login']")).sendKeys("02209");
        //driver.findElement (new By.ByXPath("//android.widget.TextView[contains(@text,'Your PIN']")).click();
        //driver.findElement (new By.ByXPath("//android.widget.TextView[contains(@text,'Your PIN']")).sendKeys("030378");

// System.out.print("test passed");


    }
}

Error:错误:


    Executing ':CapabilityBase.main()'...
    
    > Task :compileJava NO-SOURCE
    > Task :processResources NO-SOURCE
    > Task :classes UP-TO-DATE
    > Task :compileTestJava UP-TO-DATE
    > Task :processTestResources UP-TO-DATE
    > Task :testClasses UP-TO-DATE
    
    > Task :CapabilityBase.main()
    Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 404. Message: The session identified by 72bf293f-5423-4430-b126-96be60d37a2c is not known 
    Host info: host: 'MBPvonEnrico2', ip: '2a02:8109:9f80:1a68:0:0:0:ea6f%en0'
    Build info: version: '4.7.1', revision: 'c6795baf1a3'
    System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_292'
    Driver info: io.appium.java_client.android.AndroidDriver
    Command: [null, newSession {capabilities=[{appium:app=/Users/enrico.weck/eclipse-workspace/BMUI_testAutomation/src/test/resources/SystemUnderTest/app-staging.apk, appium:autoGrantPermissions=true, appium:automationName=uiautomator2, appium:deviceName=Pixel, platformName=ANDROID, appium:platformVersion=12}], desiredCapabilities=Capabilities {app: /Users/enrico.weck/eclipse-..., autoGrantPermissions: true, automationName: uiautomator2, deviceName: Pixel, platformName: ANDROID, platformVersion: 12}}]
    Capabilities {}
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
        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 io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:133)
        at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
        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:551)
        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.android.AndroidDriver.<init>(AndroidDriver.java:117)
        at setup.CapabilityBase.main(CapabilityBase.java:26)
    
    > Task :CapabilityBase.main() FAILED
    
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
    
    You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
    
    See https://docs.gradle.org/7.4/userguide/command_line_interface.html#sec:command_line_warnings
    3 actionable tasks: 1 executed, 2 up-to-date
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':CapabilityBase.main()'.
    > Process 'command '/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
    
    * Try:
    > Run with --stacktrace option to get the stack trace.
    > Run with --info or --debug option to get more log output.
    > Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 27s
    ```

Server Logs:服务器日志:

    
        [HTTP] <-- POST /wd/hub/session 200 29274 ms - 1106
        [HTTP] 
        [HTTP] --> POST /wd/hub/session/8e481bd0-d86d-4310-aac1-d0dcebe57e76/element
        [HTTP] {"using":"xpath","value":"//android.widget.TextView[contains(@text,'Your Login']"}
        [W3C (8e481bd0)] Calling AppiumDriver.findElement() with args: ["xpath","//android.widget.TextView[contains(@text,'Your Login']","8e481bd0-d86d-4310-aac1-d0dcebe57e76"]
        [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator
        [BaseDriver] Waiting up to 0 ms for condition
        [WD Proxy] Matched '/element' to command name 'findElement'
        [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8202/wd/hub/session/0a905b04-4358-45e9-ba42-c3e8ec736cee/element] with body: {"strategy":"xpath","selector":"//android.widget.TextView[contains(@text,'Your Login']","context":"","multiple":false}
        [WD Proxy] Got response with status 400: {"sessionId":"0a905b04-4358-45e9-ba42-c3e8ec736cee","value":{"error":"invalid selector","message":"org.eclipse.wst.xml.xpath2.processor.XPathParserException: CUP parser error: Parser error: line 1 col 54: ]","stacktrace":"io.appium.uiautomator2.common.exceptions.InvalidSelectorException: org.eclipse.wst.xml.xpath2.processor.XPathParserException: CUP parser error: Parser error: line 1 col 54: ]\n\tat io.appium.uiautomator2.core.AccessibilityNodeInfoDumper.findNodes(AccessibilityNodeInfoDumper.java:213)\n\tat io.appium.uiautomator2.utils.ElementLocationHelpers.getXPathNodeMatch(ElementLocationHelpers.java:119)\n\tat io.appium.uiautomator2.handler.FindElement.findElement(FindElement.java:88)\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:67)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:266)\n\tat io.appium.uiautomator2.server.AppiumServlet.handl...
        [W3C] Matched W3C error code 'invalid selector' to InvalidSelectorError
        [W3C (8e481bd0)] Encountered internal error running command: io.appium.uiautomator2.common.exceptions.InvalidSelectorException: org.eclipse.wst.xml.xpath2.processor.XPathParserException: CUP parser error: Parser error: line 1 col 54: ]
        [W3C (8e481bd0)]    at io.appium.uiautomator2.core.AccessibilityNodeInfoDumper.findNodes(AccessibilityNodeInfoDumper.java:213)
        [W3C (8e481bd0)]    at io.appium.uiautomator2.utils.ElementLocationHelpers.getXPathNodeMatch(ElementLocationHelpers.java:119)
        [W3C (8e481bd0)]    at io.appium.uiautomator2.handler.FindElement.findElement(FindElement.java:88)
        [W3C (8e481bd0)]    at io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:67)
        [W3C (8e481bd0)]    at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)
        [W3C (8e481bd0)]    at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:266)
        [W3C (8e481bd0)]    at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:260)
        [W3C (8e481bd0)]    at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
        [W3C (8e481bd0)]    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
        [W3C (8e481bd0)]    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
        [W3C (8e481bd0)]    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
        [W3C (8e481bd0)]    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
        [W3C (8e481bd0)]    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
        [W3C (8e481bd0)]    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
        [W3C (8e481bd0)]    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
        [W3C (8e481bd0)]    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
        [W3C (8e481bd0)]    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
        [W3C (8e481bd0)]    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
        [W3C (8e481bd0)]    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
        [W3C (8e481bd0)]    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)
        [W3C (8e481bd0)]    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)
        [W3C (8e481bd0)]    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
        [W3C (8e481bd0)]    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
        [W3C (8e481bd0)]    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
        [W3C (8e481bd0)]    at java.lang.Thread.run(Thread.java:920)
        [W3C (8e481bd0)] Caused by: org.eclipse.wst.xml.xpath2.processor.XPathParserException: CUP parser error: Parser error: line 1 col 54: ]
        [W3C (8e481bd0)]    at org.eclipse.wst.xml.xpath2.processor.internal.InternalXPathParser.parse(InternalXPathParser.java:67)
        [W3C (8e481bd0)]    at org.eclipse.wst.xml.xpath2.processor.JFlexCupParser.parse(JFlexCupParser.java:33)
        [W3C (8e481bd0)]    at org.eclipse.wst.xml.xpath2.processor.Engine.parseExpression(Engine.java:17)
        [W3C (8e481bd0)]    at io.appium.uiautomator2.core.AccessibilityNodeInfoDumper.findNodes(AccessibilityNodeInfoDumper.java:211)
        [W3C (8e481bd0)]    ... 37 more
        [W3C (8e481bd0)] Caused by: org.eclipse.wst.xml.xpath2.processor.internal.CupError
        [W3C (8e481bd0)]    at org.eclipse.wst.xml.xpath2.processor.internal.XPathCup.report_error(XPathCup.java:3238)
        [W3C (8e481bd0)]    at java_cup.runtime.lr_parser.syntax_error(lr_parser.java:396)
        [W3C (8e481bd0)]    at java_cup.runtime.lr_parser.parse(lr_parser.java:595)
        [W3C (8e481bd0)]    at org.eclipse.wst.xml.xpath2.processor.internal.InternalXPathParser.parse(InternalXPathParser.java:47)
        [W3C (8e481bd0)]    ... 40 more
        [W3C (8e481bd0)] 
        [HTTP] <-- POST /wd/hub/session/8e481bd0-d86d-4310-aac1-d0dcebe57e76/element 400 1414 ms - 5068


I have already tried a few things as well as a JDK or appium upgrade or changing the runner to intellij.我已经尝试了一些东西以及 JDK 或 appium 升级或将运行器更改为 intellij。 Maybe someone can help me thx.也许有人可以帮助我。

Sounds like the way you are using the selector is not correct.听起来您使用选择器的方式不正确。

Please change this statement:请更改此声明:

driver.findElement (new By.ByXPath("//android.widget.TextView[contains(@text,'Your Login']")).click();

To this,对此,

driver.findElement (AppiumBy.xpath("//android.widget.TextView[contains(@text,'Your Login']")).click();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.openqa.selenium.SessionNotCreatedException:消息:无法启动新的 session。响应代码 500 错误使用 Selenium Java - org.openqa.selenium.SessionNotCreatedException: Message: Could not start a new session. Response code 500 error using Selenium Java org.openqa.selenium.SessionNotCreatedException:无法启动新的 session.响应码 500.Message:未知错误:无法创建 Chrome 进程 - org.openqa.selenium.SessionNotCreatedException:Could not start a new session.Response code 500.Message:unknown error: Failed to create Chrome process org.openqa.selenium.SessionNotCreatedException:无法启动新的 session。 使用驱动程序 service-docker 容器创建 session 时出错 - org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Error while creating session with the driver service-docker container SessionNotCreatedException: Could not start a new session. Response code 500 错误使用 Selenium Java 和 WebDriverManager 通过 pom.xml - SessionNotCreatedException: Could not start a new session. Response code 500 error using Selenium Java and WebDriverManager through pom.xml Appium 错误:线程“main”org.openqa.selenium.SessionNotCreatedException 中的异常:无法创建新的远程会话 - Appium Error :Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。 在模拟器中初始化android驱动程序 - org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. while initializing android driver in emulator org.openqa.selenium.SessionNotCreatedException:无法创建新的会话。 (原始错误:&#39;java -version&#39;失败。错误:产生ENOENT) - org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT) org.openqa.selenium.SessionNotCreatedException:无法通过 Selenium 和 Java 使用 GeckoDriver 和 Firefox 创建会话错误 - org.openqa.selenium.SessionNotCreatedException: Unable to create session error using GeckoDriver and Firefox through Selenium and Java Appium \\ MAC OS \\ Android \\ Java-org.openqa.selenium.SessionNotCreatedException - Appium \ MAC OS \ Android \ Java - org.openqa.selenium.SessionNotCreatedException Appium _org.openqa.selenium.SessionNotCreatedException - Appium _org.openqa.selenium.SessionNotCreatedException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM