How to Start Appium Sever Pogrammatically With Custom Environments Using NodeJS

Hi,

I am starting appium server using the code below

const appium = require('appium')
server = appium.main(myCapabilities);

Appium server starts on “127.0.0.1:{{myCapabilities.port}}/wd/hub”. It’s OK but my appium process using different Environment variables then mine. I can see it when I run command below

ps -wwE -p {{processID_of_Appium}}

The partitial output of command is

PATH=/usr/bin:/bin:/usr/sbin:/sbin

When I run command “echo $PATH”, I get output below

/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

Conclusion:
When I try to start my test on “127.0.0.1:{{myCapabilities.port}}/wd/hub”, I get the error below

Original error: Unable to launch WebDriverAgent because of xcodebuild failure: not found: carthage.

My carthage is in /usr/local/bin/

How can I start appium server with custom environments using nodejs?

Add /usr/local/bin/ to PATH

I’ve already added. This is my output when I run command “echo $PATH”


But appium process still see
“PATH=/usr/bin:/bin:/usr/sbin:/sbin”

Is this running from command line or an IDE? If IDE, which one?

If command line, which shell? Also, how are you adding to your $PATH? For example you might add an 'export $PATH ’ statement to .bash_profile if you are using bash.

I deployed software using electron-packager. So, not from an IDE or terminal.

Additional info: If I run my code using terminal(npm start), appium process see my $PATH as “/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin”.

I am coding on VS Code.

Also, this is inside of my bash_profile
11

I did a quick web search on this. According to this page you need to set the variables in .bashrc. You should do an ‘echo $SHELL’ on your command line to make sure you aren’t on ZSH (latest version of os x uses this) in which case you would want to put them in .zshrc.

This would probably be a useful read for you:

It did not work. But I found a solution.

I am adding this code block before appReady() state.

process.env.PATH = process.env.PATH.includes(actualPath) ? process.env.PATH : actualPath + process.env.PATH;

Then everything works fine.

Thanks for posting your solution.

1 Like