Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run capybara in rake task

How can I run Capybara functionality in Rake task?

for example: visit('http://google.com')

Thank you!

like image 488
thesis Avatar asked Sep 17 '11 19:09

thesis


People also ask

How to run rake task locally and remotely with capelets?

As an added bonus, capelets you set how you want to run your rake task locally and remotely (no more bundle exec rake), just add this to your config/deploy.rbfile: # Configure Cape to execute Rake via Bundler, both locally and remotely.

How do I use Capistrano-rakegem to execute rake tasks?

Use the capistrano-rakegem Just install the gem without messing with custom capistrano recipes and execute desired rake tasks on remote servers like this: cap production invoke:rake TASK=my:rake_task

What is the use of rake in Ruby?

Rake enables you to define a set of tasks and the dependencies between them in a file, and then have the right thing happen when you run any given task. The combination of convenience and flexibility that Rake provides has made it the standard method of job automation for Ruby projects.

How do I run capybara tests on BrowserStack?

To run your first Capybara test on BrowserStack, follow the steps below: You can visit BrowserStack Automate Dashboard and see your test there. Protip: You can use our capability builder and select from a wide range of custom capabilities that BrowserStack supports.


1 Answers

Try something like this in the task:

require 'capybara'
require 'capybara/dsl'

Capybara.current_driver = :selenium
Browser = Class.new { include Capybara::DSL }
page = Browser.new.page
page.visit("http://www.google.com")
puts(page.html)
like image 121
tokland Avatar answered Oct 19 '22 03:10

tokland