Git Product home page Git Product logo

rspec-capybara-docker-grid's Introduction

Build Status

A Dockerized Selenium Grid with RSpec and Capybara

I built this project to quickly provision a dockerized environment for running UI tests against a dockerized app. It employs a dockerized Selenium Grid which yields a far more cost-effective CI solution compared to purchasing and maintaining dedicated machines.

I've included bash scripts in the bin/ directory as wrappers for the docker-compose commands. Hopefully, once you've completed the initial setup, you won't have to recall any docker commands. ๐Ÿ˜ƒ

Both RSpec and Capybara are automatically provisioned in the testrunner docker image. You can easily customize their configurations in spec/spec_helper.rb.

Dependencies

  • a clone of this repo on your machine
  • Docker

Setup

Here's the default workflow when writing RSpec tests in this project:

  • bin/build && bin/start && bin/test
  • make changes to files inside the spec/ directory
  • verify changes with bin/build && bin/start && bin/test

:sadtrombone:

To make your life easier, first do this:

cp docker-compose.dev.override.yml docker-compose.override.yml

Now any changes you make within this repo on your host file system will automatically show up in the testrunner docker container. Here's your new workflow:

  • bin/build && bin/start && bin/test
  • make changes to files inside the spec/ directory
  • bin/test

:party:

Some folks have reported file permission issues with this workflow, so YMMV.

Where do I add my app?

By default this project will use a bare-bones Sinatra web app as the system under test (SUT). If you want to replace that default web app with your own, open the docker-compose.yml file, find the web service configuration, and replace mycargus/hello_docker_world:master with your app's docker image label.

For example:

web:
  image: my-app-under-test:master

If you're not sure how to create or pull a docker image, I recommend working through the official Docker tutorial located on their website.

How do I execute the tests?

Start the Selenium hub, the SUT, and the Selenium browser nodes:

bin/start

Execute the tests with Rspec and Capybara from inside the testrunner container:

bin/test

When you're done, stop and remove the docker containers:

bin/stop

I want to see the app under test. How can I do that?

If you're using the default web app provided, then open your browser and go to http://locahost:8080.

If you're using your own web app, make sure to expose a port in your web app's Dockerfile. For example, if you have EXPOSE 9887 in your web app's Dockerfile, then you can view it at http://localhost:9887.

Can I view the Selenium grid console?

Yep! After having started the Selenium hub and nodes (bin/start), open a browser and go to http://localhost:4444, then click the 'console' link.

A test is failing. How do I debug it?

Start the Selenium hub, the app under test, and the Selenium debug browser nodes:

bin/start-debug

View the chrome debug node via VNC (password: secret):

open vnc://localhost:5900

View the firefox debug node via VNC (password: secret):

open vnc://localhost:5901

Next execute the tests against the browser nodes and watch them run in the VNC window(s):

bin/test

Again, once you're finished:

bin/stop

rspec-capybara-docker-grid's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar mycargus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rspec-capybara-docker-grid's Issues

Failed to connect

In case this is a known issue I'll paste it here before spending a lot of time figuring it out.

(I know, this sounds lazy, but I'm going through dozens of people's dockerized rspec solutions and looking for the first one that is easier to get running than building it myself.)

Output:

kai@KaiMacLaptop selenium-rspec $ git clone https://github.com/mycargus/docker-grid-rspec-capybara.git
Cloning into 'docker-grid-rspec-capybara'...
remote: Counting objects: 87, done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 87 (delta 40), reused 87 (delta 40), pack-reused 0
Unpacking objects: 100% (87/87), done.
Checking connectivity... done.
kai@KaiMacLaptop selenium-rspec $ ls
docker-grid-rspec-capybara
kai@KaiMacLaptop selenium-rspec $ cd docker-grid-rspec-capybara/
kai@KaiMacLaptop docker-grid-rspec-capybara (master) $ ls
Dockerfile		Gemfile.lock		README.md		docker-compose.yml	spec
Gemfile			LICENSE.txt		bin			grid
kai@KaiMacLaptop docker-grid-rspec-capybara (master) $ ls bin
build		debug_start	start		stop		test
kai@KaiMacLaptop docker-grid-rspec-capybara (master) $ bin/start
No stopped containers
Creating network "dockergridrspeccapybara_default" with the default driver
Pulling web (mycargus/hello_docker_world:latest)...
latest: Pulling from mycargus/hello_docker_world
ba76e97bb96c: Pull complete
4d6181e6b423: Pull complete
4854897be9ac: Pull complete
4458f3097eef: Pull complete
9989a8de1a9e: Pull complete
ea70060f797f: Pull complete
52b1993bdf6d: Pull complete
025c77999500: Pull complete
78e03c241c59: Pull complete
da9a09dae808: Pull complete
0312b7a5ca9d: Pull complete
2341f9d33aa7: Pull complete
cfcb30eaedc4: Pull complete
fd773e04dc7a: Pull complete
4bd4e4f6f39a: Pull complete
dc000cf7ac7c: Pull complete
a47d0c43b4cb: Pull complete
33dfe777c6a0: Pull complete
3390be7782cc: Pull complete
a7a98e835be4: Pull complete
5ca3da6202bc: Pull complete
3b8cf3523b2d: Pull complete
da3c86f22689: Pull complete
610fe81e3422: Pull complete
37bfd2dcbfb3: Pull complete
7fb41199ad76: Pull complete
1550964eb61a: Pull complete
02759016ae08: Pull complete
1955818543ac: Pull complete
e2cda21da4f3: Pull complete
d5b6943d66c8: Pull complete
657afbbb42cb: Pull complete
Digest: sha256:502cb4d19616b94e806019d22b0ed39d611deee9ade79389d7250ca8c4967160
Status: Downloaded newer image for mycargus/hello_docker_world:latest
Pulling hub (selenium/hub:3.0.1)...
3.0.1: Pulling from selenium/hub
8aec416115fd: Already exists
695f074e24e3: Already exists
946d6c48c2a7: Already exists
bc7277e579f0: Already exists
2508cbcde94b: Already exists
87f3935fea59: Pull complete
eec2af8fab00: Pull complete
4260b93cf923: Pull complete
0949e2c674ff: Pull complete
c055c1c292d8: Pull complete
b72060544a02: Pull complete
f7501c5a62d7: Pull complete
09b6809fe888: Pull complete
7bb14cb35cf1: Pull complete
Digest: sha256:d4b35e37087fd74ae9ba619c258814b69707f6daf4ea1e03d8436ed53e00ab57
Status: Downloaded newer image for selenium/hub:3.0.1
Pulling node-firefox (selenium/node-firefox:3.0.1)...
3.0.1: Pulling from selenium/node-firefox
8aec416115fd: Already exists
695f074e24e3: Already exists
946d6c48c2a7: Already exists
bc7277e579f0: Already exists
2508cbcde94b: Already exists
87f3935fea59: Already exists
eec2af8fab00: Already exists
4260b93cf923: Already exists
0949e2c674ff: Already exists
c055c1c292d8: Already exists
ebc8bdfd17e5: Pull complete
fe411204c602: Pull complete
ca0fc8e30444: Pull complete
011d924db270: Pull complete
2ff3709a636d: Pull complete
f31f513f6c86: Pull complete
e96bfd55726f: Pull complete
Digest: sha256:da8b3c412b6aa32ea9a5e63e913c0c5edb285d5e7b829ac4112825d536a65ffd
Status: Downloaded newer image for selenium/node-firefox:3.0.1
Pulling node-chrome (selenium/node-chrome:3.0.1)...
3.0.1: Pulling from selenium/node-chrome
8aec416115fd: Already exists
695f074e24e3: Already exists
946d6c48c2a7: Already exists
bc7277e579f0: Already exists
2508cbcde94b: Already exists
87f3935fea59: Already exists
eec2af8fab00: Already exists
4260b93cf923: Already exists
0949e2c674ff: Already exists
c055c1c292d8: Already exists
ebc8bdfd17e5: Already exists
fe411204c602: Already exists
ca0fc8e30444: Already exists
f86ce080d9e9: Pull complete
58fa63ecb260: Pull complete
6ac376cc61d8: Pull complete
f3f919ca336b: Pull complete
397f07646f34: Pull complete
c52f1a15e4bc: Pull complete
df2c0a2110ef: Pull complete
Digest: sha256:7befa2f4008032f2ae551920e7cf28c5f8c8674cb1ee66812daf223c41cf610a
Status: Downloaded newer image for selenium/node-chrome:3.0.1
Creating dockergridrspeccapybara_web_1
Creating dockergridrspeccapybara_hub_1
Creating dockergridrspeccapybara_node-firefox_1
Creating dockergridrspeccapybara_node-chrome_1
kai@KaiMacLaptop docker-grid-rspec-capybara (master) $ bin/test
Building testrunner
Step 1/11 : FROM instructure/ruby:2.3
2.3: Pulling from instructure/ruby
30d541b48fc0: Pull complete
8ecd7f80d390: Pull complete
46ec9927bb81: Pull complete
2e67a4d67b44: Pull complete
7d9dd9155488: Pull complete
59a94b809ac7: Pull complete
b05d73938bea: Pull complete
f43764c10683: Pull complete
d8667b3c8760: Pull complete
d9340e18df5f: Pull complete
035172710b60: Pull complete
f2d6c008ffd2: Pull complete
6f03e693658f: Pull complete
24ac24cef97d: Pull complete
14521cca7141: Pull complete
0d08bee79066: Pull complete
5dbd0beda8aa: Pull complete
472687a281a0: Pull complete
Digest: sha256:6e7613923966395510710d5554c086beb80a7c043b72f075e6b729e39a20106f
Status: Downloaded newer image for instructure/ruby:2.3
 ---> 785ea068b152
Step 2/11 : USER root
 ---> Running in 3c10034f55f0
 ---> 2452c4cdc2a4
Removing intermediate container 3c10034f55f0
Step 3/11 : ENV APP_HOME /usr/src/app
 ---> Running in 56d9beeba9b7
 ---> d7170735b138
Removing intermediate container 56d9beeba9b7
Step 4/11 : WORKDIR $APP_HOME
 ---> 189a0287a7f1
Removing intermediate container c311f25afa43
Step 5/11 : COPY Gemfile Gemfile.lock $APP_HOME/
 ---> 640ed5115061
Removing intermediate container 554a3eed7f55
Step 6/11 : USER docker
 ---> Running in 5707254194b2
 ---> f2cd20b20d5a
Removing intermediate container 5707254194b2
Step 7/11 : RUN bundle install --quiet --jobs 8
 ---> Running in 7b8b16280fc9
 ---> d3e737eae1c3
Removing intermediate container 7b8b16280fc9
Step 8/11 : USER root
 ---> Running in 591072df4d10
 ---> 06a85c56c481
Removing intermediate container 591072df4d10
Step 9/11 : COPY . $APP_HOME
 ---> 70ef38796414
Removing intermediate container 4cba91a12dc9
Step 10/11 : RUN chown -R docker:docker $APP_HOME
 ---> Running in 46842a1d4ede
 ---> d88074e6f4ee
Removing intermediate container 46842a1d4ede
Step 11/11 : USER docker
 ---> Running in 3ced944048cd
 ---> b854506bf249
Removing intermediate container 3ced944048cd
Successfully built b854506bf249
WARNING: Image for service testrunner was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.


############################
Starting Firefox test run...
############################


Loading the app under test
Capybara test started
  displays the home page (FAILED - 1)

Failures:

  1) Loading the app under test displays the home page
     Failure/Error: visit '/'

     SocketError:
       Failed to open TCP connection to selenium.hub.docker:80 (getaddrinfo: Name or service not known)
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:103:in `response_for'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:57:in `request'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:653:in `raw_execute'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:124:in `create_session'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:88:in `initialize'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:57:in `new'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:57:in `for'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver.rb:82:in `for'
     # /home/docker/.gem/ruby/2.3.0/gems/capybara-2.10.1/lib/capybara/selenium/driver.rb:20:in `browser'
     # /home/docker/.gem/ruby/2.3.0/gems/capybara-2.10.1/lib/capybara/selenium/driver.rb:53:in `visit'
     # /home/docker/.gem/ruby/2.3.0/gems/capybara-2.10.1/lib/capybara/session.rb:240:in `visit'
     # /home/docker/.gem/ruby/2.3.0/gems/capybara-2.10.1/lib/capybara/dsl.rb:52:in `block (2 levels) in <module:DSL>'
     # ./spec/features/example_spec.rb:7:in `block (2 levels) in <top (required)>'
     # grid/testrunner.rb:40:in `block in <main>'
     # grid/testrunner.rb:12:in `block in run'
     # grid/testrunner.rb:10:in `each'
     # grid/testrunner.rb:10:in `run'
     # grid/testrunner.rb:39:in `<main>'
     # ------------------
     # --- Caused by: ---
     # SocketError:
     #   getaddrinfo: Name or service not known
     #   /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:103:in `response_for'

Finished in 0.20663 seconds (files took 0.70478 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/features/example_spec.rb:4 # Loading the app under test displays the home page



############################
Starting Chrome test run...
############################


Loading the app under test
Capybara test started
  displays the home page (FAILED - 2)

Failures:

  1) Loading the app under test displays the home page
     Failure/Error: visit '/'

     SocketError:
       Failed to open TCP connection to selenium.hub.docker:80 (getaddrinfo: Name or service not known)




     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:103:in `response_for'

















     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:57:in `request'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:653:in `raw_execute'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:124:in `create_session'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:88:in `initialize'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:57:in `new'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:57:in `for'
     # /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver.rb:82:in `for'
     # /home/docker/.gem/ruby/2.3.0/gems/capybara-2.10.1/lib/capybara/selenium/driver.rb:20:in `browser'
     # /home/docker/.gem/ruby/2.3.0/gems/capybara-2.10.1/lib/capybara/selenium/driver.rb:53:in `visit'
     # /home/docker/.gem/ruby/2.3.0/gems/capybara-2.10.1/lib/capybara/session.rb:240:in `visit'
     # /home/docker/.gem/ruby/2.3.0/gems/capybara-2.10.1/lib/capybara/dsl.rb:52:in `block (2 levels) in <module:DSL>'
     # ./spec/features/example_spec.rb:7:in `block (2 levels) in <top (required)>'
     # grid/testrunner.rb:40:in `block in <main>'
     # grid/testrunner.rb:12:in `block in run'
     # grid/testrunner.rb:10:in `each'
     # grid/testrunner.rb:10:in `run'
     # grid/testrunner.rb:39:in `<main>'
     # ------------------
     # --- Caused by: ---
     # SocketError:
     #   getaddrinfo: Name or service not known
     #   /home/docker/.gem/ruby/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:103:in `response_for'

Finished in 0.2044 seconds (files took 0.02459 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/features/example_spec.rb:4 # Loading the app under test displays the home page

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.