V
V
vovanmozg2015-03-25 10:31:29
Ruby on Rails
vovanmozg, 2015-03-25 10:31:29

How can I force a command in an rspec test to run without waiting for the previous command to complete?

Hi,
There are rspec tests in a rails application using Capybara poltergeist (which uses phantomjs). Frontend on Backbone.js. Some tests pass through time: debugging indicates that the desired content has not yet been loaded at the time of testing. If we add an artificial delay like sleep(inspection_time = 1), then the test passes.

describe 'Direct visit page /#/desk/page/[ID]' do
    before { sign_in user }
    it 'should contain page title' do
      visit "/#/desk/pages/#{page.id}"
      #sleep(inspection_time = 1)
      expect(page).to have_css(".page-detail p.title", :text => page.title)
    end
  end

js tests take so long to run, and unreliable delays further increase the execution time. Is there a good solution for the poltergeist driver (gem 'poltergeist', '1.6.0')?
Maybe you should abandon poltergeist in favor of, for example, capybara -webkit?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bmalets, 2015-03-31
@vovanmozg

I can suggest a few things about it:
1. to "parallelize" parallel_tests tests, (or you can just write a rake task that will run tests in different tty). There is also a guard to load several processors with the testran, and not just one
2. optimization of site_prizm, facory_firl, vcr, etc.
3. front-end testing. The browser driver that you use in smoke tests, for example,
starts the browser running through the pages - configure it so that it does not pull css and images (only html and js)
4. You relogin to the system before-hook before each it. Don't do it like this :)
Just override the method that kills the session after the end of each it so that it doesn't kill it.
then it will not be necessary to log in - it saves a lot of time. Here is my example, true selenium driver (the reset method is launched after each step, I just overridden it and commented out the lines with session deletion):

class Capybara::Selenium::Driver < Capybara::Driver::Base
  def reset!
    # Use instance variable directly so we avoid starting the browser just to reset the session
    if @browser
      begin
        #@browser.manage.delete_all_cookies <= cookie deletion is commented out!
      rescue Selenium::WebDriver::Error::UnhandledError => e
        # delete_all_cookies fails when we've previously gone
        # to about:blank, so we rescue this error and do nothing
        # instead.
      end
      @browser.navigate.to('about:blank')
    end
  end
end

V
vovanmozg, 2015-04-17
@vovanmozg

Thanks for the advice!
So far, we have made a crutch in the form of "rspec-retry": for separately marked tests, it tries to run the test several times, and if, for example, the test did not pass the first time, but passed the second time, then it is considered passed.
Can you show an example of using site_prizm?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question