You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've needed to run some rather complex tests on a Nanoc website (involving lots of JS), and the best solution was to use Capybara. It's actually quite nice, and there are just a few gotchas to take care of.
Here's a small gist of the code I wrote:
classItemCheck < Checkdefbrowse_to(item)@current_item=itemendprotecteddefadd_issue(desc,subject: nil)super(desc,subject: (subject || @current_item.raw_filename))endendclassCapybaraCheck < ItemCheckdefinitialize(context)super(context)require"adsf"require"capybara"require"capybara/apparition"require"capybara/dsl"root="output"Capybara.server=:webrickCapybara.default_driver=:apparitionCapybara.save_path=Pathname.new(__dir__).join("..").realpathCapybara.app ||= Rack::Builder.newdo# use Rack::CommonLoggeruseRack::ShowExceptionsuseRack::LintuseRack::HeaduseAdsf::Rack::CachinguseAdsf::Rack::CORSuseAdsf::Rack::IndexFileFinder,root: root,index_filenames: %w(index.html)run ::Rack::File.new(root)end.to_appCapybara.reset_sessions!CapybaraCheck.includeCapybara::DSLenddefbrowse_to(item)super(item)visititem.pathenddefcheck_text(text)add_issue"Doesn't have #{text.inspect}"unlesshas_text?(text)enddefcheck_no_text(text)add_issue"Has text #{text.inspect}"unlesshas_no_text?(text)enddefwait_for_js# Obviously we would need something bettersleep1endend
And then using it is rather straightforward:
CapybaraCheck.define(:homepage)dobrowse_to@items["/fr/index.html"]check_no_text"Foobar"click_on"Buy"check_text"Free shipping!"click_on"Order now"add_issue"Wasn't redirected to payment gateway"unlesshas_current_path?(/mybank.com/,url: true)end
Question
Would you be interested in adding such a feature within Nanoc directly?
Notes
I'm a bit unsatisfied by the adsf part which is copy-pasted from adsf's code (unfortunately getting just the Rack app isn't available (and we'd most likely want to remove the logger anyway).
The code does require "capybara" when executing the initialize method. That's kind of weird, but otherwise Capybara would always be loaded alongside nanoc. But I really don't want/need Capybara to be loaded when simply building the site. Anyway, this trick works, but that was painful to write. Maybe checks should live in a separate directory (not /lib) and only be loaded when running them?
The text was updated successfully, but these errors were encountered:
Capybara is nice! I’ve been using it on other projects as well.
Would you be interested in adding such a feature within Nanoc directly?
I think this would be too far away from Nanoc’s purpose to include within Nanoc itself.
Arguably, even the checks functionality as a whole shouldn’t be part of Nanoc, but rather something independent that Nanoc can easily integrate with. The same goes for the deploy functionality.
I’ll move this issue to the features repository so that the discussion isn’t lost.
I've needed to run some rather complex tests on a Nanoc website (involving lots of JS), and the best solution was to use Capybara. It's actually quite nice, and there are just a few gotchas to take care of.
Here's a small gist of the code I wrote:
And then using it is rather straightforward:
Question
Would you be interested in adding such a feature within Nanoc directly?
Notes
require "capybara"
when executing theinitialize
method. That's kind of weird, but otherwise Capybara would always be loaded alongside nanoc. But I really don't want/need Capybara to be loaded when simply building the site. Anyway, this trick works, but that was painful to write. Maybe checks should live in a separate directory (not/lib
) and only be loaded when running them?The text was updated successfully, but these errors were encountered: