Changing port of AppiumDriver

Hi all,

I’m having trouble changing the port of the AppiumDriver. What I have is below:

caps = {
    'platformName' => 'Android',
    'deviceName' => 'ab41ecf4',
    'platformVersion' => '5.0',
    'browserName' => 'chrome'
}
$appium = Appium::Driver.new(:caps => caps, :appium_port => "4726")
puts $appium.driver_attributes

However, returned by the puts statement is:

{:caps=>{:platformName=>"Android", :deviceName=>"ab41ecf4", :platformVersion=>"5.0", :browserName=>"chrome"}, :custom_url=>false, :export_session=>false, :default_wait=>0, :last_waits=>[0], :sauce_username=>nil, :sauce_access_key=>nil, :port=>4723, :device=>:android, :debug=>false}

I’ve also tried setting custom_url, but this didn’t work either.

Any help would be greatly appreciated!

EDIT - Just in case somebody stumbles across this having the same issue, the correct syntax is below:

$appium = Appium::Driver.new(:caps => caps, :appium_lib => {'port' => '4725'})
$browser = $appium.start_driver

You have to connect to port 4723 from your test application while creating driver, as server is running on that port.

If u want to use 4726, you need to configure the server to run in that port.

Thanks RamS, but my server is already on port 4726, but my tests fails because the driver is trying to use 4723. Sorry, I should have explained better in my original post.

I think it’s just “port”, not “appium_port”. Could you give that a try?

Sorry but this doesn’t work either. Looking at the source it seems like :appium_port gets translated into :port. ruby_lib/lib/appium_lib/driver.rb at master · appium/ruby_lib · GitHub

EDIT - Just seen that it may actually be :port (source). Still doesn’t seem to be working though, port still comes back as 4723.

Can u try single quote for port value instead of double quote … this is just a try :smile:
I am just guesssing it might be taking a default value as its not getting port value …

Just tried single quotes and no luck. Thanks for a the suggestion though!

Can u please share two logs -

  1. The appium server will log Server address and port details as soon as it is launched.
  2. The error logs in appium server you are getting while trying to connect to server.

Have you tried adding it in the capabilities? I think this is the way we do it, but I’m away from the office.

This is how we do it in Java -

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "Android");
capabilities.setCapability("deviceName", "xyz");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("appPackage", "com.sec.android.app.popupcalculator");
capabilities.setCapability("appActivity", "com.sec.android.app.popupcalculator.Calculator");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

Here is the server log from start up:

Launching Appium with command: '/Applications/Appium.app/Contents/Resources/node/bin/node' lib/server/main.js --port "4726" --command-timeout "7200" --debug-log-spacing --automation-name "Appium" --platform-name "Android" --platform-version "5.0"

info: Welcome to Appium v1.4.1 (REV ce6220829063679bcccf5724515c29569c4a16d9)

info: Appium REST http interface listener started on 0.0.0.0:4726
info: [debug] Non-default server args: {"port":4726,"platformName":"Android","platformVersion":"5.0","automationName":"Appium","defaultCommandTimeout":7200,"debugLogSpacing":true}
info: Console LogLevel: debug

There is no error log for the server, as it never connects to anything, it’s just happily sitting there oblivious to anything that’s going on!

Your java solution is similar to what we have when using Selenium::WebDriver, but I wanted to use Appium::Driver so that I can use their swiping methods.

@wreed - When I add it into caps I get the following from driver_attributes:

{:caps=>{:platformName=>"Android", :deviceName=>"ab41ecf4", :platformVersion=>"5.0", :browserName=>"chrome", :port=>"4726", :custom_url=>"http://localhost:4726/wd/hub"}, :custom_url=>false, :export_session=>false, :default_wait=>0, :last_waits=>[0], :sauce_username=>nil, :sauce_access_key=>nil, :port=>4723, :device=>:android, :debug=>false}

:port is set inside caps, but not outside of it.

AppiumDriver is abstract and you can not instantiate it.

Use AndroidDriver or iOSDriver

Other difference I can see is the server address - I am using 127.0.0.1 … Can u set that value as 0.0.0.0

Well I’m then doing:

$browser = $appium.start_driver

The start_driver method created a Selenium::WebDriver object with all of the caps that Appium::Driver was created with. I think this is the correct way to use it, but I could be wrong. The Appium Driver gives access to other methods, like set_context, which aren’t available with a normal WebDriver.

Also, I should say that it works perfectly on port 4723, I just can’t change it, which means I can’t run things in parallel.

OK …

[quote=“DavidSelby, post:13, topic:4799”]
The Appium Driver gives access to other methods, like set_context, which aren’t available with a normal WebDriver
[/quote] AndoridDriver and iOSDrievr extend from AppiumDriver, hence you get all plus additional APIs.

Looking at the source, I think that might just be for Java. In Java you do have an abstract AppiumDriver class, but in Ruby it’s a full usable driver. Thanks a lot for your help though. I think I’m just going to give up for now and find another way to do the things that the driver implements!

I managed to make tha work with the commands
Appium::Driver.new(caps: capabilities, appium_lib: {port: 4001})