Skip to content

Commit 1f7cca2

Browse files
committed
add_ruby_capybara
1 parent f36066e commit 1f7cca2

File tree

9 files changed

+259
-0
lines changed

9 files changed

+259
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
.bundle
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6+
7+
# gem "rails"
8+
9+
gem "mailslurp_client", "~> 11.5"
10+
11+
gem "capybara", "~> 3.35"
12+
13+
gem "selenium-webdriver", "~> 3.142"
14+
15+
gem "cucumber", "~> 5.3"
16+
17+
gem "typhoeus", "~> 1.4"
18+
19+
gem "rspec", "~> 3.10"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
activesupport (6.1.3.1)
5+
concurrent-ruby (~> 1.0, >= 1.0.2)
6+
i18n (>= 1.6, < 2)
7+
minitest (>= 5.1)
8+
tzinfo (~> 2.0)
9+
zeitwerk (~> 2.3)
10+
addressable (2.7.0)
11+
public_suffix (>= 2.0.2, < 5.0)
12+
builder (3.2.4)
13+
capybara (3.35.3)
14+
addressable
15+
mini_mime (>= 0.1.3)
16+
nokogiri (~> 1.8)
17+
rack (>= 1.6.0)
18+
rack-test (>= 0.6.3)
19+
regexp_parser (>= 1.5, < 3.0)
20+
xpath (~> 3.2)
21+
childprocess (3.0.0)
22+
concurrent-ruby (1.1.8)
23+
cucumber (5.3.0)
24+
builder (~> 3.2, >= 3.2.4)
25+
cucumber-core (~> 8.0, >= 8.0.1)
26+
cucumber-create-meta (~> 2.0, >= 2.0.2)
27+
cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
28+
cucumber-gherkin (~> 15.0, >= 15.0.2)
29+
cucumber-html-formatter (~> 9.0, >= 9.0.0)
30+
cucumber-messages (~> 13.1, >= 13.1.0)
31+
cucumber-wire (~> 4.0, >= 4.0.1)
32+
diff-lcs (~> 1.4, >= 1.4.4)
33+
multi_test (~> 0.1, >= 0.1.2)
34+
sys-uname (~> 1.2, >= 1.2.1)
35+
cucumber-core (8.0.1)
36+
cucumber-gherkin (~> 15.0, >= 15.0.2)
37+
cucumber-messages (~> 13.0, >= 13.0.1)
38+
cucumber-tag-expressions (~> 2.0, >= 2.0.4)
39+
cucumber-create-meta (2.0.4)
40+
cucumber-messages (~> 13.1, >= 13.1.0)
41+
sys-uname (~> 1.2, >= 1.2.1)
42+
cucumber-cucumber-expressions (10.3.0)
43+
cucumber-gherkin (15.0.2)
44+
cucumber-messages (~> 13.0, >= 13.0.1)
45+
cucumber-html-formatter (9.0.0)
46+
cucumber-messages (~> 13.0, >= 13.0.1)
47+
cucumber-messages (13.2.1)
48+
protobuf-cucumber (~> 3.10, >= 3.10.8)
49+
cucumber-tag-expressions (2.0.4)
50+
cucumber-wire (4.0.1)
51+
cucumber-core (~> 8.0, >= 8.0.1)
52+
cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
53+
cucumber-messages (~> 13.0, >= 13.0.1)
54+
diff-lcs (1.4.4)
55+
ethon (0.12.0)
56+
ffi (>= 1.3.0)
57+
ffi (1.15.0)
58+
i18n (1.8.10)
59+
concurrent-ruby (~> 1.0)
60+
mailslurp_client (11.5.20)
61+
middleware (0.1.0)
62+
mini_mime (1.1.0)
63+
mini_portile2 (2.5.0)
64+
minitest (5.14.4)
65+
multi_test (0.1.2)
66+
nokogiri (1.11.2)
67+
mini_portile2 (~> 2.5.0)
68+
racc (~> 1.4)
69+
nokogiri (1.11.2-x86_64-linux)
70+
racc (~> 1.4)
71+
protobuf-cucumber (3.10.8)
72+
activesupport (>= 3.2)
73+
middleware
74+
thor
75+
thread_safe
76+
public_suffix (4.0.6)
77+
racc (1.5.2)
78+
rack (2.2.3)
79+
rack-test (1.1.0)
80+
rack (>= 1.0, < 3)
81+
regexp_parser (2.1.1)
82+
rspec (3.10.0)
83+
rspec-core (~> 3.10.0)
84+
rspec-expectations (~> 3.10.0)
85+
rspec-mocks (~> 3.10.0)
86+
rspec-core (3.10.1)
87+
rspec-support (~> 3.10.0)
88+
rspec-expectations (3.10.1)
89+
diff-lcs (>= 1.2.0, < 2.0)
90+
rspec-support (~> 3.10.0)
91+
rspec-mocks (3.10.2)
92+
diff-lcs (>= 1.2.0, < 2.0)
93+
rspec-support (~> 3.10.0)
94+
rspec-support (3.10.2)
95+
rubyzip (2.3.0)
96+
selenium-webdriver (3.142.7)
97+
childprocess (>= 0.5, < 4.0)
98+
rubyzip (>= 1.2.2)
99+
sys-uname (1.2.2)
100+
ffi (~> 1.1)
101+
thor (1.1.0)
102+
thread_safe (0.3.6)
103+
typhoeus (1.4.0)
104+
ethon (>= 0.9.0)
105+
tzinfo (2.0.4)
106+
concurrent-ruby (~> 1.0)
107+
xpath (3.2.0)
108+
nokogiri (~> 1.8)
109+
zeitwerk (2.4.2)
110+
111+
PLATFORMS
112+
ruby
113+
x86_64-linux
114+
115+
DEPENDENCIES
116+
capybara (~> 3.35)
117+
cucumber (~> 5.3)
118+
mailslurp_client (~> 11.5)
119+
rspec (~> 3.10)
120+
selenium-webdriver (~> 3.142)
121+
typhoeus (~> 1.4)
122+
123+
BUNDLED WITH
124+
2.2.3
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-include ../.env
2+
3+
bundler:
4+
gem install bundler
5+
6+
vendor:
7+
bundle install --path ./vendor/bundle
8+
9+
test:
10+
API_KEY=$(API_KEY) bundle exec cucumber
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ruby Capybara Selenium Cucumber Test
2+
Example use of MailSlurp emails with Capybara and Cucumber.
3+
4+
## Install
5+
`gem install bundler`
6+
`bundler install`
7+
8+
## Run
9+
`API_KEY=your-mailslurp-key make test`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default: --publish-quiet
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@selenium
2+
Feature: User authentication with verification
3+
4+
Testing an application with real email addresses
5+
6+
Scenario: Sign up and confirm account
7+
Given a user has an email address and loads the app
8+
When user signs up with email address and password
9+
Then they receive a confirmation code and can confirm their account
10+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
require 'mailslurp_client'
2+
3+
# configure the mailslurp client with an API Key
4+
MailSlurpClient.configure do |config|
5+
api_key = ENV['API_KEY']
6+
if api_key == "" or api_key == nil then
7+
raise "No API_KEY environment variable set for MailSlurp API KEY"
8+
end
9+
config.api_key['x-api-key'] = api_key
10+
end
11+
12+
inbox = nil
13+
14+
Given /a user has an email address and loads the app/ do
15+
# create a test email account for the user
16+
inbox_controller = MailSlurpClient::InboxControllerApi.new
17+
inbox = inbox_controller.create_inbox
18+
19+
# load the playground application
20+
visit '/'
21+
expect(page).to have_title 'React App'
22+
end
23+
24+
When /user signs up with email address and password/ do
25+
# click the sign up link
26+
find('[data-test="sign-in-create-account-link"]').click
27+
28+
# fill out the form
29+
within('[data-test="sign-up-body-section"]') do
30+
fill_in 'email', with: inbox.email_address
31+
fill_in 'password', with: 'test-password'
32+
end
33+
34+
# click submit and wait for confirm page to load
35+
find('[data-test="sign-up-create-account-button"]').click
36+
find('[data-test="confirm-sign-up-body-section"]').visible?
37+
end
38+
39+
Then /they receive a confirmation code and can confirm their account/ do
40+
# wait for first unread email to arrive in user's inbox
41+
wait_controller = MailSlurpClient::WaitForControllerApi.new
42+
email = wait_controller.wait_for_latest_email({ inbox_id: inbox.id, unread_only: true, timeout: 30_000 })
43+
44+
# assert the email is a confirmation
45+
expect(email.subject).to include("Please confirm your email address")
46+
47+
# extract a 6 digit code from the email body
48+
match = email.body.match(/code is ([0-9]{6})/)
49+
if match == nil then
50+
raise "Could not find match in body #{email.body}"
51+
end
52+
code, * = match.captures
53+
54+
expect(code).to be_truthy
55+
56+
# submit confirmation code
57+
within('[data-test="confirm-sign-up-body-section"]') do
58+
fill_in 'code', with: code
59+
end
60+
find('[data-test="confirm-sign-up-confirm-button"]').click
61+
62+
# load the main page again
63+
visit '/'
64+
65+
# login and see a welcome
66+
fill_in 'username', with: inbox.email_address
67+
fill_in 'password', with: "test-password"
68+
find('[data-test="sign-in-sign-in-button"]').click
69+
70+
# wait for welcome to load
71+
expect(find('h1', wait: 30).text).to include("Welcome")
72+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'capybara'
2+
require 'capybara/dsl'
3+
require 'capybara/cucumber'
4+
require 'selenium-webdriver'
5+
6+
Capybara.configure do |config|
7+
config.default_driver = :selenium
8+
config.app_host = 'https://playground.mailslurp.com'
9+
end
10+
11+
World(Capybara)
12+

0 commit comments

Comments
 (0)