Problems with namespaces inside World

46 views
Skip to first unread message

David García

unread,
Oct 27, 2014, 12:19:57 PM10/27/14
to cu...@googlegroups.com
I wanted to use Cucumber + Capybara together with Calabash in a project where we test both an Android app and a web app. I'm having some problems because some methods loaded in the World have the same name. For instance, 'page' or 'click_button' are both defined in Calabash and Capybara, so if I do page.visit for capybara, the method from calabash is called. I understand that this setup is quite concrete, but I guess this can happen to other people that want to use different gems inside the World.

Is there any solution or workaround for that? I could use for instance Capybara.current_session.visit instead of simply 'visit', but given that the steps and helpers used for capybara and calabash are separated, I would like a cleaner solution, so Capybara modules cannot see methods from Calabash.

Andrew Premdas

unread,
Oct 27, 2014, 2:27:12 PM10/27/14
to cu...@googlegroups.com
On 27 October 2014 16:19, David García <david...@gmail.com> wrote:
I wanted to use Cucumber + Capybara together with Calabash in a project where we test both an Android app and a web app. I'm having some problems because some methods loaded in the World have the same name. For instance, 'page' or 'click_button' are both defined in Calabash and Capybara, so if I do page.visit for capybara, the method from calabash is called. I understand that this setup is quite concrete, but I guess this can happen to other people that want to use different gems inside the World.

Is there any solution or workaround for that? I could use for instance Capybara.current_session.visit instead of simply 'visit', but given that the steps and helpers used for capybara and calabash are separated, I would like a cleaner solution, so Capybara modules cannot see methods from Calabash.

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


If you look at the -r option of cucumber you'll see you can control what you include in a particular run. Perhaps you could extract the capybara stuff from env.rb into something like support/capybara, do the same for calabash and then use cucumber.yml to create seperate profiles for each one. A limitation of this approach is that you won't be able to use both tools in the same session. Anyhow hope that helps

Andrew

--
------------------------
Andrew Premdas

David García

unread,
Oct 27, 2014, 4:02:07 PM10/27/14
to cu...@googlegroups.com
Unfortunately that's the case, I need to use both in the same session

David

Steve Tooke

unread,
Oct 27, 2014, 5:13:11 PM10/27/14
to cu...@googlegroups.com

On 27 Oct 2014, at 20:02, David García <david...@gmail.com> wrote:

Unfortunately that's the case, I need to use both in the same session

I haven't used calabash, but for capybara you don't need to require 'capybara/cucumber' and include the DSL in the world. 

Something like this might give you an idea:

require 'capybara'

module WebHelper
  def web_driver
    @web_driver ||= Driver.new
  end

  class Driver
    include Capybara::DSL

     # write methods here to interact with web app
     def visit_home_page
        visit '/'
     end
     
     def page_title
        page.find('h1').text
     end
  end
end
World(WebHelper)

# or you can use web_driver.visit / 
# web_driver.page etc from step defs 

I haven't tested this explicitly, but tend to do something like this for most projects. I prefer to push code down into an automation layer like this as it is more reusable than step defs. 

Steve

-- typed on a device that autocorrects when I'm not looking. 

--

David García

unread,
Oct 28, 2014, 10:46:51 AM10/28/14
to cu...@googlegroups.com
I've gave it a try, doing so for calabash instead of Capybara, but I found couple of problems:
- Calabash has some helpers which use cucumber methods (embed), and as the helpers are not in World, it can't access these methods
- Calabash provides some predefined steps, which can't access its methods because they are not in World.
I could do what you purposed for capybara, but this means that I have to do "webdriver." for every single method I want to call. I guess this is doable, but makes World kind of useless.

I'm trying to find a way to differenciate the how/where methods are called, so from World you could know which method you have to call, but I'm kind of stuck.

Konstantin Trunin

unread,
May 5, 2015, 4:44:23 AM5/5/15
to cu...@googlegroups.com
Have you found solution?
Reply all
Reply to author
Forward
0 new messages