I\'m looking at Selenium Server at the moment, and I don\'t seem to notice a driver that supports headless browser testing.
Unless I\'m mistaken, it doesn\'t support
Headless browsers are a bad idea. They get you some testing, but nothing like what a real user will see, and they mask lots of problems that only real browsers encounter. You're infinitely better off using a "headed" browser (i.e., anything but HTMLUnit) on a headless environment (e.g., Windows, or Linux with XVFB).
Install chromeDriver
and google-chrome-stable
version on the linux server, where the tests will be triggered and add the same binaries in your code.
code snippet:
private static String driverPath = "/usr/bin/chromedriver";
static
{
System.setProperty("webdriver.chrome.driver", driverPath);
options = new ChromeOptions();
options.setBinary("/usr/bin/google-chrome-stable");
options.addArguments("headless");
driver = new ChromeDriver(options);
}
I notice that you say that using an X framebuffer isn't a true headless solution, however, for most, I think it would be acceptable. In addition to that, this service will help get that going for you if you are interested in that as a solution.
Yes ,selenium supports headless browser testing...but i found HTMLUnit failing most times...I was searching for an alternative...PhantomJs was really good.you can definitely give it a try it was very fast when compared to other browsers...It is really good for smoke testing...
http://phantomjs.org/
With ruby and macOS: brew install phantomjs
then:
driver = Selenium::WebDriver.for :phantomjs
Here's a "modern answer" on how to use Selenium with xvfb and Firefox driver in an Ubuntu Linux environment running Django/Python:
# install xvfb and Firefox driver
sudo su
apt-get install -y xvfb firefox
wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz
tar -x geckodriver -zf geckodriver-v0.19.1-linux64.tar.gz -O >
/usr/bin/geckodriver
chmod +x /usr/bin/geckodriver
# install pip modules
pip install selenium
pip install PyVirtualDisplay
You can then follow the Django LiveServerTestCase instructions.
To use the driver you just installed, do something like this:
from pyvirtualdisplay import Display
from selenium.webdriver.firefox.webdriver import WebDriver
driver = WebDriver(executable_path='/usr/bin/geckodriver')
display = Display(visible=0, size=(800, 600)).start()
# add your testing classes here...
driver.quit()
display.stop()