Appium keep on asking for "platformName" capability even if it is added

Code to Reproduce -
public class AppiumBaseTest {

protected AppiumDriver<WebElement> driver;
AppiumDriverLocalService appiumService;
String appiumServiceUrl;

String platform;

    @BeforeTest

    public void setup() throws Exception {


        Properties prop = new Properties();
        InputStream input;
        appiumService = AppiumDriverLocalService.buildDefaultService();
        appiumService.start();
        appiumServiceUrl=appiumService.getUrl().toString();
        System.out.println("Appium server started at " +appiumServiceUrl);
        //platform=prop.getProperty("platform");

        try {

        input = new FileInputStream("src/test/java/Utils/appiumSession.properties");
        prop.load(input);

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("automationName", prop.getProperty("automationName"));
        capabilities.setCapability("platformName",prop.getProperty("platformName"));
        capabilities.setCapability("platformVersion", prop.getProperty("platformVersion"));
        capabilities.setCapability("deviceName", prop.getProperty("deviceName"));
        capabilities.setCapability("app", prop.getProperty("app"));
        capabilities.setCapability("newCommandTimeout", "60");


        /* Checking the platform */

       platform = prop.getProperty("platform");
        if (platform.equals("ANDROID")) {

         driver = new AndroidDriver(new URL(appiumServiceUrl),capabilities);
        } else if (platform.equals("IOS")) {
            driver = new IOSDriver<WebElement>(new URL(appiumServiceUrl), capabilities);
            driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);


        } else {
            throw new Exception("Unable to read platform");
        }

Appium shows
Appium] Capabilities:
[Appium] app: ‘/Users/piyushkumar/Desktop/apk/SignUpApp-qa-release-2.6-unaligned.apk’
[Appium] newCommandTimeout: ‘60’
[Appium] platformVersion: ‘5.1.1’
[Appium] automationName: ‘Appium’
[Appium] platformName: ‘Android’
[Appium] deviceName: ‘Galaxy Nexus API 22’

**Then it shows **
[MJSONWP] Encountered internal error running command: Error: You must include a platformName capability
at AppiumDriver.getDriverForCaps (…/…/lib/appium.js:44:13)
at AppiumDriver.createSession$ (…/…/lib/appium.js:157:28)

**Finally it throws **
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{app=/Users/piyushkumar/Desktop/apk/SignUpApp-qa-release-2.6-unaligned.apk, newCommandTimeout=60, platformVersion=5.1.1, automationName=Appium, platformName=Android, deviceName=Galaxy Nexus API 22}], required capabilities = Capabilities [{}]
Build info: version: ‘3.4.0’, revision: ‘unknown’, time: ‘unknown’
System info: host: ‘Piyushs-MacBook-Pro.local’, ip: ‘fe80:0:0:0:1876:bc3c:b563:7490%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.12.4’, java.version: ‘1.8.0_144’
Driver info: driver.version: AndroidDriver

at io.appium.java_client.remote.AppiumProtocolHandShake.lambda$1(AppiumProtocolHandShake.java:96)
at java.util.Optional.orElseThrow(Optional.java:290)
at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:96)
at io.appium.java_client.remote.AppiumCommandExecutor.doExecute(AppiumCommandExecutor.java:111)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:162)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
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.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:88)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:112)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:73)
at Tests.AppiumBaseTest.setup(AppiumBaseTest.java:74)

**Line 74 is ** - driver = new AndroidDriver(new URL(appiumServiceUrl),capabilities);

Pom is -
io.appium
java-client
5.0.0-BETA8

capabilities.setCapability(“platformName”,prop.getProperty(“platformName”));

are you sure the property key is platformName ?
coz in the /* Checking the platform */ block you are using prop.getProperty(“platform”);

Yes , I have two different keys “platformName” as capability . “platform” is to check whether it is android or ios.

Also the appium logs shows -
Appium] Capabilities:
[Appium] app: ‘/Users/piyushkumar/Desktop/apk/SignUpApp-qa-release-2.6-unaligned.apk’
[Appium] newCommandTimeout: ‘60’
[Appium] platformVersion: ‘5.1.1’
[Appium] automationName: ‘Appium’
[Appium] platformName: ‘Android’ - This means it got platform name as capability right ?
[Appium] deviceName: ‘Galaxy Nexus API 22’

@Piyush_Kumar1 try:

// for Android:
capabilities = DesiredCapabilities.android();

// for iOS
capabilities = DesiredCapabilities.iphone();
// or
capabilities = DesiredCapabilities.ipad();

and other no change

also with debug Appium logs take a look before “You must include a platformName”. normally real reason is there.

It seem it was an issue with the appium & selenium versions compatibility.

Now am getting -

debug] [AndroidDriver] Getting Java version
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Called deleteSession but bootstrap wasn’t active
[MJSONWP] Encountered internal error running command: Error: Command ‘java -version’ exited with code 20
at ChildProcess. (…/…/lib/teen_process.js:70:19)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:920:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5)
[HTTP] <-- POST /wd/hub/session 500 48 ms - 180

And lastly throws excpetion -

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Command ‘java -version’ exited with code 20 (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 122 milliseconds

AnyOne has the soltution

platformName is not necessary as you are already defining AndroidDriver, so by default it will run for Android.
Add androidCapabilities.setCapability(“automationName”, “uiautomator2”);

1 Like

I already have [Appium] automationName: ‘Appium’
Is this not enough ?

I’d this issue too, what was happening was related to the bad device name, try changing it, verify that the name of your device is the same also for platform version.

@Piyush_Kumar1 this confusing error is not actually shows problem. problem is somewhere in other place. e.g. what @krantos mentioned. look at appium log slightly above. real problem should be there.

Okay , So if i look at the logs it says ,

[debug] [UiAutomator2] Deleting UiAutomator2 session
[UiAutomator2] Unable to remove port forward ‘Cannot read property ‘removePortForward’ of undefined’
[MJSONWP] Encountered internal error running command: Error: Command ‘java -version’ exited with code 20
at ChildProcess. (…/…/lib/teen_process.js:70:19)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:920:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5)
[HTTP] <-- POST /wd/hub/session 500 52 ms - 180
**Also my appium server is starting at **
Appium server started at http://0.0.0.0:4723/wd/hub . Is it supposed to be at 127.0.0. ?

Yes, it can start at 0.0.0.0 or 127.0.0.0 too, try to use Appium Desktop and open the inspector, there you can check more quickly your capabilities.

→ Error while starting a new session: · Issue #8822 · appium/appium · GitHub

2 Likes

All this time and this . Many thanks @Aleksei

Hi guys , i am getting below error while automating the appium script

Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: You must include a platformName capability (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 107 milliseconds

my script

package Maven_appium;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class ex11 {

static AppiumDriver<MobileElement> driver1; // this future are more specific for appium mobile Testing


public static void main(String[] args) throws Exception {
	try {
		opencal(); // calling the method
	} catch (MalformedURLException e) {

		System.out.println(e.getMessage());
		System.out.println(e.getCause());

		e.printStackTrace();
	}

}

public static void opencal() throws Exception {

	

	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("deviceName", "HUAWEI VNS-L31"); // model number:HUAWEI VNS-L31
	capabilities.setCapability("udid", "4TE7N16B25004195"); // udid: device id go to C:\Users\PAVAN\AppData\Local\Android\Sdk\platform-tool --> type cmd --> type adb devices (it shows list of devices)
	capabilities.setCapability("PLATFORM_NAME", "Android");
	capabilities.setCapability("PLATFORM_VERSION", "6.0");
	capabilities.setCapability("apppackage", "com.android.calculator2"); // com.android.calendar : this is
																			// calculator package name
	capabilities.setCapability("appActivity", "com.android.calculator2.Calculator"); 
	
	URL url = new URL("http://127.0.0.1:4723/wd/hub "); // http://127.0.0.1:4723/wd/hub : 4723-port no

	driver1 = new AppiumDriver<MobileElement>(url, capabilities);
	System.out.println("appilcation started...");
	

}

}

I don’t see, ‘platformName’ anywhere in your capabilities. Have you thought about the idea that the error you are getting is exactly the problem?

You don’t post the log, but it may have an entry that calls out ‘PLATFORM_NAME’ as an unknown capability.

Please see here for a list of capabilities:

https://appium.io/docs/en/writing-running-appium/caps/