I need to use Appium 2 for CodeceptJS mobile tests

1.4k Views Asked by At

Because latest iOS is making problems with Appium 1.x, Appium team is no longer supporting it, and Appium 2 is working ok - I need to use v2...

CodeceptJS 3.3.x is using Appium 1.x now and because of the '/wd/path' used by default in CodeceptJS Appium helper, I can't set it to use Appium 2. When starting a test, CodeceptJS fails with:

Error: Failed to create session.
The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource

Please make sure Selenium Server is running and accessible
Error: Can't connect to WebDriver.
Error: Failed to create session.
The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource

Please make sure Selenium Server is running and accessible

And Appium 2 fails with:

[debug] [HTTP] No route found for /wd/hub/session
[HTTP] <-- POST /wd/hub/session 404 1 ms - 211

Is there a way to change the default '/wd/path' to just '/' ? Or is there another helper or something for Appium 2?

Part of the codecept.config.js file:

        Appium: {
            host: process.env.CLOUD_HOST || 'localhost',
            port: parseInt(process.env.CLOUD_PORT) || 4723,
            app: (PLATFORM_NAME === 'iOS') ? APP_PATH_IOS || 'com.mobile.beta' : APP_PATH_ANDROID,
            desiredCapabilities: {
                platformName: process.env.PLATFORM_NAME || 'iOS',
                platformVersion: process.env.PLATFORM_VERSION || '16.0',
                automationName: process.env.AUTOMATION_NAME || 'xcuitest',
                deviceName: process.env.DEVICE_NAME || 'iPhone Xs',
                appPackage: process.env.APP_PACKAGE,
                appActivity: process.env.APP_ACTIVITY,
                xcodeOrgId: process.env.XCODE_ORG_ID,
                // udid: process.env.UDID, // used only for real iOS device

            },
        },

=========================================

  • UPDATE:

I started Appium with --base-path /wd/hub (appium --base-path /wd/hub) but now another error appears:

Error: Can't connect to WebDriver.
Error: Failed to create session.
All non-standard capabilities should have a vendor prefix. The following capabilities did not have one: platformVersion,automationName,deviceName,appPackage,appActivity,xcodeOrgId,app

Please make sure Selenium Server is running and accessible

I tried updating the capabilities in codecept.conf.js with appium: prefix, but either I do it wrong or it doesn't work:

The Update:

        Appium: {
            host: process.env.CLOUD_HOST || 'localhost',
            port: parseInt(process.env.CLOUD_PORT) || 4723,
            app: (PLATFORM_NAME === 'iOS') ? APP_PATH_IOS || 'com.mobile.beta' : APP_PATH_ANDROID,
            desiredCapabilities: {
                'appium:platformName': process.env.PLATFORM_NAME || 'iOS',
                'appium:platformVersion': process.env.PLATFORM_VERSION || '16.0',
                'appium:automationName': process.env.AUTOMATION_NAME || 'xcuitest',
                'appium:deviceName': process.env.DEVICE_NAME || 'iPhone Xs',
                'appium:appPackage': process.env.APP_PACKAGE, // not needed for iOS
                'appium:appActivity': process.env.APP_ACTIVITY, // not needed for iOS
                'xcodeOrgId': process.env.XCODE_ORG_ID, // not needed for Android
                udid: process.env.UDID, // used only for real iOS device testing
            },
        },

Error:

Error: Can't connect to WebDriver.
Error: Invalid or unsupported WebDriver capabilities found ("platformVersion", "deviceName", "appPackage", "appActivity", "xcodeOrgId", "app", "tunnelIdentifier"). Ensure to only use valid W3C WebDriver capabilities (see https://w3c.github.io/webdriver/#capabilities).If you run your tests on a remote vendor, like Sauce Labs or BrowserStack, make sure that you put them into vendor specific capabilities, e.g. "sauce:options" or "bstack:options". Please reach out to to your vendor support team if you have further questions.

Please make sure Selenium Server is running and accessible

Error#2:

Error: Can't connect to WebDriver.
Error: Invalid or unsupported WebDriver capabilities found ("deviceName", "app", "tunnelIdentifier"). Ensure to only use valid W3C WebDriver capabilities (see https://w3c.github.io/webdriver/#capabilities).If you run your tests on a remote vendor, like Sauce Labs or BrowserStack, make sure that you put them into vendor specific capabilities, e.g. "sauce:options" or "bstack:options". Please reach out to to your vendor support team if you have further questions.

Please make sure Selenium Server is running and accessible
3

There are 3 best solutions below

10
drunkencheetah On

If you are starting Appium server using the CLI you can use something like appium -p 4726 --base-path /wd/hub which will make it accept requests on the old endpoint

Update: With Appium 2.0, the Appium server will enforce strict compability with the W3C WebDriver specification when it comes to Capabilities. They can be found here. Anything else that you provide for Appium should have the appium: prefix (like appium:platformVersion, appium:appPackage and so on)

0
Dimitar Hristovski On

This is most probably a problem with the CodeceptJS's Appium helper and needs to be updated to follow the Appium's more strict compability with the W3C WebDriver specification.

The update needs a support for prefixes like:

...
appium:platformName: 'iOS'
appium:automationName: 'xcuitest'
...

or

...
browserstack:platformName: 'Android'
saucelabs:automationName: 'uiautomator2'
...

for now, we can't configure variables with prefixes.

There's also no way I know of, to contact the CodeceptJS maintainers for making this update.

1
Vincent Coste On

On my side I commented these 3 lines in the Appium.js file and now it runs

//config.capabilities.deviceName = config.device || config.capabilities.deviceName;
config.capabilities.browserName = config.browser || config.capabilities.browserName;
//config.capabilities.app = config.app || config.capabilities.app;
config.capabilities.platformName = config.platform || config.capabilities.platformName;
//config.capabilities.tunnelIdentifier = config.tunnelIdentifier || config.capabilities.tunnelIdentifier;
config.waitForTimeoutInSeconds = config.waitForTimeout / 1000;