appium / appium/java-client

ListensToLogcatMessages.class function startLogcatBroadcast improvement

Open
#1,352 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.3k
Forks
752
Avg merge
6d 21h
Merged PRs (30d)
8

Description

The problem

I tried using the 'addLogcatMessagesListener' for the appium Android Driver but it failed with an exception that it can not connect. Only after I looked into the issue more deeply I noticed, that the default port is hardcoded into the startLogcatBroadcast function. I think this is really confusing and unnecessary.

    default void startLogcatBroadcast() {
        this.startLogcatBroadcast("localhost", 4723);
    }

    default void startLogcatBroadcast(String host) {
        this.startLogcatBroadcast(host, 4723);
    }

However, it is possible to use this to not use the default host and port:

    default void startLogcatBroadcast(String host, int port) {
        this.execute("executeScript", ImmutableMap.of("script", "mobile: startLogsBroadcast", "args", Collections.emptyList()));

        URI endpointUri;
        try {
            endpointUri = new URI(String.format("ws://%s:%s/ws/session/%s/appium/device/logcat", host, port, ((RemoteWebDriver)this).getSessionId()));
        } catch (URISyntaxException var5) {
            throw new IllegalArgumentException(var5);
        }

        this.getLogcatClient().connect(endpointUri);
    }

What I do not get is why ListensToLogcatMessages.class doesn't simply use the host and port by the driver calling this class/function? Is there even a point in doing logcatListening to another appium service besides the one used by the driver?
Is there a reason why this should not be automated?
Imho what it should do is this:

    default void startLogcatBroadcast() {
        URL remoteAdress = this.getRemoteAddress();
        this.startLogcatBroadcast(remoteAdress.getHost(), remoteAdress.getPort());
    }

Environment

  • Appium version (or git revision) that exhibits the issue: 1.17.1
  • Desktop OS/version used to run Appium: Manjaro
  • Mobile platform/version under test: Android
  • Real device or emulator/simulator: emulator
  • Appium CLI or Appium.app|exe: CLI

Details

Code To Reproduce Issue [ Good To Have ]

For testing the addLogcatMessagesListener I took this code:
https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/android/AndroidLogcatListenerTest.java

For creating the appium service I used this code (which will always uses any free port it finds):

    public static URL createAppiumService() {
        AppiumServiceBuilder builder = new AppiumServiceBuilder();
        builder.usingAnyFreePort();
        builder.withArgument(GeneralServerFlag.LOG_LEVEL, LogLevel);
        builder.withArgument(GeneralServerFlag.LOG_TIMESTAMP);
        builder.withArgument(GeneralServerFlag.RELAXED_SECURITY);
        appium = AppiumDriverLocalService.buildService(builder);
        appium.start();
        Assert.assertTrue(appium.isRunning(), "Der Appium Server läuft nicht!");
        return appium.getUrl();
    }

The driver can then be initialized like so:

AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(createAppiumService(), _YourDesiredCapsHere_);

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ListensToLogcatMessages.class and the AndroidLogcatListenerTest.java test referenced in the issue. Run the listener test with an Appium service on a dynamically assigned port, then inspect how the driver exposes its remote address. Done means the no-argument broadcast method uses the driver's host and port while the explicit overloads retain their behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.