openqa.selenium.NoSuchSessionException:会话已终止或未启动

问题描述 投票:0回答:2

我使用 selenium + maven + cucumber + testng + appium 进行移动 ui 测试。我也在真实设备上运行这个案例。但应用程序启动了两次;

Mar 03, 2020 5:56:11 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Mar 03, 2020 5:56:37 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C

然后我看到以下错误消息;

Scenario: [1.0] Check Incoming Payment Types [90m# src/test/resources/features/Android/Payment.feature:6[0m
    [31mGiven [0m[31modeal app is launched[0m                [90m# PaymentFlow.launchedOdealApp()[0m
      [31morg.openqa.selenium.NoSuchSessionException: A session is either terminated or not started
      Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
      System info: host: 'admins-Mac-mini.local', ip: 'fe80:0:0:0:14b1:249d:6e8e:379f%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.3', java.version: '1.8.0_231'
      Driver info: io.appium.java_client.android.AndroidDriver
      Capabilities {app: /Users/busekaya/Desktop/app..., appActivity: com.telera.merchant.splash...., appPackage: com.telera.merchant.stage.d..., automationName: UiAutomator2, clearSystemFiles: false, databaseEnabled: false, desired: {app: /Users/busekaya/Desktop/app..., appActivity: com.telera.merchant.splash...., appPackage: com.telera.merchant.stage.d..., automationName: UiAutomator2, clearSystemFiles: false, deviceName: TestDevice-1, noReset: true, platformName: android, platformVersion: 7.1.1, udid: ZH33D2543D}, deviceApiLevel: 25, deviceManufacturer: motorola, deviceModel: Moto E (4) Plus, deviceName: ZH33D2543D, deviceScreenDensity: 320, deviceScreenSize: 720x1280, deviceUDID: ZH33D2543D, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, pixelRatio: 2, platform: LINUX, platformName: Android, platformVersion: 7.1.1, statBarHeight: 48, takesScreenshot: true, udid: ZH33D2543D, viewportRect: {height: 1136, left: 0, top: 48, width: 720}, warnings: {}, webStorageEnabled: false}
      Session ID: 9b91b01c-08bd-4b7a-a65e-4e09e5a7fcf5
      *** Element info: {Using=id, value=login}
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
        at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
        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.findElement(RemoteWebDriver.java:323)
        at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61)
        at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
        at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
        at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:372)
        at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:69)
        at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)
        at io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)
        at org.openqa.selenium.By$ById.findElement(By.java:188)
        at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
        at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:57)
        at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
        at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
        at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
        at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
        at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:641)
        at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:638)
        at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
        at com.odealMobile.PaymentFlow.launchedOdealApp(PaymentFlow.java:44)
        at ✽.Given odeal app is launched(src/test/resources/features/Android/Payment.feature:7)
      [0m
    [36mWhen [0m[36muser log in to Odeal successfully[0m     [90m# PaymentFlow.loginTheApp()[0m
    [36mAnd [0m[36mClicks on New Payment button[0m           [90m# PaymentFlow.clickNewPayment()[0m
    [36mAnd [0m[36mEnter Price to Opened Page[0m             [90m# PaymentFlow.enterPrice()[0m
    [36mAnd [0m[36mClicks on Get Paid button[0m              [90m# PaymentFlow.clickPaidButton()[0m
    [36mThen [0m[36mAll Payment Types will be Appeared[0m    [90m# PaymentFlow.checkPaymentTypes()[0m

[31mFailed scenarios:[0m
[31msrc/test/resources/features/Android/Payment.feature:6 [0m# Scenario: [1.0] Check Incoming Payment Types

1 Scenarios ([31m1 failed[0m)
6 Steps ([31m1 failed[0m, [36m5 skipped[0m)
0m54.617s

org.openqa.selenium.NoSuchSessionException: A session is either terminated or not started
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'admins-Mac-mini.local', ip: 'fe80:0:0:0:14b1:249d:6e8e:379f%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.3', java.version: '1.8.0_231'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: /Users/busekaya/Desktop/app..., appActivity: com.telera.merchant.splash...., appPackage: com.telera.merchant.stage.d..., automationName: UiAutomator2, clearSystemFiles: false, databaseEnabled: false, desired: {app: /Users/busekaya/Desktop/app..., appActivity: com.telera.merchant.splash...., appPackage: com.telera.merchant.stage.d..., automationName: UiAutomator2, clearSystemFiles: false, deviceName: TestDevice-1, noReset: true, platformName: android, platformVersion: 7.1.1, udid: ZH33D2543D}, deviceApiLevel: 25, deviceManufacturer: motorola, deviceModel: Moto E (4) Plus, deviceName: ZH33D2543D, deviceScreenDensity: 320, deviceScreenSize: 720x1280, deviceUDID: ZH33D2543D, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, pixelRatio: 2, platform: LINUX, platformName: Android, platformVersion: 7.1.1, statBarHeight: 48, takesScreenshot: true, udid: ZH33D2543D, viewportRect: {height: 1136, left: 0, top: 48, width: 720}, warnings: {}, webStorageEnabled: false}
Session ID: 9b91b01c-08bd-4b7a-a65e-4e09e5a7fcf5
*** Element info: {Using=id, value=login}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
    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.findElement(RemoteWebDriver.java:323)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:372)
    at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:69)
    at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)
    at org.openqa.selenium.By$ById.findElement(By.java:188)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:57)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
    at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:641)
    at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:638)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
    at com.odealMobile.PaymentFlow.launchedOdealApp(PaymentFlow.java:44)
    at ✽.Given odeal app is launched(src/test/resources/features/Android/Payment.feature:7)


===============================================
Suite
Total tests run: 1, Passes: 0, Failures: 1, Skips: 0
===============================================

实际上我在移动设备上看到打开的应用程序,但我的案例无法运行。我想强调应用程序打开两次。首先应用程序打开并出现主页,然后关闭。然后应用程序第二次打开,没有案例正在运行。

我用于测试的移动设备:摩托罗拉 Moto E(4) Plus,7.1.1 Appium 版本 1.15.1

我所需的能力详细信息:

 //Screen Classes Initialization
    public void setupCucumber () throws MalformedURLException {
         DesiredCapabilities cap = new DesiredCapabilities();
         cap.setCapability("deviceName", "TestDevice-1");
         cap.setCapability("automationName", "UiAutomator2");
         cap.setCapability("udid", "ZH33D2543D");
         cap.setCapability("platformName", "Android");
         cap.setCapability("platformVersion", "7.1.1");
         cap.setCapability("noReset", "true");
         //cap.setCapability("fullReset", "false");
         cap.setCapability("clearSystemFiles", "false");
         cap.setCapability("appPackage", "com.telera.merchant.stage.debug");
         cap.setCapability("appActivity", "com.telera.merchant.splash.SplashActivity");
         cap.setCapability("app", "/Users/busekaya/Desktop/app-stage-debug.apk");
         //cap.setCapability("autoAcceptAlerts", true);
         //cap.setCapability("path", "/Users/busekaya/Desktop/app-stage-debug.apk");
         driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap); //"http://127.0.0.1:4723/wd/hub\"
         driver.manage().timeouts().implicitlyWait(200, TimeUnit.SECONDS);
         wait = new WebDriverWait(driver, 200);
    }

黄瓜特征文件;

Feature: [1] All Scenarios About Payment    

  @buse2  
  Scenario: [1.0] Check Incoming Payment Types
     Given app is launched
     When  user log in successfully
     And Clicks on New Payment button
     And Enter Price to Opened Page
     And Clicks on the Get Paid button
     Then All Payment Types will be Appeared
android selenium appium-android
2个回答
0
投票

不确定这是否适用,但我遇到了同样的问题,应用程序已安装,但 Appium 立即终止我的会话,说它是

原因:java.lang.RuntimeException:连接 UiAutomation 时出错

就我而言,受到@DebanjanB 答案的启发,我重新安装了 Appium 的 UiAutomator2 软件包,之后它就完美运行了

我跑了这个:

yarn add appium-uiautomator2-driver

如果您使用 npm,请运行此命令

npm i appium-uiautomator2-driver

-1
投票

这个错误信息...

[31morg.openqa.selenium.NoSuchSessionException: A session is either terminated or not started
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'admins-Mac-mini.local', ip: 'fe80:0:0:0:14b1:249d:6e8e:379f%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.3', java.version: '1.8.0_231'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: /Users/busekaya/Desktop/app..., appActivity: com.telera.merchant.splash...., appPackage: com.telera.merchant.stage.d..., automationName: UiAutomator2, clearSystemFiles: false, databaseEnabled: false, desired: {app: /Users/busekaya/Desktop/app..., appActivity: com.telera.merchant.splash...., appPackage: com.telera.merchant.stage.d..., automationName: UiAutomator2, clearSystemFiles: false, deviceName: TestDevice-1, noReset: true, platformName: android, platformVersion: 7.1.1, udid: ZH33D2543D}, deviceApiLevel: 25, deviceManufacturer: motorola, deviceModel: Moto E (4) Plus, deviceName: ZH33D2543D, deviceScreenDensity: 320, deviceScreenSize: 720x1280, deviceUDID: ZH33D2543D, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, pixelRatio: 2, platform: LINUX, platformName: Android, platformVersion: 7.1.1, statBarHeight: 48, takesScreenshot: true, udid: ZH33D2543D, viewportRect: {height: 1136, left: 0, top: 48, width: 720}, warnings: {}, webStorageEnabled: false}
Session ID: 9b91b01c-08bd-4b7a-a65e-4e09e5a7fcf5
*** Element info: {Using=id, value=login}

...意味着 AndroidDriver 无法通过 UiAutomator2 启动/生成新的 浏览上下文


来自服务器端日志(Appium 日志)的更多信息将有助于我们更好地分析问题。但是,当您使用 Appium v1.15.1 时,根据讨论 错误:无法初始化检测进程 v1.11 及更高版本中观察到此问题,如版本 v1 所示。 10.1不存在这样的问题。据推测,服务器端日志(Appium 日志)将包含与类似行中的 UiAutomator2 相关的 logs messages 形式的更多详细信息:

[UiAutomator2] 'skipServerInstallation' is set. Attempting to use UIAutomator2 server from the device
[UiAutomator2] Waiting up to 60000ms for UiAutomator2 to be online...
[debug] [ADB] Creating ADB subprocess with args: ["-P",5037,"-s","emulator-5554","shell","am","instrument","-w","io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner"]
[debug] [Instrumentation] android.util.AndroidException: INSTRUMENTATION_FAILED: io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner

可能的原因是,设备上未安装UiAutomator2,或者可能是服务器安装被明确禁用。


解决方案

一个更简单的解决方案是在 Appium 内升级/降级 UIAutomator2,但你不能这样做,因为 UIAutomator2 依赖于其他模块。

因此,解决方案是降级整个 Appium 软件包。作为替代方案,您也可以更改运行测试的设备上的仿真器/模拟器。有时从设备上卸载

Appium Settings
应用程序并重新启动 Appium 进程也可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.