How to start Appium server programatically in mac using ruby ? - appium

Is there a way I can get appium to startup within the code? I am trying to automate an iOS application, Since appium only needs to run when my test is running it doesnt make sense to me to keep the appium server always going.
Right now I am using Appium GUI to start server.Is it possible to add something in Before method to start the appium server before connecting the WebDriver to it, and then terminating it in the After method.
Please help me to do it in Mac using Ruby.
Appium server version: 1.8.0
Mac OS: 10.13
node: 6.11
Ruby: 2.5.1
Thanks in advance,

Here is solution for BDD framework written Ruby. Paste these two hooks in hooks.rb file
Starting the server:
AfterConfiguration do |config|
pid = spawn ‘appium --address 0.0.0.0 --port 4723’
Process.detach(pid)
sleep(10)
end
AfterConfiguration hook that will be run after Cucumber has been configured. This hook will run only once,after support has been loaded but before features are loaded. so it is usefull to launch Appium server.
Stoping the server:
at_exit do
exec ‘/usr/bin/killall -KILL node’
end
at_exit will be executed after execution of all the feature files. So executing exec '/usr/bin/killall -KILL node' command inside this hook kills the server at the end

call shell commands from inside of a Ruby program.
`/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --selendroid-port 8082 --no-reset --local-timezone`
change the path accordingly or copy the appium app to Applications folder

Related

Start Appium on jenkins and wait for it to fully complete startup

I m setting up jenkins to run appium scripts. The issue I am seeing is if I run main.js to start appium the jenkins will not execute next commands and if I put appium in background next statements are executed immediately. Is there any way to start appium in background and wait for it to complete? and also once test execution complete how will I stop appium if appium process is in background?
Thanks in Advance
Shrikanth
You can create one folder called build and put your application in same folder and create a batch file using following commands :
cd /d C"":\Program Files (x86)\Appium\node_modules""
node appium --address 127.0.0.1 --port 4723 --app C:\Build\Application.apk --pre-launch --platform-name Android --platform-version 23 --automation-name Appium --device-name "DEVICEID" --log-no-color
Trigger this batch file from Jenkins and give wait of 20000 millisecond before running your test script.

Fitnesse - Remote debug error

I'm trying to enable remote-debugging with fitnesse. Getting below error.
Could not complete testing: java.lang.Exception: FitClient: external
process terminated before a connection could be established.
To start fitnesse in debug-mode, i'm adding below startup command
set DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9000
java -jar %DEBUG_OPTS% fitnesse-standalone.jar -p 81
And with this, able to connect to the Fitness process, but enabling Tools->Remote Debug from Fitnesse GUI gives above error. Any pointers?
FitNesse is starting the System under test in a separate process by default. You can execute the test suite with debugging enabled, e.g. "MySuite?suite&debug".
Make sure all required libraries are on your class path (the one you use to start FitNesse "java -cp jar1.jar:classes:fitnesse-standalone.jar fitnesseMain.FitNesseMain -p 81"), since your application will be started inside the FitNesse process.

Starting Erlang service at boot time (using Relx for creating release)

I have a server written in Erlang, compiled with Rebar, and I make a release with Relx. Starts nicely with
/root/rel/share3/bin/share3 start
The next step is to start when the server boots.
I have tried different approaches, the last one is using the /etc/init.d/skeleton where I changed the following
NAME=share3
DAEMON=/root/rel/share3/bin/share3
DAEMON_ARGS="$1"
After that, I run update-rc.d, but I have not gotten it too work. (Ubuntu 14.04)
The service runs until the machine reboots, and I need to login and start it again.
For Windows, it is really elegant, since it can create the Windows service.
Ubuntu uses upstart as init system, so you could try something like that:
description "Start my awesome service"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /root/rel/share3/bin/share3
You have to place this script in /etc/init/ directory with '.conf' extension like '/etc/init/share3.coinf'. To start it invoke sudo start share3.
At last, I solved it!
I have told to relx to place the result at /home/mattias/rel. The script from relx is /home/mattias/rel/share3/bin/share3
Replace the row
SCRIPT_DIR="$(dirname "$0")"
by (you need to fix the path /home/mattias/rel)
HOME=/home/mattias
export HOME
SCRIPT_DIR="/home/mattias/rel/share3/bin"
Copy the file to /etc/init.d/share3 using
sudo cp ~/rel/share3/bin/share3 /etc/init.d/
Test that it works using
/etc/init.d/share3 start
and
/etc/init.d/share3 stop
In order to make it start at boot, install sysv-rc-conf
sudo apt-get install sysv-rc-conf
Enable boot at start using
sudo sysv-rc-conf share3 on
and disable
sudo sysv-rc-conf share3 off
Alternatives are welcome.

Ruby (Rack) application could not be started error message

my ruby application was working fine until earlier this week, the system crashed, and now I get an error message on the page...
Error message:
Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)
Exception class:
PhusionPassenger::UnknownError
Application root:
/home/deploy/www/gm-git
The system is set up as such...
• Ruby on Rails 3.0.8
• Mongoid 2.0.2
• Redis & Resque for background processing
I have tried the following boot sequence but withou success...
/opt/redis/redis-server
/opt/mongodb/bin/mongod --force --logpath /opt/mongodb/bin
rake environment rescue:workers
touch /home/proyectos/gm/test_git/goldenmile
I have updated this many times to for example
/opt/redis/redis-server
/opt/mongodb/bin/mongod --fork --logpath /opt/mongodb/bin
/opt/mongodb/bin/mongod --repair
rake environment rescue:workers
touch /home/proyectos/gm/test_git/goldenmile
But I get error messages in the terminal such as
/opt/mongodb/bin/mongod --start
ERROR: unknown option start
/opt/mongodb/bin/mongod --status
ERROR: unknown option status
/opt/mongodb/bin/mongod start
Invalid command: start
/opt/mongodb/bin/mongod/ --logpath /opt/mongodb/bin
-bash: /opt/mongodb/bin/mongod/: Not a directory
/opt/mongodb/bin/mongod/ --logpath /opt/mongodb/bin/mongod/
-bash: 2b.: command not found
/opt/mongodb/bin/mongod/ --logpath /opt/mongodb/bin/mongod
-bash: /opt/mongodb/bin/mongod/: Not a directory
Any help/directions would be most useful
The Mongo::ConnectionFailure error for localhost:27017 is typical when mongod is not running. You should check for this using the ps command, restart mongod if necessary, and then run the mongo shell. If the mongo shell reports "Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84" then go back and check the status of your mongod server process.
The following lines are suspicious.
/opt/mongodb/bin/mongod --fork --logpath /opt/mongodb/bin
/opt/mongodb/bin/mongod --repair
It appears that you are trying to run the mongod server and repair at the same time. The repair attempt will bail out if mongod is already running, and I'm guessing that you really intended to run it before starting db service. If you are on a 64-bit platform, journaling is on by default and you should not do a repair to recover a consistent state, see http://www.mongodb.org/display/DOCS/Durability+and+Repair
Also, repair can take a long time, and during this time, you cannot start another mongod for db service. I suspect that this is your underlying problem - that repair was running, causing attempts to start db service to fail.
Regardless, it appears that mongod is not running. Options like --start, --status, start are all unknown as stated, and mongod also prints a full list of options for each of these errors. Having a trailing slash after a shell command (after mongo) is telling the OS to look for a directory. Did you try to execute mongod in the shell with no options? What happens? You need to get mongod running as a db server (not repair) and should verify that it is up and that you can connect using the mongo shell before you go any further.
Let us know how it works out.

Run ruby script in background without using screen

I have a two scripts in the Rails environment which have to run 24/7. I'm working on a remote server, so I need to start the scripts using ssh, which means I need to keep the ssh windows open all the time.
I'm searching for a simple way to run these scripts in the background so they aren't canceled as soon as I close the ssh connection.
I don't want to use screen. I think there must be simpler way to handle this. Isn't there?
I think the most basic solution would be nohup:
nohup myscript &> /dev/null &
You can disown a script:
ruby script.rb &!
STDOUT/STDERR are still attached to the current shell, but the ruby process isn't a child of the shell anymore, so it won't get killed if you close the terminal.
Check Daemons. It's a toolkit for converting a script to a controllable daemon.
You can use
runit
supervisord
For daemonizing
Or some ruby stuff: https://www.ruby-toolbox.com/#Background_Processing for background processing

Resources