Selenium with Xvfb and Jenkins throws TimeoutException - selenium

I'm trying to setup automatic Selenium tests with Jenkins on a Linux server.
The problem is that all tests fail with:
org.openqa.selenium.TimeoutException: Timed out after 60 seconds waiting for visibility of element located by By.linkText
Each test fails with the fist element expected.
Jenkins has the Xvfb plugin installed, and from the console messages it seems to work:
Xvfb starting$ /usr/bin/Xvfb :1 -screen 0 1024x768x24
I tried to increase the timeout, but it seems its not that the problem.
The tests run fine on windows and on a linux system with display.
The problem is I don't have direct access to the server, so I'm trying to explore all possibilities before I make requests to the sys admins.
To run the tests are used two projects, both seem to deploy fine, but when the tests start its like one project (the backend) is not deployed and some URLs are not found, from here the timeout exception. I'm not very sure how Jenkins behaves in this case, and if it starts one project at a time.
Any ideas? Thanks a lot!

To check if the application under test is running when tests try to access it, you can connect to the test machine via ssh, and take screenshot at the moment when the test runs:
xwd -root | convert xwd:- capture.png
http://inspirated.com/2007/04/02/howto-use-xwd-for-screenshots

Related

Cucumber selenium failing in jenkins pipeline only

I am working on an integration test, using Selenium/Java/Cucumber. When I run the test on localhost, or remotely on a VM, it passes fine. But when it runs as part of a Jenkins pipeline it hangs with the error "Timed out receiving message from renderer". I have googled this and there are several possible causes, including version conflicts. But I can't seem to figure out how to check these versions in the jenkins pipeline. Any pointers on what to look into would be helpful. I believe the tests are running headless on the pipeline, because there is no Chromedriver pluigin installed in our Jenkins. The test is pretty straightforward - it involves clicking on an element within an iframe (this is where it hangs) and checking for some output. I have even tested it running manually on the VM created by the very same pipeline and it always works without an issue.

Selenium works when started locally, but not remotely

I'm hoping this is a simple issue to solve:
I have a dedicated machine that runs selenium with chromedriver. I can physically walk to the machine and type the following in a local terminal:
java -Dwebdriver.chrome.driver=chromedriver238 -jar selenium-server-3.11.jar
I can then go to any other machine on the network and kick off testing (in my case, codeception on jenkins) and it will sucessfully run my tests in chrome without a hitch.
However, if I try to run the above command without physically being at the selenium machine (ex, trying to ssh into the machine to run the command or making this command run as part of a supervisor process) then selenium has trouble starting the instance of chrome.
Has anyone run into this scenario before? Is there a way I can give 'interactive' access to the background script to allow it to open stuff on my screen?
Because when you physically walk to the machine and run the command. the selenium can get the desktop/window interface.
When use SSH, selenium lost the desktop/window interface, selenium have to start chrome under headless model, but your code not config to run as headless model. So the conflict come out.
you need to config your code to run with headless model.
I'm to getting the same scenario, when i try to start the selenium code on the machine A it works yet when i try to start selenium and run the scripts from machine B
(remotely connecting to machine A using ssh [ssh test#machine-a]) chrome instance doesn't start/launch and driver is getting null.
logs :
2020-02-27 12:04:27,319 INFO [LogWritter] Exception in beforeclass chrome driver instantiation , driver is null
2020-02-27 12:04:27,493 INFO [LogWritter] Exception in getting screenshot---java.awt.AWTException: headless environment
Any help/suggestion would be great !

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)

When selenium test runs by Jenkins and MSUnit, the browser doesn't come up however there are valid results

I put together a machine (Windows Server 2012R2) for POC reasons where a Jenkins installed and it executes Selenium UI tests using msunit
But, when I log in the server where the Jenkins runs and I watch what happens during CI build (compile and test execution) I can't see that the browser (Firefox) starts automatically, however, the test results and the logs show that a browser was executed.
My question is that, what the is happening when my tests are executed by Jenkins? If I execute the command which from visual studio on the same machine then I can see that Firefox starts, does what is programmed in the tests and the results are in the result.trx.Can I somehow set up Jenkins the way the browser really executed (I can believe it when I see it :)
In Jenkins when you run selenium test cases, they are executed in the background by default.
Your Jenkins might be configured to run those test cases in some video buffer(usually it happens on Linux but can also be configured on Windows) or in a headless state.
As your question, if you are using MSTest which basically used to convert the test cases result from trx to JMX format but also can be used to run selenium tests. when you run the same in Jenkins it will run in background on any slave or on master.

Selenium server cannot be started inside Bamboo

I am trying to configure a Selenium testing through Bamboo. I am able to run Selenium scripts directly from command line, however it always fails if I run it through Bamboo remote agent. The error is:
: Could not start Selenium session: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107)
I took some advice from the web, and checked "Allow service to interact with desktop" for Bamboo remote agent service. However, it does not work.
Anyone have other suggestions?
You must run Bamboo in Console Mode for this to work. Also, the build machine desktop must be active - and not covered or minimized if you want mouse simulations to work. I know right!