-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Cruikshanks/feature/javascript-error-example
Add example of testing for and handling js errors
- Loading branch information
Showing
10 changed files
with
104 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- Main jumbotron for a primary marketing message or call to action --> | ||
<div class="jumbotron"> | ||
<h1><%= @title %></h1> | ||
<p class="lead">This page can be used for checking what happens when you test a page with a JavaScript error.</p> | ||
<p class="lead">There are examples of how to test against the data in this page, but essentially they are just | ||
using <strong>Capybara's</strong> <code>find()</code> method.</p> | ||
<ul> | ||
<li><code>features/quke/javascript_error.feature</code></li> | ||
<li><code>features/step_definitions/quke/javascript_error_steps.rb</code></li> | ||
<li><code>quke_demo_app/views/javascript_error.erb</code></li> | ||
</ul> | ||
</div> | ||
<script> | ||
throw ({'error':'boom'}); | ||
</script> | ||
<div id="result"> | ||
<h2>Results</h2> | ||
<p><%= @results %></p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Feature: JavaScript error | ||
To demonstrate how you can use Quke | ||
As a user of Quke | ||
I want to see how JavaScript errors are handled | ||
And how I can choose to ignore them | ||
|
||
Scenario: Testing driver response to a JavaScript error (page objects) | ||
Given I am on the home page | ||
When I go to the JavaScript error page | ||
Then It should show we have an error | ||
|
||
Scenario: Testing driver response to a JavaScript error (capybara) | ||
Given I'm at the home page | ||
When I navigate to the JavaScript error page | ||
Then I should see we have an error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# Home page | ||
class HomePage < SitePrism::Page | ||
set_url '/' | ||
|
||
element :title, 'h1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# JavaScript error page | ||
class JavascriptErrorPage < SitePrism::Page | ||
set_url '/jserror' | ||
|
||
element :title, 'h1' | ||
|
||
elements :results, "div[class='result']" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# The following steps use the page objects to drive the browser | ||
Given(/^I am on the home page$/) do | ||
@app = App.new | ||
@app.home_page.load | ||
expect(@app.home_page.title.text).to eq('Welcome to Quke') | ||
end | ||
|
||
When(/^I go to the JavaScript error page$/) do | ||
expect { @app.javascript_error_page.load }.to raise_error(Capybara::Poltergeist::JavascriptError) | ||
end | ||
|
||
Then(/^It should show we have an error$/) do | ||
# We have to capture the error in the previous step else the exception will | ||
# block us from continuing. However the scenario reads better if we can break | ||
# it down. | ||
true | ||
end | ||
|
||
# The following steps use capybara directly to drive the browser | ||
Given(/^I'm at the home page$/) do | ||
visit '/' | ||
expect(page).to have_content('Welcome to Quke') | ||
end | ||
|
||
When(/^I navigate to the JavaScript error page$/) do | ||
expect { visit('/jserror') }.to raise_error(Capybara::Poltergeist::JavascriptError) | ||
end | ||
|
||
Then(/^I should see we have an error$/) do | ||
# We have to capture the error in the previous step else the exception will | ||
# block us from continuing. However the scenario reads better if we can break | ||
# it down. | ||
true | ||
end |