I have feature specs in my Rails app that use Capybara to run tests through a browser. By default they use the phantomjs/poltergeist and rack-test drivers, which are headless.
It often is desirable to run a single spec (or spec file) using a capybara driver that runs a visible browser so that I can see what is happening. For this use case I use Selenium. When I want to run a spec using Selenium I set an environment variable (DEBUG=true) before running rspec like so:
DEBUG=true rspec spec/features/my_spec.rb
My spec_helper looks for the DEBUG environment variable and runs the spec with Selenium instead of the default drivers. I'd like to duplicate this capability in Rubymine, so that when I right-click on a spec in the project tree and click "Debug 'Run spec...'" it sets up the DEBUG environment variable and runs the spec with the Selenium driver. How can I configure the default 'Debug' configuration to set up this environment variable?
Next to the run button on the tool bar, there's the name of the configuration that is active, click it and choose Edit Configuration inside you'll find server arguments you can write there the DEBUG=true and it will be sent to the runner file.
Related
I am currently using Capybara selenium/webkit in functional testing, I don't really understand how it works behind the scene.
By checking the Capybara document, the selenium by default is using firefox browser for testing. It doesn't even mention what is the version it is using. (I didn't install firefox, I think it came together with the gem selenium-webdriver or capybara-webkit)
My question:
1) If I want to trigger my test on specific browser version, is it possible? How can I do that? For example, on Chrome browser version 53.1.2.
2) The automated functional test all conducted behind the scene, is it possible to visualize the testing procedure? For example, Selenium driver launch the browser and visualize the click/scroll/drag effect along with the test running?
The selenium-webdriver gem does not install firefox, and if you're not seeing a browser opening when you run your tests you are not actually using selenium-webdriver, since when used with desktop browsers (firefox, chrome, IE, safari) it will open those browsers and you can watch it interact with the app being tested.
When you run tests Capybara uses the driver identified by Capybara.current_driver at the start of each test. In the normal Capybara configuration (when using rspec) the current driver is set in a before block - https://github.com/teamcapybara/capybara/blob/2.12.0/lib/capybara/rspec.rb#L26 - to either the value of Capybara.javascript_driver or Capybara.default_driver depending on whether the test has a js: true metadata tag or not - see https://github.com/teamcapybara/capybara/blob/2.12.0/README.md#drivers and https://github.com/teamcapybara/capybara/blob/2.12.0/README.md#using-capybara-with-rspec .
By default Capybara.javascript_driver = :selenium and the default config for that driver would use firefox. Therefore if you add the js: true metadata to one of your tests it will use the selenium driver and attempt to run your system installed firefox (depending on versions installed you may also need to install geckodriver), raising errors if there is no FF installed. You will also want to read about database_cleaner in the Capybara README and get that installed correctly for testing. If you don't specify the js: true metadata then (by default) your test is using the rack_test driver which does not process CSS or JS and is really only useful for very basic form and link processing testing. If you want all your tests to run with selenium you could set Capybara.default_driver = :selenium which will then be used for all the tests (you will still need to set up database_cleaner)
The Capybara README has instructions for how to configure the :selenium driver to use Chrome if wanted (you will also need to install chromedriver), and the selenium-webdriver documentation will have details on how you can specify alternate instances of the browsers (if you have multiple versions installed).
If on the other hand you want to use the capybara-webkit gem (or Poltergeist) you would need to specify the name of the registered driver - for instance Capybara.javascript_driver = :webkit/:poltergeist - see their READMEs for details of the different options you can specify for each of those drivers when registering them.
I need to make an environmental variable available to Sublime Text (3).
Specifically, I am using Ruby Test to run RSpec tests on a Rails app. In order for my Rails App to use Postgres it needs access to an env that I'm setting in my .bash_profile:
# Postgres
export PGHOST=localhost
If I launch ST from the Terminal, this env is available because my .bash_profileis loaded when I open the shell, however if I open ST by launching the app via its icon or via Alfred, .bash_profile is never loaded and this env is not available to ST, causing all my RSpec tests to fail due to problems connecting to the Postgres database.
So how can I pass environmental variables into Sublime Text (3)?
Just a guess, but if you are using the build system, perhaps adding the "shell": true option? If it's a plugin you are working through, perhaps create an issue for the plugin (I'm guessing it's on github)
I've noticed that when I run tests (using Rspec and spork, if that matters), my hostname is set to www.example.com. So if I do:
visit sports_url
the test is actually going to www.example.com/sports.
This is a problem because I need to run some of the tests with selenium (to get javascript support). Also, I noticed my emails where being marked as coming from www.example.com.
What did I mess up? Why is the test environment running as example.com? Can I configure this somewhere? I would assume it should be programatic (depending on what port the test server starts up on).
You can configure the test environment domain, then set up DNS to do what you need.
How do I change the default "www.example.com" domain for testing in rails?
is there a way to debug all/single tests in Aptana Studio / Eclipse?
ruby-debug19 & ruby-debug-ide are installed and I'm able to set breakpoints and debug my development environment, e.g. in a controller's index method. If I go to http://localhost:3000/controler_name eclipse opens debugging perspective and halts.
But how to do that with tests / rspec tests?
Thanks in advance.
For a normal ruby file, right click on it and select Debug As > Ruby application.
If your test is a rails one that requires some setup, or you want to debug the whole suite, you'll need to generate a debug configuration manually (or edit one manually).
Run > Debug As > Debug configurations... Then add an entry under Ruby application. Point it at your rake script path (say /usr/local/bin/rake) as the file to launch and then edit the arguments to pass in your app's Rakefile as the first arg and the rake task as the second arg. (i.e. /my/path/to/project/Rakefile tests)
Is is possible to run capybara with nginx and passenger? instead or webrick? Capybara is installed with cucumber in a rails app.
It is easy - the only thing you have to do is to switch your mind - neither capybara nor cucumber are not tied to local environment you can test application that is located in internet and it will not care about it - you can even test google.com if you want.
For your particular problem you'll have to set
Capybara.run_server = false
Capybara.server_port = 8000 # or whatever port is your instance of nginx is configured to serve
Capybara.app_host = 'http://www.google.com' # if your instance is running on remote machine, else just drop it and capybara will use localhost
You can easily control restarting of your application using cucumber hooks, you can configure it to restart before each test or before test suite. (See cucumber wiki) Within hook you'll have to issue FileUtils.touch tmp/restart.txt command. The same with database - you can manually setup hook to truncate it whenever it is needed (See database_cleaner gem)