Running appium programatically in mac terminal using Java - ios-ui-automation

I want to start appium server programatically in mac using Java.
Can any one help me how to write the code to start appium.
Thanks..

You can launch appium server programmatically with below piece of code.
appium = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
.usingPort(4723).withIPAddress("127.0.0.1"));
appium.start();
If you want to launch from terminal you can run below command
/Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js
If you want to specify the simulator and app details etc you can run below command.
node /Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js --address 127.0.0.1 --port 4723 --full-reset
--device-name "iPhone 6"
--platform-name iOS
--platform-version "8.3"
--app "/My.app"
--browser-name iOS
For this the node executable should be added to the path.
For starting appium 1.5.3 go through below link.
starting appium 1.5.3 programmatically

This line will start appium:
Runtime.getRuntime().exec("appium");
Bonus - The next loop will wait until there will be a message from the executed command
(Please note that It doesn't check the output itself, it just waits until there is one - it works great for me)
while ((stdInput.readLine()) == null) {
Thread.sleep(1000);
}
After this you can continue with running the project knowing that the Appium server has started

Try following:
AppiumDriverLocalService appiumServer = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js"))
.usingPort(4723).withIPAddress("127.0.0.1"));
appiumServer.start();

Related

My UIautomator is not starting in mac. I have done everything possible

I am learning appium and I have set up everything that is required. I have setup paths, installed android studio, run appium and created a virtual android device too. But when i am writing uiautomatorviewer its giving me an error
mac#Macs-MacBook-Pro ~ % uiautomatorviewer
-Djava.ext.dirs=/Users/mac/Library/Android/sdk/tools/lib/x86_64:/Users/mac/Library/Android/sdk/tools/lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
mac#Macs-MacBook-Pro ~ %
Can anyone help me please
A. I encountered this issue once, sometime env var doesn't load and it throws error, open and load bash profile and run that command.
open ~/.bash_profile
source ~/.bash_profile
uiautomatorviewer
B. if appium server is running, try to close it and run the command.
Try the following command:
sudo ./uiautomatorviewer

Test instrumentation process crashed - where is the .txt file?

Sometimes, while Espresso testing, I see the following exception.
Test instrumentation process crashed. Check package_name.TestName#methodName.txt for details
Where is this .txt file stored? I can't seem to find it anywhere.
Use Case
In Jenkins (CI), I want the logs to see exactly what stacktrace caused the crash.
If you are working with an emulator, in A.S open Device File Explorer and go to:
/data/user_de/0/android.support.test.orchestrator/files/, then you can look for a particular file there
EDIT: June 25 - 2019 >> If you have updated to AndroidX dependencies, then the .txt file is located in
/data/user_de/0/androidx.test.orchestrator/files/
In my case, it was simpler to just check Logcat, rather than listen to that recommendation
For others encountering this issue, as #antek pointed out the files might not be accessible on a non-rooted device. You might try using an emulator running a non-Google Play API where you can obtain a root shell.
adb root
adb shell
ls /data/data/androidx.test.orchestrator/files
Alternatively, you could try running the tests using the debugger.
I could not find the text file, but I was able to get logcat and view the fatal that caused the orchestrator to crash
first I clear the logcat
adb logcat -c
then I run the test, then I grab the logcat
adb logcat > ~/Desktop/logcat
then I open logcat file and search for string FATAL
I just did wipe data in Android studio for my emulator using Device manager.
Restarted the emulator and run the test works for me

Is it possible to run my meteor tests in docker?

Once I've built my container with my Meteor app in it, I'd really like to be able to go
docker run me/myapp velocity test-app --ci --once --settings settings-test.json
And have it exit with 0 if successful, in which case I'll push it to docker hub, deploy it somewhere etc.
However when I try this it just hangs:
[velocity] is in continuous integration mode
[velocity] mocha is starting a mirror at http://localhost:56381/.
[velocity] *** Meteor Tools is installing ***
This takes a few minutes the first time.
[velocity] You can see the mirror logs at: tail -/app/.meteor/local/log/mocha.log
I'm using jasmine as per https://github.com/meteor-velocity/velocity-examples (I started with Mocha, but switched over to see if it made any difference).
Inspecting my .meteor/local/log files I find jasmine-client- unit.log has this at the bottom:
WARN [watcher]: [39m Pattern "/app/tests/jasmine/client/unit/**/*-+(stub|stubs|mock|mocks).+(js|coffee|litcoffee|coffee.md)" does not match any file.
WARN [karma]: [39m No captured browser, open http://localhost:9876/
INFO [karma]: [39m Karma v0.13.9 server started at http://localhost:9876/
INFO [launcher]: [39m Starting browser Chrome
ERROR [launcher]: [39m No binary for Chrome browser on your platform.
Please, set "CHROME_BIN" env variable
Parent process ( 725 ) is dead! Exiting jasmine-client-unit
Chrome clearly isn't going to be available in docker - should phantomjs be installed at this point and specified as a the running option? I would have expected this to be the case by default if the --ci option has been specified?
Thanks.
Ideally you should be using a real browser such as Chrome or Firefox to do automated testing, not PhantomJS. You can run browsers headlessly using Xvfb.
These might be useful:
http://codeutopia.net/blog/2013/07/13/headless-chromefirefox-testing-in-nodejs-with-selenium-and-xvfb/
http://elementalselenium.com/tips/38-headless
Selenium is the way to go for testing. IMO the best setup would be to use a CI server like Jenkins or TeamCity, with Xvfb installed, and have a test/deploy shell script in Jenkins such as:
#!/bin/sh
set -ex
cd $WORKSPACE
export VELOCITY_CI=1
meteor --test --settings $WORKSPACE/.deploy-staging/settings.json
cd .deploy-staging
mupx setup
mupx deploy
(Note that Xvfb is not implemented here, though). This test is not entirely working, I have yet to jump into Xvfb myself, though I know this is the right direction.
I'm using mupx to deploy my apps, which automatically creates a Docker instance on the remote server for me and handles deployment completely.

Jenkins & TestNG start browsers

Is it possible to make Jenkins use actual browser instead of headless browser? I a running some tests written in TestNG (using Selenium webdriver). When I run the testng.xml file in Eclipse, the browser starts and the tests run. But when I use Jenkins and run the tests with maven, it doesn't start any browsers.
If your jenkins is hosted in a Windows machine, there are some special configurations you should know about services that are allow to use the interface.
By the way, the easiest way to see the browsers running is starting jenkins using the command line:
java -jar jenkins.war
In linux you could use the same command or use xvfb plugin to run browsers in background.
Hope helps
In addition to this, the main reason for not launching the browser is JNLP (java network launch protocol) , when we execute the war we can interact with the desktop applications.
Using Selenium Grid will allow you to execute the test on Jenkins but open the browser on a remote slave.
To achieve this you need to create an instance RemoteWebdriver than ChromeDriver, IEDriver etc I
For linux. If jenkins is running as a daemon, you could specify active display to connect to and run your browser on it. Check what display you could connect to:
ps e | grep -Po " DISPLAY=[\.0-9A-Za-z:]* " | sort -u
My output is:
DISPLAY=:10.0
DISPLAY=:2
DISPLAY=:2.0
Then go to your jenkins project -> Configure -> Build and add the next string above your main build configuration through "Add build step -> Execute shell"
/bin/bash -c "export DISPLAY=:10"
Edited: I've encountered the issue again recently. To resolve it:
I've given for the jenkins' user ability to interact with the desktop of my current user:
xhost +si:localuser:jenkins
so if I connect to my linux system through ssh using jenkins' user credentials, export display of my current user (export DISPLAY=:10) and run, for example google-chrome or firefox inside of putty's terminal, they are launching on my current user's desktop.
After this I've checked If I could start "mvn test" command inside of workspace/MyTests folder from my putty so it will start browser and execute tests.
At the end I've created simple script in the root of my current user:
vi ~/.startup.sh
#!/bin/bash
xhost +si:localuser:jenkins
and added it to my Xfce4 GUI: Application -> Settings -> Session and Startup -> Application Autostart, specifying command field as:
sh -c $HOME/.startup.sh
It's because of this script should work only when desktop is loaded to share my current user's display with jenkins' user. After reboot and connecting to this server through RDC desktop loads with xhost command applied. And after this jenkins could interract with desktop even when I close the RDP connection but leaving current user's session alive.
I've removed Build step in my jenkins' project configuration that was stated "Invoke top-level Maven targets". It could not start my browsers.
I've changed my "Add build step -> Execute shell" to:
export DISPLAY=:10
cd /var/lib/jenkins/workspace/MyTests
mvn test
I've tried grid also, turning selenium-server-standalone -hub and -node into daemons. But it was slower than launching browsers with WebDriver in the such way.

Jenkins stops at Launching Internet Explorer

we are using Jenkins as CI in our project. We were running the CI from the command line using the following command
java -jar C:\\jenkins\\jenkins.war --httpPort=8085 --ajp13Port=8009
As the system needs to restart frequently, we change CI to start as a windows service.
Now we are facing the issues for Selenium test cases. Selenium test cases are not running after we make Jenkins as service. We are getting the following log and no more progress from that point
18:36:30,718 INFO [org.openqa.selenium.server.SeleniumDriverResourceHandler] Command request: getNewBrowserSession[*iexploreproxy, http://192.168.132.105:8080/, ] on session null
18:36:30,718 INFO [org.openqa.selenium.server.BrowserSessionFactory] creating new remote session
18:36:30,796 INFO [org.openqa.selenium.server.BrowserSessionFactory] Allocated session 80b95d0273ac4ea4a82860c79438f071 for http://192.168.132.105:8080/, launching...
18:36:30,796 INFO [org.openqa.selenium.server.browserlaunchers.WindowsProxyManager] Modifying registry settings...
18:36:31,781 INFO [org.openqa.selenium.server.browserlaunchers.InternetExplorerCustomProxyLauncher] Launching Internet Explorer...
Per hudson wiki, you should be running Hudson (or jenkins) as tasks rather than service for GUI testing. Check here. Look at the section GUI Testing in Windows
Following changes will resolve the problem
Update the selenium version.
Use *iexploreproxy or *piiexplore for IE instead of *iehta/*iexplore