capycon - New Ruby GEM for Running Capybara on Console


Testing is enjoyable if you are using the right tools and technologies, of-course you also need to understand the philosophy behind the testing. I generally use testing tools interactively to try different options that the tool you are using gives as alternatives. For Selenium and Capybara, I have scripts to run get to get them ready on my console, you can read more this post for Windows and this for Unix-like. Under the quarantine days, I wanted to create a Ruby GEM for any want to get Capybara experience on the console for their project. 


Capycon is simple, the short version of Capybara-Console, a GEM file so you can install it by:

gem install capycon

To use it, open your terminal and switch irb or pry and then require the capycon, then you use all the functionality of the Capybara on the console. See the following steps;
~/P/p/c/capy_con (master ⚡→☡) pry
[1] pry(main)> 
[2] pry(main)> require "capycon"

  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *                                                                           *
  *                capycon - CAPYBARA CONSOLE                                 *
  *                                                                           *
  *  Default driver is :driver_iphone6_vertical_visible                       *
  *  To set the site name as environment variable:                            *
  *    echo 'export SITE_NAME=http://www.github.com' >> ~/.bash_profile       *
  *                                                                           *
  *  To set the driver  as environment variable:                              *
  *    echo 'export DRIVER=driver_chrome_visible' >> ~/.bash_profile          *
  *                   OR                                                      *
  *  You can set the driver by one of the following options                   *
  *                                                                           *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    Capybara.current_driver = :driver_chrome_visible
    Capybara.current_driver = :driver_chrome_fullscreen_headless
    Capybara.current_driver = :driver_iphone6_vertical_visible
    Capybara.current_driver = :driver_iphone6_vertical_headless
    Capybara.current_driver = :driver_iphone6_horizontal_visible
    Capybara.current_driver = :driver_iphone6_horizontal_headless
    Capybara.current_driver = :driver_iphone6plus_vertical_headless
    Capybara.current_driver = :driver_iphone6plus_horizontal_headless
    Capybara.current_driver = :driver_ipad_vertical_visible
    Capybara.current_driver = :driver_ipad_horizontal_visible
    Capybara.current_driver = :driver_ipad_vertical_headless
    Capybara.current_driver = :driver_ipad_horizontal_headless
    Capybara.current_driver = :driver_samsungs6_vertical_headless
    Capybara.current_driver = :driver_samsungs6_horizontal_headless
    Capybara.current_driver = :driver_samsungsTabA_horizontal_headless
    Capybara.current_driver = :driver_samsungsTabA_vertical_headless
    Capybara.current_driver = :driver_desktop_headless
=> true
[3] pry(main)> Capybara.current_driver = :driver_chrome_visible
=> :driver_chrome_visible
[4] pry(main)> visit "/"
=> nil
[5] pry(main)> find(".js-site-search-form > label > input").send_keys "capycon"
=> #<Capybara::Node::Element tag="input" path="/HTML/BODY[1]/DIV[1]/HEADER[1]/DIV[1]/DIV[2]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/FORM[1]/LABEL[1]/INPUT[1]">
[6] pry(main)> find(".js-site-search-form > label > input").send_keys :return
=> Obsolete #<Capybara::Node::Element>
[7] pry(main)> page.has_content? "gunesmes/capycon"
=> true

When you require the capycon, it automatically opens www.testrisk.com with Chrome driver by default. But you change the current driver by one of the following in the list. If you always want to open the URL as SITE_NAME that you generally test with the driver you want, you set them as environment variables in your bash_profile. For this run the following commands:

echo 'export SITE_NAME=http://www.github.com' >> ~/.bash_profile
echo 'export DRIVER=driver_chrome_visible' >> ~/.bash_profile

I will be appreciated to get feedback from you on GitHub.

Popular posts from this blog

Selenium Error "Element is not currently interactable and may not be manipulated"

Change Default Timeout and Wait Time of Capybara

Performance Testing on CI: Locust is running on Jenkins

Selenium Chromedriver Error Message: u'unknown error: unable to discover open pages

Getting the text of elements in Espresso