Not able to start multiple Appium session using Appium Driver in Ruby

I am working on Android hybrid app. I am using Appium with Ruby.
I am new to Ruby and Appium.

Issue 1

If I start Appium server with port other than default port i.e. 4723, I am not able to set server path/url or Appium port.

I am using following code:

cmd Appium server

appium -a -p 4727 -bp 4728 --chromedriver-port 9517 --no-reset

Ruby Code using Appium Driver:

capabilities = {
‘platformVersion’ => ‘4.4’,
‘platformName’ => ‘Android’,
‘app’ => ‘app\path\Example-debug.apk’,
‘app-package’ => ‘com.appsample’,
‘app-activity’ => ‘.UIActivity’,
‘deviceName’ => ‘Nexus’,
‘newCommandTimeout’ => ‘300’


@driver = capabilities, url: SERVER_URL).start_driver


ERROR: Unable to connect to Appium. Is the server running? (RuntimeError)

Issue 2

On the other hand if I use Selenium WebDriver instead of Appium Driver, I am able to use desired port however I am not able to use methods like switch to web context, scroll, etc.

Code using Selenium Driver

with same capabilities as above

@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => SERVER_URL)

webview = @driver.contexts.last


undefined method `contexts’ for #<Selenium::WebDriver::Driver:0xe5fd2ce browser=:Android> (NoMethodError)

Can anyone please help me on this? Am I missing something?

I haven’t used web contexts yet, so I’ll stick to Question #1.

I use the load_appium_txt format of loading in my device capabilities.
But if you are doing it raw like you are suggesting, I think you need to add this. That should match your server port:
’appium_port’ => '4727’

I found this in $HOME/.rvm/gems/ruby-2.1.2/gems/appium_lib-7.0.0/lib/appium_lib/driver.rb
Your ruby version and appium_lib version may vary.

Thanks for suggestion shermaneric, I am using ruby 1.9.3

I added appium_port in caps and tried, facing the same issue.

Also tried by passing appium_port in in driver as:

@driver = capabilities, custom_url: SERVER_URL, appium_port: 4727).start_driver

This is also not working

Any suggestions?

Hi Nikhil,

I you have node installed in your machine, Please try node "C:\Program Files\Appium\node_modules\appium\bin\appium.js" -a -p 4727 -bp 4729 --chromedriver-port 9517 --no-reset, Please replace my appium.js Path with yours. Once server is started you will see logs like

After you see logs in terminal please verify here, URL should return something like {"status":0,"value":{"build":{"version":"1.4.0","revision":"8f63e2f91ef7907aed8bda763f4e5ca08e86970a"}}}


Yes Donald, I see the results same as mentioned by you.

However getting same error “ERROR: Unable to connect to Appium. Is the server running? (RuntimeError)” for below code

@driver = capabilities, server_url: “”).start_driver

The issue is Appium server is running on 4727 port however when I start driver using above code Appium driver checks whether Appium server running on default port instead of customized port 4727.

Hey there Nikhil_Digrase:

If it’s not too late, I would try to use the appium.txt method for loading in your device capabilities. It’s much cleaner and easier.

The SauceLabs Appium BootCamp goes over this pretty well. Albeit their latest documentation formatting for me was tougher to follow than before:

If you want to jump right to the appium.txt setup, you can skip to Chapter 5.

You can also clone the corresponding repo and open in your favorite Text Editor (I’m using RubyMine). That may help.

You’re right with your last comment. The port number in your desired capabilities is not pointing to the right appium server port number.

For sure, let me know if you have any questions. Thanks!

Hi shermaneric,

Sorry for late reply, was stuck in some other work.

I tried using appium.txt flow, still no luck; used following configuration in text file:

platformName = “Android”
deviceName = “Nexus 7”
app = “path\to\Example-debug.apk”
appPackage = “”
appActivity = “.UIActivity”
port = “4727”/appium_port=“4727”

sauce_username = false
sauce_access_key = false

Hmm that’s strange.
With appium.txt just use port (not appium_port)

Could you paste the whole appium server log into a GitHub gist for easier reading? (

Then I can have a closer look.

Also after starting appium, can you paste the results of

  1. Ps - ef | grep node
  2. Netstat -a 4727


just put url = “” in appium.txt file.

Anh_Pham, do you mean 4727 instead of 4723?

I have tried that also, getting same error

shermaneric, I am using windows machine, will try to get the relative logs and let you know

1 Like

def server_url
def capabilities_ios
‘platformName’ => ‘ios’,
‘deviceName’ => ‘iPad Air’,
‘platformVersion’ => ‘8.3’,
‘app’ => IOS_APP_PATH
end{caps: capabilities_ios,appium_lib: { server_url: server_url }}).start_driver

Sure it works now :wink:

1 Like

Anh_Pham, Thanks for reply :smile:
I am able to start appium server on appium default port: 4723 however getting error when I try to start appium driver on any other customized port viz. 4727.

Please make sure you set your customized port in Appium application.

I am facing the exact same problem, any resolutions?

fixed it by passing port to opts hash:

opts = {caps: {
platformName: ‘Android’,
udid: ENV[“UDID”],
deviceName: “Android Emulator”,

}, appium_lib: { port: “4799” }