appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.2k stars 755 forks source link

Could not start a new session #1980

Closed skibinstein closed 11 months ago

skibinstein commented 1 year ago

Do I have the most recent component updates?

Is the component officially supported by the Appium team?

Is there an existing issue for this?

Current Behavior

Hi,

I’m trying to automate android testing with github actions. When I start appium programmatically, getting the below error, but the same code works fine when I execute it on my mac.


@Login 
Scenario Outline: Unsuccessful login. - UnHappy Path                 # src/test/resources/features/Login.feature:26
Starting appium server
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
[Appium] Welcome to Appium v2.0.1
[Appium] Non-default server args:
[Appium] { address: '127.0.0.1', sessionOverride: true }
[Appium] Attempting to load driver uiautomator2...
[debug] [Appium] Requiring driver at /home/runner/.appium/node_modules/appium-uiautomator2-driver
[Appium] Appium REST http interface listener started on http://127.0.0.1:4723
[Appium] Available drivers:
[Appium]   - uiautomator2@2.29.3 (automationName 'UiAutomator2')
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
[HTTP] --> GET /status
[HTTP] {}
[debug] [AppiumDriver@1dac] Calling AppiumDriver.getStatus() with args: []
[debug] [AppiumDriver@1dac] Responding to client with driver.getStatus() result: {"build":{"version":"2.0.1"}}
[HTTP] <-- GET /status 200 5 ms - 39
[HTTP] 
[HTTP] --> GET /status
[H[   70.470878] healthd: battery l=100 v=5000 t=25.0 h=2 st=2 c=900000 fc=3000000 cc=10 chg=a
[   70.980486] binder: undelivered TRANSACTION_COMPLETE
[   70.982457] binder_cleanup_transaction: 3 callbacks suppressed
[   70.982458] binder: undelivered transaction 312840, process died.
[   71.527650] binder: 1065:1300 transaction failed 29189/-22, size 3292-0 line 2920
[   71.557773] binder: 1065:1300 transaction failed 29189/-22, size 2244-0 line 2920
[   71.580825] binder: 1065:1298 transaction failed 29189/-22, size 2560-0 line 2920
[   71.583438] binder: 1065:1300 transaction failed 29189/-22, size 3128-0 line 2920
[   71.647489] binder: 1065:1300 transaction failed 29189/-22, size 524-0 line 2920
[   71.697644] binder: 1065:1300 transaction failed 29189/-22, size 2700-0 line 2920
[   71.835995] binder: 1065:1300 transaction failed 29189/-22, size 168-0 line 2920
[   71.870918] binder: 1065:1298 transaction failed 29189/-22, size 168-0 line 2920
[   75.304376] binder_alloc: 1065: binder_alloc_buf size 1056768 failed, no address space
[   75.306733] binder_alloc: allocated: 0 (num: 0 largest: 0), free: 1040384 (num: 1 largest: 1040384)
[   75.329630] binder: 1176:3030 transaction failed 29201/-28, size 1056768-0 line 3101
[   75.369698] logd: logdr: UID=10116 GID=10116 PID=1176 n tail=0 logMask=4 pid=0 start=0ns deadline=0ns
TTP] {}
[debug] [AppiumDriver@1dac] Calling AppiumDriver.getStatus() with args: []
[debug] [AppiumDriver@1dac] Responding to client with driver.getStatus() result: {"build":{"version":"2.0.1"}}
[HTTP] <-- GET /status 200 1 ms - 39
[HTTP] 
Appium server started
getting capabilities
appUrl is/home/runner/work/app-release.apk
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 
Host info: host: 'runner', ip: '10.0.0.36'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-1042-azure', java.version: '17.0.7'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [null, newSession {capabilities=[{appium:app=/home/runner/work/app-release.apk, appium:appActivity=com.app.Mobile.MainActivity, appium:appPackage=com.app.Mobile, appium:automationName=UiAutomator2, appium:chromeDriverPort=11002, appium:deviceName=Pixel 6 API 33 5gb A13, appium:fullReset=true, appium:isHeadless=true, platformName=ANDROID, appium:platformVersion=13.0, appium:systemPort=10002, appium:udid=emulator-5554}], desiredCapabilities=Capabilities {app: /home/runner/work/tests.app..., appActivity: com.app.Mobile..., appPackage: com.app.Mobile, automationName: UiAutomator2, chromeDriverPort: 11002, deviceName: Pixel 6 API 33 5gb A13, fullReset: true, isHeadless: true, platformName: ANDROID, platformVersion: 13.0, systemPort: 10002, udid: emulator-5554}}]
Capabilities {app: /home/runner/work/tests.app..., appActivity: com.app.Mobile..., appPackage: com.app.Mobile, automationName: UiAutomator2, chromeDriverPort: 11002, deviceName: Pixel 6 API 33 5gb A13, fullReset: true, isHeadless: true, platformName: ANDROID, platformVersion: 13.0, systemPort: 10002, udid: emulator-5554}
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:536)
    at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:274)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:159)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:89)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:101)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:113)
    at org.Mobile.utilities.DriverManager.initializeDriver(DriverManager.java:29)
    at org.Mobile.stepDefinitions.Hooks.initialize(Hooks.java:19)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
    at io.cucumber.java.Invoker.invoke(Invoker.java:24)
    at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
    at io.cucumber.java.JavaHookDefinition.execute(JavaHookDefinition.java:64)
    at io.cucumber.core.runner.CoreHookDefinition.execute(CoreHookDefinition.java:46)
    at io.cucumber.core.runner.HookDefinitionMatch.runStep(HookDefinitionMatch.java:21)
    at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10)
    at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:85)
    at io.cucumber.core.runner.TestStep.run(TestStep.java:57)
    at io.cucumber.core.runner.TestCase.run(TestCase.java:78)
    at io.cucumber.core.runner.Runner.runPickle(Runner.java:75)
    at io.cucumber.junit.PickleRunners$NoStepDescriptions.lambda$run$0(PickleRunners.java:151)
    at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:129)
    at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
    at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:129)
    at io.cucumber.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:148)
    at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:144)
    at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:28)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at io.cucumber.junit.FeatureRunner.run(FeatureRunner.java:137)
    at io.cucumber.junit.Cucumber.runChild(Cucumber.java:196)
    at io.cucumber.junit.Cucumber.runChild(Cucumber.java:89)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at io.cucumber.junit.Cucumber$RunBeforeAllHooks.evaluate(Cucumber.java:266)
    at io.cucumber.junit.Cucumber$RunAfterAllHooks.evaluate(Cucumber.java:281)
    at io.cucumber.junit.Cucumber$StartTestRun.evaluate(Cucumber.java:233)
    at io.cucumber.junit.Cucumber$FinishTestRun.evaluate(Cucumber.java:248)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:364)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:272)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:237)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:158)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:428)
    at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
    at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:562)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:548)
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:182)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
    ... 58 more
  Given the asset app user is on asset app login page.                                # org.Mobile.stepDefinitions.LoginStepDefinitions.theAssetAppUserIsOnAssetAppLoginPage()
      java.lang.NullPointerException: Cannot invoke "io.appium.java_client.android.AndroidDriver.findElements(org.openqa.selenium.By)" because "this.driver" is null
    at org.Mobile.assetAppScreen.AndroidActionsPage.webElements_ById(AndroidActionsPage.java:105)
    at org.Mobile.assetAppScreen.LoginScreen.verifyTheUserIsOnTheLoginPage(LoginScreen.java:39)
    at org.Mobile.stepDefinitions.LoginStepDefinitions.theAssetAppUserIsOnAssetAppLoginPage(LoginStepDefinitions.java:26)
    at ✽.the asset app user is on asset app login page.(file:///home/runner/work/./src/test/resources/features/Login.feature:5)

  When the asset app user enter "" username.                                          # org.Mobile.stepDefinitions.LoginStepDefinitions.theAssetAppUserEnterUsername(java.lang.String)
  And the asset app user enter "" password.                                           # org.Mobile.stepDefinitions.LoginStepDefinitions.theAssetAppUserEnterPassword(java.lang.String)
  And the asset app user clicks on Continue button.                                   # org.Mobile.stepDefinitions.LoginStepDefinitions.theAssetAppUserClicksOnContinueButton()
  Then the asset app user unable to login "Please enter an email address." displayed. # org.Mobile.stepDefinitions.LoginStepDefinitions.theAssetAppUserUnableToLoginDisplayed(java.lang.String)
[   83.927455] init: processing action (persist.device_config.lmkd_native.thrashing_limit_critical=*) from (/system/etc/init/lmkd.rc:44)
[   83.931066] init: processing action (lmkd.reinit=1) from (/system/etc/init/lmkd.rc:10)
[   83.932961] init: starting service 'exec 23 (/system/bin/lmkd --reinit)'...
[   83.988500] init: Service 'exec 23 (/system/bin/lmkd --reinit)' (pid 4996) exited with status 0 oneshot service took 0.053000 seconds in background
[   83.991767] init: Sending signal 9 to service 'exec 23 (/system/bin/lmkd --reinit)' (pid 4996) process group...
[   83.995780] libprocessgroup: Successfully killed process cgroup uid 0 pid 4996 in 1ms
[   84.369125] init: Unable to set property 'persist.device_config.tethering.bpf_net_maps_enable_java_bpf_map' from uid:1000 gid:1000 pid:568: SELinux permission check failed
[   84.373512] type=1107 audit(1691492585.057:8): uid=0 auid=4294967295 ses=4294967295 subj=u:r:init:s0 msg='avc: denied { set } for property=persist.device_config.tethering.bpf_net_maps_enable_java_bpf_map pid=568 uid=1000 gid=1000 scontext=u:r:system_server:s0 tcontext=u:object_r:default_prop:s0 tclass=property_service permissive=0

Expected Behavior

Appium server starts a new session.

Minimal Reproducible Example

public class ServerManager {
  private static final ThreadLocal<AppiumDriverLocalService> server = new ThreadLocal<>();

  public AppiumDriverLocalService getServer() {
    return server.get();
  }

  public void startServer() {
    System.out.println("Starting appium server");
    AppiumDriverLocalService server = MacGetAppiumService();
    server.start();
    if (server == null || !server.isRunning()) {
      System.out.println("Appium server not started. ABORT !!!!");
      throw new AppiumServerHasNotBeenStartedLocallyException(
              "Appium server not started. ABORT !!!!");
    }
    ServerManager.server.set(server);
    System.out.println("Appium server started");
  }

  public AppiumDriverLocalService getAppiumServerDefault() {
    return AppiumDriverLocalService.buildDefaultService();
  }

  public AppiumDriverLocalService WindowsGetAppiumService() {
    GlobalParams params = new GlobalParams();
    return AppiumDriverLocalService.buildService(
            new AppiumServiceBuilder()
                    .usingAnyFreePort()
                    .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                    .withLogFile(
                            new File(
                                    params.getPlatformName()
                                            + "_"
                                            + params.getDeviceName()
                                            + File.separator
                                            + "Server.log")));
  }

  public AppiumDriverLocalService MacGetAppiumService() {
    GlobalParams params = new GlobalParams();
    HashMap<String, String> environment = new HashMap<String, String>();
    environment.put(
            "PATH",
            "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:"
                    + System.getenv("PATH"));
    environment.put("ANDROID_HOME", "/usr/local/lib/android/sdk");
    environment.put(
            "JAVA_HOME", "/opt/hostedtoolcache/Java_Corretto_jdk/17.0.8-7.1/x64");
    return AppiumDriverLocalService.buildService(
            new AppiumServiceBuilder()
                    .usingDriverExecutable(new File("/opt/hostedtoolcache/node/18.17.0/x64/bin/node"))
                    .withAppiumJS(new File("/opt/hostedtoolcache/node/18.17.0/x64/lib/node_modules/appium/build/lib/main.js"))
                    .withIPAddress("127.0.0.1")
                    .usingPort(4723)
                    .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                    .withEnvironment(environment));
  }
}

Environment

Link to Appium Logs

No response

Futher Information

No response

BraveEvidence commented 1 year ago

Same issue

myselfuser1 commented 1 year ago

Same issue

subha-glitch commented 1 year ago

I too have similar issue on Windows. It was working a few days back.

[RemoteTestNG] detected TestNG version 7.4.0 [Configuration] [WARN] Detected a static method [BaseTR.TestEngineTR.startSuite()]. Static configuration methods can cause unexpected behavior. Aug 17, 2023 3:27:12 PM BaseTR.TestEngineTR startSuite INFO: Properties file loaded successfully Aug 17, 2023 3:27:12 PM BaseTR.TestEngineTR startSuite INFO: Intializing extent Reports Aug 17, 2023 3:27:12 PM BaseTR.TestEngineTR startSuite INFO: Extent report is available under the same directoryC:\Users\username\eclipse-workspace\DemoNewPOM\Reports\testReport.html SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details. FAILED: configureAppium org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Host info: host: 'TCGCGCG', ip: 'xxx.cc.ii.oo' Build info: version: '4.11.0', revision: '040bc5406b' System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1.1' Driver info: io.appium.java_client.android.AndroidDriver Command: [null, newSession {capabilities=[{appium:deviceName="Pixel2API33", platformName=ANDROID, appium:automationName=UIAutomator2, appium:app=C:\Users\subhashini_r\eclipse-workspace\DemoNewPOM\src\test\resources\ApiDemos-debug.apk}], desiredCapabilities=Capabilities {appium:app: C:\Users\subhashini_r\eclip..., appium:automationName: UIAutomator2, appium:deviceName: "Pixel2API33", platformName: ANDROID}}] Capabilities {appium:app: C:\Users\subhashini_r\eclip..., appium:automationName: UIAutomator2, appium:deviceName: "Pixel2API33", platformName: ANDROID} at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:536) at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:274) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:159) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:89) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:101) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:113) at BaseTR.TestEngineTR.configureAppium(TestEngineTR.java:210) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133) at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598) at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173) at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46) at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824) at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.testng.TestRunner.privateRun(TestRunner.java:794) at org.testng.TestRunner.run(TestRunner.java:596) at org.testng.SuiteRunner.runTest(SuiteRunner.java:377) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332) at org.testng.SuiteRunner.run(SuiteRunner.java:276) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212) at org.testng.TestNG.runSuitesLocally(TestNG.java:1134) at org.testng.TestNG.runSuites(TestNG.java:1063) at org.testng.TestNG.run(TestNG.java:1031) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) 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:182) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518) ... 32 more

=============================================== Default test Tests run: 1, Failures: 1, Skips: 0

=============================================== Default suite Total tests run: 1, Passes: 0, Failures: 1, Skips: 0

valfirst commented 1 year ago

java.lang.NoSuchMethodError: 'java.lang.String org.openqa.selenium.json.Json.toJson(java.lang.Object, int)'

@skibinstein please check compatibility matrix and make sure you use compatible binaries: https://github.com/appium/java-client#compatibility-matrix

ashwithpoojary98 commented 12 months ago

@subha-glitch @skibinstein, Please try adding basepath to the builder argument. .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub")

almayenn commented 11 months ago

@skibinstein

Sometimes is useful to install jdk 15, please try with that.

bejaoui13 commented 3 weeks ago
  java.lang.NullPointerException: Cannot invoke "io.appium.java_client.android.AndroidDriver.findElements(org.openqa.selenium.By)" because "this.driver" is null