The document discusses several frequently encountered issues when testing cross-browser, including time dependence, managing test virtual machines, random DOM IDs, testing layout, unit testing JavaScript, model layer access in tests, starting state, and parallel test runs. Some solutions proposed include using fixtures to manage database state, cleaning up the database between tests, and starting multiple browser instances in parallel to speed up test runs.
59. require 'selenium-webdriver'
describe 'Google' do
before(:each){ @browser = Selenium::WebDriver.for :firefox }
after(:each) { @browser.quit }
it 'should return search results for "hello world"' do
@browser.navigate.to "http://www.google.co.uk"
@browser.find_element(:name, "q").send_keys("hello world")
@browser.find_element(:name, "btnG").submit
@browser.find_element(:partial_link_text,
"Hello world program - Wikipedia")
end
end
64. Cucumber
Capybara
Culerity
Selenium
2
*Wa(r
WebDriver Celerity
HTML
Unit
65.
66. Feature: Looking up a contact
In order to understand my contacts better
As a Gmail user
I want to see social information next to my email thread
Scenario: Load an email conversation
Given I am logged into Gmail
And Rapportive is loaded
When I search for "martin@rapportive.com"
And I click on the conversation with subject "Testing 1 2 3"
Then I should be on a conversation view
And Rapportive should show "Co-founder at Rapportive"
67. Given /^I am logged into Gmail$/ do
visit 'https://mail.google.com/a/rapportive.com'
fill_in 'Email', :with => 'test'
fill_in 'Passwd', :with => GMAIL_TEST_ACCOUNT_PASSWORD
click 'Sign in'
end
Then /^Rapportive should show "([^"]*)"$/ do |text_to_show|
page.within_frame('canvas_frame') do
page.within(:css, '#rapportive-sidebar') do
page.should have_content(text_to_show)
end
end
end
79. 7.
Random
DOM
IDs
‣ Ext.js,
GWT,
Cappuccino
‣ Use
toolkit
APIs
// Selecting an item in a Ext.js Combo Box
var combo = Ext.getCmp('countryComboBox');
combo.setValue('Germany');
// setValue() doesn't trigger the event
combo.fireEvent('select');
96. 4.
Model
layer
access
‣ Violates
abstrac(on
‣ BUT:
factories
=
only
sane
way
of
managing
DB
state
97. Factory.define :user do |u|
u.first_name 'John'
u.last_name 'Doe'
u.admin false
end
Given /^I am on John's profile page$/ do
user = Factory.create(:user)
visit user_url(user)
end
102. 2.
Parallel
test
runs
‣ End-‐to-‐end
tests
are
SLOW
‣ Start
up
several
browsers
(TestSwarm,
Selenium
Grid,
...)
‣ BUT:
concurrent
modifica(on
of
DB
state!
103. 2.
Parallel
test
runs
One
DB
per
test
process
‣ h"p://github.com/grosser/parallel_tests
‣ h"p://github.com/qxjit/deep-‐test
104. 2.
Parallel
test
runs
Caveat:
state
outside
of
your
control
‣ e.g.
OAuth
status
‣ use
mocks,
or
work
around
it
108. 2
schools
of
thought
1. “Disposable”
test
scripts
(invest
licle
effort,
use
recording
tools)
2. “Engineered”
test
scripts
(use
carefully
designed
abstrac(ons)
109. Feature: Looking up a contact
In order to understand my contacts better
As a Gmail user
I want to see social information next to my email thread
Scenario: Load an email conversation
Given I am logged into Gmail
And Rapportive is loaded
When I search for "martin@rapportive.com"
And I click on the conversation with subject "Testing 1 2 3"
Then I should be on a conversation view
And Rapportive should show "Co-founder at Rapportive"
110. Fragility
No
silver
bullet,
obvious
stuff:
‣ Consistent
naming
of
IDs
&
CSS
classes
‣ Maintain
&
refactor
your
tests