Selenium jobs not running on jenkins CI server - jenkins

We have automated 5 test cases and ran locally and seems to be worked fine. When the same code base is running on CI server(linux box against firefox browser), It failed to execute. However I used xming to see the GUI execution part and observed the browser is keep on loading and not displayed any web element to perform action. I just cross check with whether its proxy issue, and handled through code as below: (Due to security issue I can't able to share proxy details, but I pinged It returned proper response.)
Sample Code(created firefox profile):
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", "someproxy.com");
profile.setPreference("network.proxy.http_port", 8090);
//Other dependencies like "No Proxy for" is added in firefox.
profile.setPreference("network.proxy.no_proxies_on","localhost, 127.1.1.1, prt-www.xxx.com, ti.xxx.com, s3, xxx.com" );
DesiredCapabilities desired = DesiredCapabilities.firefox();
desired.setCapability(FirefoxDriver.PROFILE, profile);
I really don't understand the root cause for this issue. Can somebody tell me what would be the root cause for this issue?
I check the firewall in that box , and It has been stopped.

Related

Why is my Dockerized Browserless-Chrome hanging when a Mediawiki Selenium test causes a new page to be loaded?

Background
I have a makefile which fetches and spins up a Dockerized Mediawiki instance on my local machine, from scratch, with a single make command:
https://gitlab.wikimedia.org/mhurd/mediawiki-docker-make
This works fairly well. Please try it!
Goal
I'd also like to be able to run Mediawiki's Selenium tests (as-is) in Docker containers and watch them execute "live", with the makefile, again, making it easy to kick this process off.
Approach
This work-in-progress branch adds a container for running Mediawiki Selenium tests, and a browserless-chrome container so you can watch and debug the tests "live", as they run:
https://gitlab.wikimedia.org/mhurd/mediawiki-docker-make/-/tree/selenium
As you can see from the top of this branch's readme, after running make to spin everything up, running make runseleniumtests kicks the tests off. When doing so a browser window is automatically opened which lets you see the Selenium tests which are running in the browserless-chrome container. This works... to a point.
Problem
Unfortunately, after a few tests are seen to be running, I'm seeing this error:
Protocol error (Input.dispatchMouseEvent): Target closed.

I suspect the way the browserless-chrome container manages its Chrome sessions may be to blame, as it appears the error is happening when a test causes a new page to be loaded, but I'm not sure.
Any ideas appreciated, and please try it yourself - the whole point of the makefile is to make spinning this up from scratch super simple. It only takes a couple commands and you should be able to see the tests running and the resulting error. Thanks!
Misc
Running curl -s http://127.0.0.1:3000/sessions | python3 -m json.tool on the host machine after attempting to run the tests shows there are multiple browserless-chrome sessions, but I'm unsure how to make it behave more like a non-dockerized setup - which has no problem with tests which cause page loads.
In email communication with Browserless support, they mention seeing similar issues but haven't been able to track down why:
It seems to be that the root cause may be due to "click" events aren't
working properly when your viewing the live debugger. Can you confirm
that if you don't open the live viewer, it allows the test to progress
and eventually throws new errors regarding selectors not being found? (Edit: I did)
I've also run into this live debugger behavior before and in my
experience I stopped watching the live debugger, and since I couldn't
see which selector it wasn't finding I exported a screenshot and in
that particular case, it ended up being an issue with my viewport,
since the viewport in the remote session was smaller, the styles
rendered differently then locally on my machine, when I set the
viewport size, the selectors were found - but then again, that was my
particular issue, might not be yours.
But yes, for some odd reason when you view live sessions, you can run
into this odd issue which we haven't been able to understand.

Websites detecting and blocking Selenium Chromedriver

I got a task to update a URL in a test (using Selenium, Java and Chromedriver) to a new URL. The page is the same, just at a new location. This test worked fine with the old URL.
I brought up an instance of Chrome and verified I could access the URL.
Then I changed the URL, committed to git, and ran on our Jenkins machine and it failed. The screenshot said "This site can’t be reached". I told a co-worker that I think the URL must be wrong (though it worked on my desktop without Selenium). He tried it and it loaded fine. I tried it again from a regular Chrome window and it loaded fine. I tried from Eclipse using Selenium and I got the message about the site could not be accessed.
So I ran Eclipse, stopped it right when Chrome came up but hadn't loaded a URL yet. I manually entered the URL (from copy/paste) and got "This site cannot be accessed). Then I brought up a regular Chrome window and pasted the URL in and it loaded fine.
I decided to look for differences. So in my regular Chrome window it was "Version 77.0.3865.120 (Official Build) (64-bit)". I did the same on the version running under Chromedriver and got "Version 77.0.3865.120 (Official Build) (64-bit)". So the same.
I did a search for the latest Chromedriver. It said for version 77 to please use 77.0.3865.40. This was not what I was using. So I downloaded the correct version and thought "surely this will fix it". I verified it was 77.0.3865.40 coming up. But, as you guessed it, I got the same problem after updating to the most compatible Chromedriver.
Some searches said that basically nothing would be able to tell, but there was one property that Chromedriver inserts. I don't know whether this would be enough to block a session using Chromedriver?
The only thing I can think of is that we have iBoss and possibly iBoss is blocking it? Either that or somehow the site is blocking it.
I would like to share the URL with you but I do not know whether that would be violating company policy. If I get permission, I will share the URLs.
by the way, the error is "ERR TUNNEL CONNECTION FAILED"
Got some internal help to help fix some settings

Intern test framework hangs/does nothing when used with Appium 1.4.13 on an iOS device for mobile web

I just started looking into using the intern test framework to write functional tests for our mobile web apps. I'm looking to run these tests on actual iOS devices.
I setup Appium as the selenium server talking to the intern client. It works as expected on the simulator (although I get 'method not implemented' for many of the touch related methods).
I then decided to configure everything to work on my iPhone 6 plus, running iOS 9.0.2
After much wrangling with instructions from here, I got all the various pieces working in tandem (ios-webkit-debug-proxy, appium-server from the repo, etc.)
Finally, I decided to run my tests. When I run the test runner, Safari on my device starts up (via SafariLauncher App), and ios-webkit-debug-proxy and appium-server seem to be talking to each other. However, intern simply posts a 'created session on...' message, and then does nothing.
To ensure that the server was running properly, I decided to use a rest client to send it POST and GET requests using the JSONWire Protocol methods, and it seems to be loading the web-page url and responding to JSONWire requests. So clearly, something is going wrong with Appium talking to intern, or vice-versa.
Any help/insight on this would be greatly appreciated. Thanks!
I'm also in the unique position of having to run these locally, so using SauceLabs, BrowserStack, etc. is out of the question.
Got it working!!!
So the trick was to specify the proxyUrl config option.
My original conjecture was that there might have been some issues with basePath, etc., but I noticed my console.log statements that were outside of test cases were running properly.
That's when I noticed that the Safari page tried to navigate to localhost right after the test had started. This is my first time ever working with Intern or Appium or any Selenium stuff for that matter. Because you cannot access localhost (which in this case was meant for accessing the Intern server on my computer, since you're running the tests on your computer, and not on an external device), from the iPhone, I specified proxyUrl and proxyPort in the config, and specified my computer's local IP (192.168.x.x) and the Intern server port (9000). It still didn't work. I looked at the URL in Safari and noticed that it wasn't using the proxyPort field - so that the URL looked like: 192.168.x.x/__intern/clie... So I just tried to enter the port in the proxyUrl option - as that option's a string - 192.168.x.x:9000. And voila - it worked!!!
So hopefully this helps some other soul looking to have a native mobile test working with this setup!

Can I see what happens in PhantomJS?

Sometimes, when running automated tests in PhantomJS using Cucumber for Rails 4, it would be really, really useful to actually sit in front of my screen, look in a window, and see exactly what the browser is doing.
There are times when your code is right and your test is right, but testing fails intermittently nonetheless. It's often because of a script, or an animation, or some CSS that gets in the way. But seeing a screenshot, drilling into a DOM inspector, or using the debugger is not enough to catch those edge cases.
Is there any way to have a window looking at what PhantomJS is doing in the background? It could be something in X Window, or running in a VNC Server, etc. Anything visual would greatly help with debugging, especially in with those finicky details.
I found a little program called PhantomVNC, but it's not telling me much on how it works. It looks like something just feeding a series of screenshots through VNC.
I tried PhantomJS and Capybara-WebKit, but neither of those headless browsers other a "head" option. Selenium-WebDriver seems complicated to set up and only seems to work with a full browser like Firefox, and that may cause more problems than it solves.
If you have any ideas, please let me know. Thank you in advance.
Not sure specifically about Cuc/Rails - but I specifically have a second chrome/webdriver Virtual Machine for this. I use PhantomJS specifically for the headless automatic acceptance testing, but when there is an issue with the tests and I'm trying to diagnose it can be helpful to view the browser live.
In other words, spin up a Ubuntu desktop VM, install chrome, install selenium server and the chrome webdriver. Log in to the VM, open chrome, make sure selenium is running, then configure your test suite to connect to the selenium webdriver service (usually port :4444) of this instance. Run your tests and you should be able to watch the chrome instance on the VM.

grails embedded server functional testing needs to have valid ssl cert

I have been scouring the web for how to solve my problem with grails functional testing using embedded server + ssl, and would very much appreciate any help with the problem I'm having.
We have had good success so far testing our Grails webapp with Firefox using Selenium WebDriver 2. We run functional tests automatically from our Jenkins server (and sometime our local machines) using the functional-test plugin to start and stop our app, and the webdriver plugin in conjunction.
This line:
profile.acceptUntrustedCertificates = true
that is used for the profile of the new Firefox instance has been effective for us in making everything SSL totally valid as far as the browser is concerned during our tests with Firefox.
So, although that setup is working great with Firefox, we still need to run a parallel set of tests for IE 8, but I simply cannot figure out a way for webdriver to deal with the SSL warnings/obstacles of IE 8.
Because we are purely Mac (dev)/Linux (jenkins, etc) here, we run IE 8 in a Win 7 VirtualBox VM. Then from the Win 7 VM instance we run the standalone WebDriver server. It works fine up to the point where the test reaches the SSL part of our webapp, at which point I get the IE SSL warning page, and the test is derailed.
We bought a cheap godaddy SSL cert to use for this very reason, hoping to make IE happy, but I have not been able to figure out a way to make our certificate appear as valid and CA signed one, rather than just self-signed. When I examine the certificate in Chrome for example, it does show my certificate, but also that it is self signed. It's CN is along the lines of testbox.example.com and I have added to /etc/hosts the line: 127.0.0.1 testbox.example.com.
I generated the CSR with java keytool and then imported the resulting signed certificate, and intermediate certificate, cross certificate, etc, per the instructions on the godaddy site. I saw somewhere that grails requires it's keystore to retain the password 123456, which I have done.
I have done SSL configs successfully for regular servers, e.g. standalone glassfish and tomcat, but I have just really hit a wall on this issue.
Thanks!
Jamie
Another aproach:
You mentioned that changes in the IE settings don't work since the WebDriver creates a new IE instance.
IE stores a lot of settings in the windows registry. So "IE registry certificate" could be a good start to google your problem. Here is one promising result:
http://www.ehow.com/how_5024374_fix-certificate-error-internet-explorer.html
Since you run your IE in a virtual machine, I guess it is OK to disable the IE security features on this vm. Otherwise I have to admit that it's not a good idea to disable such a security feature by default.
For testing just install your certificate into IE 8.
See What do I need to do to get Internet Explorer 8 to accept a self signed certificate?
I know it's not a very clean solution, but out IE8 displays a warning that something is wrong with the certificate. This warning itself is a valid HTML page and your are able to click the link which says something like "ignore this, display the page".
You only have to this once for a session. So we simple have a small step in our tests which checks after invoking the first page if we get the error message. If yes, we automatically click the link and the rest works fine.
Again: I know it's not a clean solution. But it works for us. And having to configure the java keystores the right way can be a pain. :-)

Resources