Cant launch and run Appium server programmatically with C#

Im trying to launch appium and run the server programmatically with C# but I cant get it working
I can launch Appium but cant get the Appium Server running (by click the Play button)

When I manually press play to run the appium server I get the following
Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 23 --automation-name Appium --log-no-color

If this helps how do I put this into C# to run appium server?

Any help would be much appreciated!

Hi raffi,
here is the code to Run Appium server programmaticaly with C#

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = “cmd.exe”;
startInfo.Arguments = “/C C:\Appium\node.exe C:\Appium\node_modules\appium\bin\appium.js --address 127.0.0.1 --port 4723 --automation-name Appium --log-no-color”;
process.StartInfo = startInfo;
process.Start();

Hope, it will be helpful for you. :sunglasses:

Regards
@Abdul_Sathar_Beigh

Thanks for you reply Abdul
I will try first thing tomorrow morning when I get to work and will let you know…

Thanks alot!
Raffi

Hi Abdul,

I tried and still cant get it to work

Im running the following commands:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = “cmd.exe”;
startInfo.Arguments = “/C C:/Program Files (x86)/Appium/node.exe C:/Appium/node_modules/appium/bin/appium.js --address 127.0.0.1 --port 4723 --automation-name Appium --log-no-color”;
process.StartInfo = startInfo;
process.Start();

and after running the following command:

new AndroidDriver(new Uri(this.AppiumServerUri), capabilities, TimeSpan.FromSeconds(this.CommandTimeout));

Im getting this:

An exception of type ‘OpenQA.Selenium.WebDriverException’ occurred in WebDriver.dll but was not handled in user code
Additional information: Unexpected error. System.Net.WebException: Unable to connect to the remote server —> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:4723
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
— End of inner exception stack trace —
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)

Any ideas?
Raff

By the way I am trying to do this within a TestMethod in VisualStudio 2012

Try with providing actual machine address, instead of loopback address 127.0.0.1

Got it working now with the following code

            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = "C:/Program Files (x86)/Appium/node.exe";
            startInfo.Arguments = @"""C:/Program Files (x86)/Appium/node_modules/appium/bin/appium.js"" --address 127.0.0.1 --port 4723 --automation-name Appium --log-no-color";
            process.StartInfo = startInfo;
            process.Start();
            appium_started = true;

Hi Team,

I am trying to run code.But it is showing error.Can you please help me with it.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace StoreTicketingApp.AppiumSupport
{
class Appium_Test
{

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "C:/Program Files (x86)/Appium/node.exe";
     System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "C:\Users\azargar\AppData\Local\Programs\Appium\Appium.exe";
    startInfo.Arguments = @"""C:/Program Files (x86)/Appium/node_modules/appium/bin/appium.js"" --address 127.0.0.1 --port 4723 --automation-name Appium --log-no-color";
    process.StartInfo = startInfo;
    process.Start();
    appium_started = true;


}

}
Can you mail me correct code at [email protected] it need some dependency

I tried same code,its not working for me.Can you please help me :-
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Solution1

{

 class Test_Appium
{

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
     startInfo.FileName = "C:/Users/azargar/AppData/Local/Programs/Appium/Appium.exe";
     startInfo.Arguments = @"""C:/Users/azargar/AppData/Local/Programs/Appium/Appium.exe"" --address 127.0.0.1 --port 4723 --automation-name Appium --log-no-color";
      process.StartInfo = startInfo;
       process.Start();
      appium_started = true;

}

}