Protractor/Selenium: run browser in the background - selenium-webdriver

I'm using protractor for testing. 99% of the times there's no need to actually see the browser, the tests take a long time, and all we're interested in is the final outcome.
Is there a way to hide the browser opened for testing (e.g. run in the background)?

As stated before, docker-selenium works wonders. The only browser not supported by docker-selenium is Internet Explorer, for obvious reasons.

From what I understand, you cannot really reliably control the way browser windows are opened via protractor/webdriverjs/selenium.
A common way to approach the problem is to use a virtual display, see:
Can Selenium Webdriver open browser windows silently in background?
An alternative way to accomplish that, would be to run tests inside a docker-selenium container, here is a quite detailed introduction:
protractor with any headless browser?
Or, as pointed out here and if you are on Mac OS X, you can run selenium tests on the same machine but under a different user which would not interfere with your current display.
You can also run protractor tests in a docker container in a headless firefox:
Protractor-Firefox-Headless-Docker
Another alternative would be to use a remote selenium server, as, for example, BrowserStack or Sauce Labs services provide.

You can try headless browser like PhantomJS for this purpose. PhantomJS runs in background and failures can be captured using screenshot.
Refer following link to know more about phantomjs:
Protractor running tests on PhantomJS

Related

same-site-by-default-cookies alternative for Chrome

I am writing to ask about --disable-features=SameSiteByDefaultCookies feature which was part of chrome earlier.
I am working with IT MNC and recently we promoted very important functionality to Production. We have started charging customer for this. It is legacy application .
This application can't be tested locally anymore! Earlier we could point out application to lower environment with custom settings in project's config.js file and disabling #same-site-by-default-cookies in Chrome and application could be tested locally. But now we can't!
We tried many different settings and debugged but it could not help !!
It is noted that these settings no longer work in Chrome 94+. These flags are removed entirely.
As per my analysis it is found that application still can be tested locally if we get the portable Chrome. Or older version of Chrome installed in our System. However as per the compliance policy of company and client, we can't get old or portable chrome in system. We have latest version only.
Earlier we used to perform following to run it locally:
Open CMD
cd to Chrome path ( Till Application )
Fire the following command:
chrome.exe --disable-web-security --user-data-dir=C:\XXXX\XXXX\localwlp --disable-features=SameSiteByDefaultCookies"
This would open a new window of Chrome ( Close all before firing the command) and then we could test the application locally.
Anybody is aware about the alternative for this? That would be really helpful. We can't test the application locally so for even small changes, we require to deploy on lower environments which takes a lot of time and also code will work or not can't say.
I look forward to hearing from you all guys.
Thanks,
Kailash Nirmal.

What is the most reliable .net selenium web driver?

In using .net selenium webdrivers, I have been stumbling in 2 main issues, each for a different specific webdriver.
The table below shows the issues Chrome and Firefox webdrivers have been falling short with me:
I am using RellYa's selenium jquery extensions.
Chrome webdriver randomly throws a jQuery not found exception. If I try a couple of times, I eventually succeed.
With Firefox's webdriver, this never happened.
On the other hand, firefox throws a
Unable to bind to locking port 7054 within 45000 ms
Research shows that the reason behind this is that I must have left another firefox webdriver not closed/not quit. But this defeats my using selenium to automate web tasks, in a multi threaded manner. I mean, after a couple of threads are opened, seems it reaches some limit and waits for one of the opened webdrivers to close.
Actually, from this firefox webdriver's documentation, they make it clear that only one instance is supposed to be running. What one is supposed to do then if he had in mind multi threading ?
Does any one have working solutions for the problems singled out in the table, for each specific webdriver implementations ?
No, you can run multiple instances of firefox, chrome, or whatever from your machine at any one time. If you research "Selenium Grid", you will see that it is designed to do that.
So:
The unable to bind message on firefox is not caused by another driver locking a port. Each driver instance starts on its own open port.
If you are not using Selenium Grid, or not using the grid, and are trying to handle the multi-threading yourself, just be careful of how you open and close your browsers in your #Configuration phases in your test runner.
As a educated guess, if you have instability, its more likely because you are trying to control a newer browser with a too-old version of Selenium? We need more info on your question, such as an example project to look at.

Is it possible to run phantomjs by using IE desired capabilities?

By default phantomjs uses chrome capabilities. Is it possible to run it with IE capabilities .If so, I need to use it for page-object gem like:
#browser = Watir::Browser.new(:phantomjs, args: '--ignore-ssl-errors=true')
Can any body please provide me any solution for it.
The quick answer is no: Phantom is using the same WebKit rendering engine that Chrome/Safari uses (*), so cannot act like IE.
You might be interested in TrifleJS which is a headless IE port of PhantomJS. (The project is in the early stages, and (AFAIK) won't work with CasperJS yet, and does not seem to support selenium integration either yet.)
*: More precisely, Phantom 1.9 is equivalent to about Chrome 13. And recent versions of Chrome use Blink, not WebKit. So Phantom 2.x, when finally released, won't be equivalent to any version of Chrome.

Selenium Grid: Error communicating with the remote browser. It may have died

I have two machines, one with all the stuff I need (Eclipse + TestNG +scripts) and the other one with just browsers installed.
I use Selenium Grid 2.35.0.
Everything seems to be fine except the problem that very often I get this error:
Error communicating with the remote browser. It may have died.
Scripts are not complicated at all, I run them one-by-one, so it just happens randomly. I don't think it's because of the browser.
Any idea/fix?
If you need more info I'm here.
The only time I get that error is when I manually close the browser myself. I would verify that the machine withe the browsers is stable.
It could also be due to calling driver.quit() and not instantiating another driver (I haven't ever done this, so I don't know what error this throws)
I notice this error as well but ONLY when using Selenium grid (using 2.35 but 2.38 exists now)
When I run locally I don't get error communicating with the browse but typically it can happen when there is a bug with your setup and teardown code (maybe one of your classes creates an instance of your browser before your setup function gets called)
See How to close child browser window in Selenium WebDriver using Java
ensure to call driver.close(); on every popup / new windows / new tab you open during the test (after switching to it using driver.switchTo())
and to call driver.quit(); at the end of the session (generally in #AfterClass annotated method)

Selenium, PhantomJS, Mocha combination fails on sendKeys command

I have implemented the following technology stack for automated unit testing in the browser.
Mocha -> Selenium -> Phantomjs
I followed this example:
http://net.tutsplus.com/tutorials/javascript-ajax/headless-functional-testing-with-selenium-and-phantomjs/
I suspect that there might be a bug in the "send keys" command between Selenium and PhantomJs. I do not have any experience in these 2 technologies, so I suspect it is rather me making some configuration mistake.
Basically what happens is that the characters sent by Selenium is not all applied by PhantomJs.
I switched PhantomJs out with Firefox and there it works like a charm.
The Selenium output for the 2 drivers are exactly the same. So I am left with suspecting a bug in PhantomJs or Ghostdriver. But as I said it might just be me not configuring the thing correctly. Given that this is quite a big issue I really suspect that is the case.
I am also not 100% sure where to log this, if this is indeed a bug.
There were a couple of issues with sendKeys fixed recently.
https://github.com/camme/webdriverjs/issues?page=1&state=closed
Are you running the latest version?
If not I would log a bug there about it.

Resources