Permalink
Browse files

First commit - working :)

  • Loading branch information...
0 parents commit 8ff813863d2e0901353ea2133c069fd94a8569f5 @alisterscott committed Oct 29, 2011
@@ -0,0 +1,5 @@
+results.html
+.idea/*
+.bundle/*
+junit*
+chromedriver.log
2 .rvmrc
@@ -0,0 +1,2 @@
+rvm_install_on_use_flag=1
+rvm --create use ruby-1.9.2@watirmelon-cucumber
@@ -0,0 +1,10 @@
+rvm:
+ - 1.9.2
+notifications:
+ recipients:
+ - alister.scott@gmail.com
+before_script:
+ - ./travis.sh
+env:
+ - WEB_DRIVER=firefox
+ - WEB_DRIVER=chrome
@@ -0,0 +1,8 @@
+source "http://rubygems.org"
+gem "rake"
+gem "spinach", ">0"
+gem "rspec", ">0"
+gem "watir-webdriver", ">0"
+gem "watir-page-helper", ">0"
+gem "headless", ">0"
+gem "watir", :platforms => [:mswin, :mingw]
@@ -0,0 +1,47 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ childprocess (0.2.2)
+ ffi (~> 1.0.6)
+ colorize (0.5.8)
+ diff-lcs (1.1.3)
+ ffi (1.0.9)
+ gherkin (2.5.4)
+ json (>= 1.4.6)
+ headless (0.2.2)
+ json (1.6.1)
+ json_pure (1.6.1)
+ rake (0.9.2.2)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
+ rubyzip (0.9.4)
+ selenium-webdriver (2.10.0)
+ childprocess (>= 0.2.1)
+ ffi (= 1.0.9)
+ json_pure
+ rubyzip
+ spinach (0.1.5.3)
+ colorize
+ gherkin
+ watir-page-helper (0.4.0)
+ watir-webdriver (>= 0.2.0)
+ watir-webdriver (0.3.5)
+ selenium-webdriver (>= 0.2.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ headless (> 0)
+ rake
+ rspec (> 0)
+ spinach (> 0)
+ watir
+ watir-page-helper (> 0)
+ watir-webdriver (> 0)
@@ -0,0 +1,28 @@
+# Intro
+
+This is a simple, working Cucumber + Watir-WebDriver framework, where pages are defined and interacted with.
+
+Build Status: [![Build Status](https://secure.travis-ci.org/alisterscott/WatirMelonCucumber.png)](http://travis-ci.org/alisterscott/WatirMelonCucumber)
+
+# Requirements
+
+* RVM on Mac OSX / Linux
+* Pik/JRuby/Bundler/Wac on Windows
+
+# Installation and Usage
+
+1. Clone this repository from Github
+
+# Mac OSX / Linux
+
+1. ensure you have RVM (Ruby Version Manager) installed: http://rvm.beginrescueend.com/
+2. run ./go in the root directory: this will bootstrap everything needed and run the cucumber feature
+
+# Windows
+
+1. Install Ruby, Pik, Bundler and Wac (see my blog post: http://wp.me/p98zF-ca)
+2. Make sure you 'pik' Ruby
+3. In root directory, run 'bundle install'
+4. Then run 'rake'
+
+
@@ -0,0 +1,9 @@
+require 'cucumber'
+require 'cucumber/rake/task'
+
+Cucumber::Rake::Task.new(:cucumber) do |t|
+ t.profile = 'ci'
+end
+
+task :default => :cucumber
+
@@ -0,0 +1,2 @@
+default: -r features --tags ~@wip --color --format pretty --format html -o results.html
+ci: -r features HEADLESS=true TRAVIS=true --tags ~@wip --format progress --format html -o results.html --format junit -o junit
@@ -0,0 +1,29 @@
+Feature: Internet Search
+ As a casual internet user
+ I want to find some information about watir, and do a quick conversion
+ So that I can be knowledgeable being
+
+ Scenario: Search for Watir on Google
+ Given I am on the Google Home Page
+ When I search for "Watir"
+ Then I should see at least 100,000 results
+
+ Scenario: Search for Watir on Bing
+ Given I am on the Bing Home Page
+ When I search for "Watir"
+ Then I should see at least 30,000 results
+
+ Scenario: Do a unit conversion on Google
+ Given I am on the Google Home Page
+ When I convert 10 cm to inches
+ Then I should see the conversion result "10 centimeters = 3.93700787 inches"
+
+ Scenario: Do a search using data specified externally on Google
+ Given I am on the Google Home Page
+ When I search for a ridiculously small number of results
+ Then I should see at most 100 results
+
+ Scenario: Do a search using data specified externally on Google
+ Given I am on the Bing Home Page
+ When I search for a ridiculously small number of results
+ Then I should see at most 100 results
@@ -0,0 +1,57 @@
+class InternetSearch < Spinach::FeatureSteps
+ feature 'Internet Search'
+
+ Given 'I am on the Google Home Page' do
+ site 'Google'
+ visit :home
+ end
+
+ Given 'I am on the Bing Home Page' do
+ site 'Bing'
+ visit :home
+ end
+
+ When 'I search for "Watir"' do
+ on :home do |page|
+ page.search_for "Watir"
+ end
+ end
+
+ When 'I convert 10 cm to inches' do
+ on :home do |page|
+ page.search_for "convert 10cm to inches"
+ end
+ end
+
+ When 'I search for a ridiculously small number of results' do
+ term = Common.get_search_term_data "ridiculously small number of results"
+ on :home do |page|
+ page.search_for term
+ end
+ end
+
+ Then 'I should see at least 100,000 results' do
+ on :results do |page|
+ page.number_search_results.should >= 100000
+ end
+ end
+
+ Then 'I should see at least 30,000 results' do
+ on :results do |page|
+ page.number_search_results.should >= 30000
+ end
+ end
+
+ Then 'I should see at most 100 results' do
+ on :results do |page|
+ page.number_search_results.should <= 100
+ end
+ end
+
+ Then 'I should see the conversion result "10 centimeters = 3.93700787 inches"' do
+ on :results do |page|
+ page.conversion_result.gsub('metres', 'meters').should == "10 centimeters = 3.93700787 inches"
+ end
+ end
+
+end
@@ -0,0 +1,16 @@
+TEST_DATA_DIR = "./features/support/test_data"
+$: << File.dirname(__FILE__)+'/../../lib'
+
+WEB_DRIVER = ( ENV['WEB_DRIVER'] || :firefox ).to_sym
+require 'watir-webdriver'
+require 'watir-page-helper'
+require 'rspec'
+require 'pages.rb'
+require 'browser.rb'
+
+ENV['DISPLAY'] = ":99.0" if ENV['TRAVIS']
+
+include Browser
+
+Spinach.hooks.after_scenario { Browser::BROWSER.clear_cookies }
+Spinach.hooks.after_run { Browser::BROWSER.close }
@@ -0,0 +1,9 @@
+module Common
+ def Common.get_search_term_data term
+ YAML.load_file("#{TEST_DATA_DIR}/search_test_data.yml")["search terms"][term]["search term"]
+ end
+
+ def Common.get_search_term_exp_res term
+ YAML.load_file("#{TEST_DATA_DIR}/search_test_data.yml")["search terms"][term]["expected results"]
+ end
+end
@@ -0,0 +1,3 @@
+search terms:
+ ridiculously small number of results:
+ search term: 'macrocryoglobulinemia marvel'
9 go
@@ -0,0 +1,9 @@
+#! /usr/bin/env bash
+[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
+rvm rvmrc trust
+cd features
+cd .. # hack to load RVMRC
+set -e
+gem install bundler --no-rdoc --no-ri
+bundle install
+cucumber
@@ -0,0 +1,18 @@
+module Browser
+ BROWSER = (WEB_DRIVER == :watir) ? Watir::Browser.new : Watir::Browser.new(WEB_DRIVER)
+
+ def visit page_class, &block
+ on page_class, true, &block
+ end
+
+ def on page, visit=false, &block
+ page_class = Object.const_get "#{@site}#{page.to_s.capitalize}Page"
+ page = page_class.new BROWSER, visit
+ block.call page if block
+ page
+ end
+
+ def site name
+ @site = name
+ end
+end
@@ -0,0 +1,3 @@
+require 'pages/base_page_class.rb'
+require 'pages/search_page_class'
+Dir["#{File.dirname(__FILE__)}/pages/*_page.rb"].each {|r| load r }
@@ -0,0 +1,14 @@
+class BasePageClass
+ include WatirPageHelper
+
+ def initialize browser, visit = false
+ @browser = browser
+ goto if visit
+ expected_element if respond_to? :expected_element
+ has_expected_title? if respond_to? :has_expected_title?
+ end
+
+ def method_missing sym, *args, &block
+ @browser.send sym, *args, &block
+ end
+end
@@ -0,0 +1,16 @@
+class BingHomePage < SearchPageClass
+
+ direct_url "http://www.bing.com/"
+ expected_title "Bing"
+
+ button :bing_search, :name => 'go'
+ link :switch_to_english, :text => 'English'
+
+ def search_for term
+ switch_to_english if switch_to_english_link.exists?
+
+ self.search_text_field.when_present.set term
+ self.search_text_field.respond_to?(:send_keys) ? self.search_text_field.send_keys(:enter) : @browser.send_keys('{ENTER}')
+ end
+
+end
@@ -0,0 +1,15 @@
+class BingResultsPage < BasePageClass
+
+ expected_title /.+ Bing/
+ expected_element :span, :id => "count"
+
+ span :results, :id => "count"
+ span :conversion_result, :class => "sc_bigline"
+
+ def number_search_results
+ result = /^[\s\w-]* of ([\d,\.]+) results$/.match(results)
+ raise "Could not determine number of search results from: '#{results}'" if not result
+ result.captures[0].gsub(",","").gsub(".", "").to_i
+ end
+
+end
@@ -0,0 +1,15 @@
+class GoogleHomePage < SearchPageClass
+
+ direct_url "http://www.google.com"
+ expected_title "Google"
+ link :go_to_google_usa, :text => 'Go to Google.com'
+ link :go_to_google_in_english, :text => 'Google.com in English'
+
+ def search_for term
+ go_to_google_usa if go_to_google_usa_link.exists?
+ go_to_google_in_english if go_to_google_in_english_link.exists?
+
+ self.search = term
+ self.search_text_field.respond_to?(:send_keys) ? self.search_text_field.send_keys(:enter) : @browser.send_keys('{ENTER}')
+ end
+end
@@ -0,0 +1,15 @@
+class GoogleResultsPage < BasePageClass
+
+ expected_title /Google.*/
+ expected_element :div, :id => "resultStats"
+
+ div :results, :id => "resultStats"
+ h2 :conversion_result, :class => "r"
+
+ def number_search_results
+ result = /[\s\D]*([\d,]+) results \(\d+\.\d+ seconds\)/.match(results)
+ raise "Could not determine number of search results from: '#{results}'" if not result
+ result.captures[0].gsub(",","").to_i
+ end
+
+end
@@ -0,0 +1,5 @@
+class SearchPageClass < BasePageClass
+
+ text_field :search, :name => "q"
+
+end
@@ -0,0 +1,12 @@
+#/bin/sh
+
+if [[ "$WEB_DRIVER" = "chrome" ]]; then
+ curl -L https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
+ sudo -s 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list'
+ sudo apt-get update
+ sudo apt-get -y install google-chrome-unstable unzip
+ # curl -k http://chromium.googlecode.com/files/chromedriver_linux32_14.0.836.0.zip | sudo -s 'funzip > /usr/bin/chromedriver'
+ sudo -s 'curl -L http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux/102682/chrome-linux.test/chromedriver > /usr/bin/chromedriver'
+ sudo chmod +x /usr/bin/chromedriver
+fi
+sh -e /etc/init.d/xvfb start

0 comments on commit 8ff8138

Please sign in to comment.