Skip to content

Double Slash in Appium Endpoint URL When path Ends with Slash causing 404 Errors #4865

Closed
@mjalav

Description

@mjalav

The _buildAppiumEndpoint() function constructs the Appium REST API endpoint URL using path from this.browser.options. However, if path ends with a trailing slash (/), it results in a double slash (//) in the final URL before "session".

Steps to Reproduce:
Set path as '/' in this.browser.options:

this.browser.options = {
    protocol: 'http',
    hostname: '127.0.0.1',
    port: 4723,
    path: '/' // Root path with a trailing slash
};
this.browser.sessionId = '123456';

Call _buildAppiumEndpoint().

The generated URL will be:
http://127.0.0.1:4723//session/123456
Issue: The double slash (//session/) cause API request failures with 404 error.

Resolution:
Modify _buildAppiumEndpoint() to remove any trailing slash from path before constructing the URL.

Fix:

_buildAppiumEndpoint() { 
    const { protocol, port, hostname, path } = this.browser.options;
    // Ensure path does NOT end with a slash to prevent double slashes
    const normalizedPath = path.replace(/\/$/, '') || '';  
    return `${protocol}://${hostname}:${port}${normalizedPath}/session/${this.browser.sessionId}`;
}

Fixed Output (Corrected URL):
http://127.0.0.1:4723/session/123456
**
✅ Now, the API request will work as expected without double slashes. 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions