Running Capybara Tests for Ruby Apps in Remote Browsers
Do you have concerns about how your Ruby applications work in Internet Explorer? Do you believe that checking for bugs by emulating previous versions with different modes is enough? Even if you skip some legacy versions, you can still face problems with lack of support for the JSON format, HTML5 tags, or ECMAScript, limitations for CSS selectors, and many other issues that cannot be detected by just changing a browser mode. In fact, there are a lot of bugs that can only be reproduced on certain platforms and browsers.
To identify such problems, we suggest that you run your Capybara tests in remote browsers. In this blog post, I provide step-by-step instructions on how to use virtual machines and BrowserStack along with code, which you can copy-paste to save time.
Using a personal virtual machine
Feel free to read Capybara’s docs before working with the product.
- Install a virtual machine (VM) with a desired browser. You can use your own distributive or ievms.
- Make sure Java and desired browsers are installed on the VM.
- Run Selenium Server on the VM.
java –jar selenium-server-standalone-2.35.0.jar -role hub -multiWindow -browserSessionReuse
- Run on WebDriver.
java –jar selenium-server-standalone-2.35.0.jar -role webdriver -hub http://127.0.0.1:4444/grid/register -port 5555
- Configure forwarding TCP port 4444 from a host machine to a guest machine.
- Add to
- Run tests.
SELENIUM=remote bundle exec rspec spec/features/
- You can easily change Internet Explorer to Chrome, Firefox, etc., and run tests again.
- Create account on BrowserStack
- Download and put
- Make sure Java and сURL are installed on you VM
- Add to
- Run tests
SELENIUM=browserstack browser=IE browser_version=11.0 bundle exec rspec spec/features/
Testing in remote browsers assumes using Selenium WebDriver. So, you should make sure all your tests are passed using Selenium if previously you used WebKit or another tool.
By using a personal VM, you have more control over your browsers, you can even change browser profiles or other options. However, BrowserStack allows you to run your tests on a lot of different combinations of platforms and browsers and even mobile emulators without any additional installations. Speed of testing, though, depends on network latency and a selected plan. Fortunately, you can run tests in several treads across different browsers or tests.
In addition, BrowserStack gives you the possibility to do live testing and debug your local application or folder with a prototype. You can even check responsiveness.
Feel free to improve my Capybara integration with BrowserStack. I’ll be happy if it inspires someone to create a new gem. You can ask any questions here or in Skype of BrowserStack support.