We're doing some testing in Rails using a headless browser for our feature tests using RSpec and the web drivers gem: https://github.com/titusfortner/webdrivers to get the Chrome driver.
However we've had some issues whereby some developers don't have Chrome installed (and don't intend to) and also we have our app running on a Jenkins pipeline and we want to avoid having to install Chrome on the server for the tests...
Is it possible to run a headless browser without installing the actual browser as well as a hard dependancy on the system that the tests run on?
I've read conflicting articles that state headless allows you to still do your testing either when the system doesn't have the browser installed... but at the same time the documentation for Chrome and Firefox state the browser also needs to be installed when using their drivers.
https://github.com/rubycdp/cuprite I also came across this which bypasses the need for WebDriver etc... but still seems to have a hard dependancy on having Chrome installed on the system the tests run on.
You have to choose a browser:
Chrome: chromedriver
Firefox: geckodriver
Edge: edgedriver
Internet Explorer: iedriver
See https://github.com/titusfortner/webdrivers
Related
I have a web application, on which I would like to run Yslow. The tests would need to be integrated with Jenkins. The application has a login page. If I provide the application's url, if a valid user is not logged in the login page will be displayed. So how do I test performance using YSLow & Jenkins? Is it possible to automate the login part?
Since YSlow can generate a performance report from an input HAR file, I would use a proxy server to record the performance data while navigating the web-site with Selenium.
This way, you can independently measure the performance on a real browser (Chrome, Firefox, Safari...) or on a headless one like PhantomJS.
To proceed, first download browsermob proxy and unzip it:
https://github.com/lightbody/browsermob-proxy/releases
Then write the code to launch the proxy server and to run your scenario with a Selenium client. This example was written in Python, but you could write it the same way with some Java, Ruby, Javascript or PHP.
from browsermobproxy import Server
from selenium import webdriver
import json, sys
# setup the proxy server
server = Server(r"C:\Download\browsermob-proxy-2.1.0-beta-5\bin\browsermob-proxy")
server.start()
proxy = server.create_proxy()
try:
# setup the browser
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
# start collecting the data
proxy.new_har("google")
# login to a twitter account
driver.get("https://twitter.com/login?lang=en")
driver.find_element_by_css_selector(".js-username-field").send_keys("my name")
driver.find_element_by_css_selector(".js-password-field").send_keys("my password")
driver.find_element_by_css_selector("button.submit").click()
# save the collected data to a file
with open(sys.argv[1], 'w') as file:
file.write(json.dumps(proxy.har, indent=2))
finally:
driver.quit()
server.stop()
Finally, to run the script and generate the performance report with a command line:
python perf-login.py perf-login.har
yslow perf-login.har
yes you can, but you still miss this automated part. You need something more than a YSlow & Jenkins. It's highly depended on application's network architecture - if you run tests locally, or remotely.
Robotframework + Selenium Server
With Robotframework's selenium2library can use Selenium Server bindings to manipulate with browsers DOM. In other words, you can create very simple automated login tests and actions. Afterwards the SSHLibrary or Terminal library can run YSlow commands and you just need to provide output files to Jenkins readable location. It's pretty complex solution suitable for advanced network architecture with many dependencies.
PhantomJS + CasperJs
If you need to run your performance tests locally, you can use advantage of headless browser PhantomJS. In combination with CasperJS you are able to manipulate with DOM to create automated login processes. PhantomJS is also compatible with YSlow, so once again, you just need to define the output files location for Jenkins.
For both solutions (or any other) you will need additional jenkins plugins to read output files generated by YSlow.
I'm trying to run my cucumber tests and they seem to stop randomly. A new page is visited but nothing renders on the page except Retry later as in the following screenshot.
I'm on OS X 10.9.3, Chrome 35.0.1916.114, and running with bundle exec cucumber. It's happening in and Firefox also if I change the javascript driver.
The problem was not with Chrome, Cucumber, or Capybara. It was with Rack::Attack. 127.0.0.1 was whitelisted but according to this github issue
it wasn't whitelisting ipv6 and transitional loopback ip addresses
To simplify things I just moved Rack Attack to be production only.
tl;dr
Rack::Attack was to blame. Unless you need it in your test environment, just make the gem production only.
I am using Jenking to run my selenium scripts on a remote server. My question is "Is there any way to visually see my scripts running on the server? I mean on an actual browser when scripts are running in Jenkins?"
No, you cannot visually see a browser running on ubuntu server but apart from that you can run a headless browser and log everything to see the progress of your scripts running on server.
Yes, either use a Sauce labs account, or just run tightVNC server on the remote system, which runs a vnc server in a "Java Viewer" and by setting a "readonly password" to the server, you can open a browser and using the java viewer, basically you can watch the session and you can even "scale" the size of the desktop just like Sauce Labs can do.
Problem
My selenium functional test is failing when I run using the Chrome driver, but works when using Firefox.
My Environment
Mac OS X Mountain Lion
Chrome Version 22.0.1229.94
Build info: version: '2.2.1', revision: '16551', time: '2012-04-11 21:42:35'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.2', java.version: '1.6.0_35'
Driver info: driver.version: ChromeDriver
Steps to Reproduce
The exception occurs when using the Geb Grails example application from github.
Run the application using the Chrome driver:
grails -Dgeb.env=chrome test-app
The tests will begin to run, an instance of Chrome is successfully opened, but nothing happens afterwards. The Chrome browser isn't directed to a url, it just sits there with a silly grin on its face. The below error is thrown in the console after a 15 second (or so) timeout.
The Error
Caused by: org.openqa.selenium.WebDriverException: Unable to either launch or connect to Chrome.
Please check that ChromeDriver is up-to-date. Using Chrome binary
at: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
My Debugging Steps
Per this stackoverflow post, I've attempted various different versions of the driver with no effect.
The tests are successful when using the Firefox driver (sadly, I must test with Chrome).
Attempt to use the latest beta of chrome Version 23.0.1271.40 beta. no luck.
Upgraded the geb and selenium versions in the test app to latest and greatest: def gebVersion = "0.7.2" def seleniumVersion = "2.25.0"
Humble Thanks Section
Thanks for taking a look at this. I'd love to adopt geb, but its been an uphill battle to date.
Might be a silly answer but did you install the chrome driver? http://code.google.com/p/selenium/wiki/ChromeDriver
For Firefox, you don't need to install a driver but for Chrome and IE, you do. That may be why your tests are running using FF and not chrome.
Good luck!
I am not sure that it is Geb related, I think you will get the similar behaviour when you run the tests using WebDriver Chrome Driver.
I have seen these kind of errors when Chrome is not on the path.
chrome.binary should always be the absolute path to the actual executable. for mac, this usually look like:
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
What version of Selenium/WebDriver you are using?
i am a big fan of both cucumber and vagrant. i am using cucumber to drive development with a BDD style and have configured and setup my dev environment once in a vagrant vm so it can be easily distributed to other developers.
i've hit a snag when it comes to testing js on the vagrant vm. i'm using capybara alongside cucumber and have tried both selenium and capybara-webkit as js drivers.
selenium wanted me to install firefox. so i packaged up the vagrantbox fully expecting it not to work and installed firefox on the vm.. after that it complained about being unable to get a stable connection with firefox. exact error message: 'unable to obtain stable firefox connection in 60 seconds'
webkit complained about 'webkit_server: cannot connect to X server'.. i installed xserver-org and still no dice.
would much prefer if i didn't have to install my whole environment on my host in order to do testing as that would kind of defeat the purpose of having a distributable vagrant vm that has everything a dev needs to work on the app.
any ideas? i've encountered a similar problem with the notifications from guard, but that seems like not nearly as big a deal as this issue.
I think that all drivers require X, to be installed.
So on linux server I do not have how do it.
Other way it using Firefox from host machine via selenium remote.
It mean javascript will be run on remote Firefox on any machine.
Remote Selenium WebDriver not responding to Cucumber tests
http://code.google.com/p/selenium/wiki/RubyBindings
It work.
Run selenium server on host
java -jar selenium-server-standalone.jar
Changes in spec_helper.rb
require "selenium-webdriver"
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.http.use-cache"] = false
Capybara.register_driver :firefox_host do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:url => 'http://10.0.2.2:4444/wd/hub',
:desired_capabilities => Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
)
end
Capybara.server_port = 9300
Capybara.app_host = 'http://localhost:9300'
Capybara.javascript_driver = :firefox_host
Changes in Vagrantfile
config.vm.forward_port 9300, 9300
You may want to try running firefox headless.
http://www.alittlemadness.com/2008/03/05/running-selenium-headless/
This way, you can run tests without seeing them as well.
I ran into a similar issue. Try ssh'ing into your VM and executing xhost + from the command line. This disables access control and allows clients to connect from any host to access your display.
Also, you might need to export DISPLAY=:0 as well, because the webdriver will default to using this display when it launches Firefox.