0

Sorry for the confusing title, i've been really trying to find a good solution to writing automated tests for maintenance projects (To identify areas that potentially break after doing upgrades to rails versions or w/e it may be. Not all of our web apps are rails though).

Im somewhat familiar with using Capybara/Cucumber (Although Cucumber will be useless for this since I won't need to display any acceptance tests or anything human readable).

Anyways, is there a way for me to write the test and see them happen on a normal browser, then easily switch it to headless (Like using Poltergeist/PhantomJS)?

Capybara seems ideal for this, although im a bit confused.....if Im not using Cucumber with Capybara, what DO I use language wise? Rspec?

Edit: Also any suggestions on the initial driver to use? I need to be able to change things easily without having to rewrite the tests. I've seen that Webkit is a bit faster than Selenium? But I saw that webkit was also headless....and I need to confirm visually the tests are ok (And to Demo them) so im not sure that will work?

  • 1
    I think you're mistaken on what Webkit is. Webkit is a rendering engine that can be used by browsers to transform the website's code into something that can be shown on a screen. en.wikipedia.org/wiki/WebKit – Cronax May 2 '16 at 8:44
  • When Capybara mentions using WebKit, they are using some other technology (similar to Selenium) to drive that rendering engine. – Cronax May 2 '16 at 8:49
1

Firstly, you should separate your process from your technology stack. Evidently, you've defined a process for yourself: you'd like to write tests that you can execute manually to verify certain things and that you can later use in unattended runs to verify those same things. Now you need to find a technology stack which will let you do this.

Now, given your needs, ideally you need a framework that separates the 'code' that makes up the automated tests from the 'code' that drives the actual browser instance, since that will allow you to use the exact same test code for both the manual 'visual' testing and the unattended 'headless' testing.

I personally have no experience with using Capybara, but if it meets those criteria then you should be able to use it without needing to pick up another framework. Just because they promote the usage of a framework for a certain type of testing doesn't mean it can't be used for other testing.

A framework I am personally familiar with is the Robot Framework, which can meet your needs by using the Selenium Webdriver library. Tests are defined in semi-natural language, similar to Capybara/Cucumber, and the actual words (named 'keywords' in this context) will determine what code is actually executed. A large number of keywords are supplied out-of-the-box and virtually anything else you require you can construct custom keywords for, using either built-in keywords, custom keywords, or even custom keywords that run i.e. python code. Changing them from tests that run visually to headless tests is as simple as changing a single parameter, from i.e. Firefox to PhantomJS.

1

Capybara is a Ruby framework used for emulating a users behavior in a browser.

You can use it with whatever test framework you wish, RSpec, minitest, etc. When using Capybara, as long as you stick to its API (no calling of methods directly on the driver) you should be able to switch between different drivers relatively painlessly, using the selenium driver when you want to watch the tests, poltergeist or capybara-webkit when you want headless with more speed. You can change the driver at any time by setting Capybara.default_driver, Capybara.current_driver, and Capybara.javascript_driver as needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.