Replies: 1 comment
-
Please next time when opening an issue consider opening a discussion, because issue doesn't assume a question. This is a working one file example, that can be run as require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "puma"
gem "rspec"
gem "capybara"
gem "cuprite"
gem "ferrum"
gem "sinatra"
end
require "rspec/autorun"
require "capybara/rspec"
require "capybara/cuprite"
require "sinatra/base"
class MyApp < Sinatra::Base
get "/" do
DATA
end
end
Capybara.app = MyApp
Capybara.default_driver = :cuprite
Capybara.register_driver :cuprite do |app|
Capybara::Cuprite::Driver.new(app)
end
describe "flaky spec", type: :feature do
let(:email) { "email@example.com" }
let(:first_name) { "Firstname" }
let(:last_name) { "Lastname" }
it "submits form successfully" do
visit "/"
fill_in "email", with: email
click_button("Next")
sleep 1
fill_in "first-name", with: first_name
fill_in "last-name", with: last_name
click_button("Finish")
expect(page).to have_text("Successfully sent")
end
end
__END__
<!doctype html>
<html>
<head>
<style>
body form * { display: block; margin: 10px 0; }
#hint, .step { display: none; }
.active { display: block; }
</style>
</head>
<body>
<form>
<div class="step active">
<input id="email" />
<div id="hint">Please add here your email</div>
<button class="btn">Next</button>
</div>
<div class="step">
<input id="first-name" type="text">
<input id="last-name" type="text">
<button class="btn">Finish</button>
</div>
<div class="step">
<p>Successfully sent</p>
</div>
</form>
<script type="text/javascript">
setTimeout(() => {
document.getElementById("hint").style.display = "block";
}, 55)
document.addEventListener("click", (event) => {
event.preventDefault();
parent = event.target.parentElement;
parent.classList.remove("active");
parent.nextElementSibling.classList.add("active");
});
</script>
</body>
</html> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm not a web developer so I never used Capybara integrated with the Ruby web app -- I always ran the tests as a separetly hosted application. However I'm currently making a Sinatra app and I suppose integrating it with the minitest would allow me to start and stop the app automatically that would be nice. But I can't figure out how to do that. I tried to follow https://sinatrarb.com/testing.html
but when the browser window opens the localhost is down, it does not look like Sinatra was started. What do I miss here?
UPD: moving the
require helper
after the.app =
is probably more correct but still no effect.Beta Was this translation helpful? Give feedback.
All reactions