Site Prism's element
method, adapted to support iOS and Android in a one-line declaration
Here's an earlier implementation with Super Mario:
class GameScreen < ScreenModels::Screen
element :mario, 'mario_small'
element :score, 'score'
end
Step definitions:
Given("the score begins at {string}") do |string|
GameScreen.score.text.should eq "0"
end
When("I click Mario") do
GameScreen.mario.click
end
Then("the score increases to {string} within {string} seconds") do |expected_score, seconds|
sleep seconds.to_i + 0.5
GameScreen.score.text.should eq expected_score
end
More recently, I'm using the Kickstarter mobile app, which Kickstarter has been gracious enough to open source. :) Yay ! Thank you Kickstarter !
class AlphaScreen < ScreenModels::Screen
element :magic, 'a:MAGIC', 'i:Magic'
element :popular, 'a:POPULAR', 'i:Popular'
element :newest, 'a:NEWEST', 'i:Newest'
element :ending_soon, 'a:NEWEST', 'i:Ending Soon'
element :sign_up_or_log_in, 'i:Sign up or Log in'
end
class NavBar < ScreenModels::Screen
element :explore, 'i:Explore'
element :activity, 'i:Activity'
element :search, 'i:Search'
element :profile, 'i:Profile'
end
Test executions:
Feature: Signup tests
Scenario: Create a new user account
Given I launch the app
When I select Sign up or Log in
And I select Sign up on the Sign up or Log in screen
And I enter name "Mobile Prism" with a unique timestamp
And I enter email "[email protected]" plus the unique timestamp
And I enter password "mobileprism"
And I click go
Then I see the message "Welcome!"
When("I select Sign up or Log in") do
AlphaScreen.sign_up_or_log_in.click
end
And("I select Sign up on the Sign up or Log in screen") do
SignupOrLogin.sign_up.click
end
When("I enter name {string} with a unique timestamp") do |string|
@timestamp = Time.now.to_i
Signup.name.click
Signup.name.set "#{string}-#{@timestamp}"
end
When("I enter password {string}") do |string|
Signup.password.click
Signup.password.set string
end
When("I click go") do
Numpad.go.click
end