Running Appium recorded test - selenium

I am new to Appium. I started using the Appium app, added the simulator app file and lunched the simulator (using "launch"), as described here
I also succeed recording a test on my app and got the Ruby output (is there an PHPUnit option?).
I cannot find any good knowledge base of how can I run/use this test now? (supposed I have already created / recorded a test)
Note: the only close thing I found is this:
bundle exec cucumber features/plain_note.feature
But it uses cucumber. How can I run a simple test just recorder in the inspector?

Here's how to run your Appium Inspector saved ruby boilerplate tests.
1) Start the Appium server in terminal with this, and leave this terminal window open.
$ appium &
2) While the appium server is running in the previous terminal window, open a new terminal window and navigate to the directory where your tests are located and run them with this.
$ ruby "your_test.rb"
That should execute your Appium test you recorded with the Appium inspector.
If you have the Appium GUI running/open, you may have node issues about the same port already in use. If this happens simply run this in terminal.
$ killall node
If you don't already have the appium server installed you can install it by running this in terminal which requires npm to be installed.
$ npm install -g appium
Hope this helps.

Related

Is there any difference between start appium server via appium & command or using just appium

I can start the appium server via command line using below commands via command line since I installed the appium using npm.
appium &
appium
//To change the default port
appium & --port 9090
appium --port 9090
As I observed both commands are doing the same, so are they identical or is there any difference?
appium &
appium & runs Appium in a subshell.
Consequences:
You cannot easily quit out of that Appium session (with control + c for example.
Since you cannot quit them, you'll have to close the entire terminal to close the session so you may run into more errors like this:
Could not start REST http interface listener. The requested port may already be in use. Please make sure there is no other instance of this server running already.
Fatal Error: listen EADDRINUSE 127.0.0.1:4723
This is why I recommend not doing this locally. (I think on CI this is fine)
appium
appium runs Appium in your terminal session and essentially "locks" that process to that shell. This makes it so you can easily control + c to quit the program on MacOS. I recommend this locally.

How does the elixir community recommend setting up integration tests with chromedriver?

I am using Hound (https://github.com/HashNuke/hound) for integration testing a Phoenix application. I have chrome and chrome headless working. To get it working I have another terminal window running chromedriver (installed via brew). This feels odd to me. Is there a library or test setup that would feel more "integrated" into the application? What's the Elixir way of doing this?
In the Ruby world there's the webdrivers gem (https://github.com/titusfortner/webdrivers). As far as I know it downloads a specified driver (lets say chromedriver) to $HOME. Then with every test run, the test uses the driver downloaded to that destination to execute the tests.
Before the webdrivers gem there was chromedriver-helper gem. Before that it was phantomjs. These implementations made it so running integration tests required 1: downloading the driver 2: running the test
In Elixir (with Hound) I have my tests working by first running chromedriver --verbose in a terminal split, and in the other screen I run mix test. This works fine but feels disjointed. This adds extra steps, 1: download the driver 2: start the driver 3: run the test 4: stop driver
I could write a script manually to run chromedriver in the background, and stop it after the tests are run.
I am new to the Elixir community and so I've researched a lot. It's still not clear to me if there is a "traveled path" I should go down vs just hooking everything up manually.
Have I missed a recommended abstraction? Is this intentional? Is this "just not created, yet"?
Thank you
Have you checked out wallaby? See https://github.com/keathley/wallaby

Unable to run tests against Safari 11 remotely (ssh, CI)

I'm having troubles running Ruby/RSpec tests against Safari 11 when I'm trying to run tests via ssh manually or via Jenkins (where machine where Safari exists is remote slave).
When executing tests, I'm getting following error:
Selenium::WebDriver::Error::WebDriverError:
unable to connect to safaridriver 127.0.0.1:7050
What is weird is that I'm able to run tests when I'm logged to the Mac machine directly. This leads me to the conclusion that there could be some permission which, by default, disables execution from ssh session but not sure why?
Also, to my knowledge, Safari Driver is part of Safari 10+ and as such is not installed anymore as extension
Update: I've found out that safaridriver executable that should be spawned by tests cannot be spawned from some reason when I login via ssh.
Example:
/usr/bin/safaridriver -p 7050
It will just terminate with non-zero exit code while running same command directly on machine will run safaridriver in foreground. Since I expect Jenkins to be running test job on this machine, my idea to overcome this issue would be to launch safaridriver on this machine (by cron or launchctl) and then use this instance to connect to it with my tests. However, so far, I was not able to make my tests (Selenium/Capybara) re-use existing safaridriver instead of always trying to spawn new one on different port. Any idea on this would also be greatly appreciated.
This is my environment:
OS: MacOS Sierra 10.12.6
Browser: Safari 11.0.2
Thanks in advance
There is a possible workaround to do this. First you need to create a Automator Workflow or Apple Script that launches the SafariDriver
Then save this as a application. Let assume we name it SafariDriver7050.
Then from the SSH session you need to execute
open /Applications/SafariDriver7050.app
This will actually launch SafariDriver in the logged in session and it should work for you.
The caveat being shutting it down, you will need to first kill the SafariDriver7050 app and then you need to kill the safaridriver process. The order matters, else it will create a error dialog on UI
Edit-1:
As you suggested, it would be even easier to do this, when you wrap your test as a app and then it will be automatically be able to launch SafariDriver without any issues. The key to issue is using open command in a SSH session
Edit-2
Why does SafariDriver not work in SSH? Well if you look at the linux counterpart
In case of linux we can use the DISPLAY environment variable to launch an app in an existing display or we can use something like XVFB to launch the browser in a virtual display. That is the concept that most frameworks use in case of linux machines.
But Mac doesn't have such kind of feature, which is why this workaround is needed. Now why it doesn't have that, I am not sure. There may be some other workaround that I may not be aware of, so anyone who has valuable info, can help improve this part of the answer
For my case:
On OSX host side was created Automator app as described above and modified a little bit:
security unlock-keychain -p your_host_password /Users/$USER/Library/Keychains/login.keychain-db
safaridriver --enable
safaridriver -p 7050
On CCI/Jenkins side:
open /Applications/StartSafariDriver7050.app/
run pytest cmd
osascript -e 'quit app "StartSafariDriver7050"'
pkill safaridriver
In Python:
def safaridriver():
return webdriver.Safari(desired_capabilities=Caps.SAFARI, port=7050)

How to setup webdiver to perform actions in background?

I am currently working in Automation QA. Our project using Java: jbehave, thucydides, selenium. We are working in Ubuntu OS.
Every time I run my tests, I have to stop doing everything(coding, browsing the web), because every click or any action of selenium is taking driver window(we are using chrome driver) in focus(makes window active) and if i do something i mess up the test. Our team is wasting a lot of time because of this.
We have tried Phantomjs, it doesn't work correctly, cannot find elements etc... And also to run tests in virtual machine using vagrant isn't working for us(for company specific reasons).
It is fine if Chrome driver will take over active window when it starts, as long as it would continue performing different actions in background. Strange, but in my previous project(windows, c#, mstest) chromedriver would behave exactly like this without any additional setup.
Please help, I know few other teams having this issue. Seems like this issue only on Mac and linux.
After having this issue for a long time I have finally found a good solution. This issue still remains on ChromeDriver level, so if there are any updates on this side let me know.
The easiest way to run tests in Ubuntu in a background is using VNC Server. Here are the steps you should follow:
Install vnc server from ubuntu terminal:
sudo apt-get install vnc4server
Start server with any number(I use 7). First time doing it enter password for vnc server(Remember it!).
vncserver :7
To start server in full screen add "geometry" to last command with your screen resolution for example:
vncserver :7 -geometry 1920x1080
Download some VNC Viewer. I use Real VNC.
Go to Real vnc viewer, start new connection and enter:
VNC Server: localhost:7
Encryption: Let VNC Server choose
Press connect and enter your vnc server password(the one from step 2).
New window should be opened, open new terminal in it.
Run your test from terminal. I use java maven project so for me it works like this. Navigate to project folder and run: mvn clean install
If you want simply to run test in hidden mode using only terminal(without opening vncviewer) use this command:
cd path/to/project
xterm -display localhost:7 -e mvn clean install
If you want to stop server:
vncserver -kill :7
Hope this will help many of you.
For me (I had the same problem in my Grails project's functional test using Chrome; not with Firefox) works this set up:
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized --disable-popup-blocking");
new ChromeDriver(options);
Regards

Jenkins running selenium tests without opening browser

I browsed a lot on this topic. There are different variations of this question or no answer to fix my issue. Any help is appreciated.
I have installed firefox on my VM as root in /usr/bin/firefox.
I downloaded the maven project to run selenium tests, and run it
manually on my VM using mvn clean install command. This opens the
browser and also successfully runs the test.
Now I run Jenkins as myself ( JAVA_HOME is /usr/java/latest and started the service as
nohup java -jar jenkins.war --httpPort=-1 --httpsPort=8082; version
is 1.522).
Create a new freestyle s/w project; Configure the job
to download the maven project and invoke maven target 'clean
install';
When I run the job, I can see the steps in the console
output but the browser is not opening. It also locks up my AD account.
Why is this happening? What is the fix?
nohup runs Jenkins in the background (http://en.wikipedia.org/wiki/Nohup), in which case according to this post Jenkins will start the browser in the background as well.
Try starting jenkins without nohup so that it runs in the foreground (java -jar jenkins.war --httpPort=-1 --httpsPort=8082).
Or you can start Jenkins as a daemon (this Jenkins Wiki page contains an example of init script). When Jenkins is started as daemon, the browser started by its job is visible.