Browse Source

Moved back to selenium-webdriver for browser testing.

Martin Edenhofer 12 years ago
parent
commit
e35ac9b468

+ 1 - 2
Gemfile

@@ -72,7 +72,6 @@ group :development, :test do
     gem 'simplecov-rcov'
 
     # UI tests w/ Selenium
-    #gem 'selenium-webdriver'
-    gem 'watir-webdriver'
+    gem 'selenium-webdriver'
 
 end

+ 5 - 5
test/browser/aaa_getting_started.rb → test/browser/aaa_getting_started_test.rb

@@ -1,17 +1,17 @@
 # encoding: utf-8
 require 'browser_test_helper'
 
-class AaaGettingStarted < ActiveSupport::TestCase
-  test 'getting started' do
+class AaaGettingStartedTest < TestCase
+  def test_getting_started
     tests = [
       {
         :name     => 'start',
-        :instance => Watir::Browser.new,
-        :url      => 'http://localhost:3000/#getting_started',
+        :instance => browser_instance,
+        :url      => browser_url + '/#getting_started',
         :action   => [
           {
             :execute => 'wait',
-            :value   => 6,
+            :value   => 1,
           },
           {
             :execute => 'check',

+ 4 - 4
test/browser/auth_customer.rb → test/browser/auth_customer_test.rb

@@ -1,13 +1,13 @@
 # encoding: utf-8
 require 'browser_test_helper'
  
-class Auth < ActiveSupport::TestCase
-  test 'authentication' do
+class AuthTest < TestCase
+  def test_authentication
     tests = [
       {
         :name     => 'start',
-        :instance => Watir::Browser.new,
-        :url      => 'http://localhost:3000',
+        :instance => browser_instance,
+        :url      => browser_url,
         :action   => [
           {
             :execute => 'check',

+ 4 - 4
test/browser/auth_master.rb → test/browser/auth_master_test.rb

@@ -1,13 +1,13 @@
 # encoding: utf-8
 require 'browser_test_helper'
  
-class AuthMaster < ActiveSupport::TestCase
-  test 'authentication' do
+class AuthMasterTest < TestCase
+  def test_authentication
     tests = [
       {
         :name     => 'start',
-        :instance => Watir::Browser.new,
-        :url      => 'http://localhost:3000',
+        :instance => browser_instance,
+        :url      => browser_url,
         :action   => [
           {
             :execute => 'check',

+ 28 - 11
test/browser/chat.rb → test/browser/chat_test.rb

@@ -1,19 +1,19 @@
 # encoding: utf-8
 require 'browser_test_helper'
  
-class Chat < ActiveSupport::TestCase
-  test 'websocket' do
+class ChatTest < TestCase
+  def test_websocket
     message = 'message 1äöüß ' + rand(99999999999999999).to_s
     tests = [
       {
         :name     => 'start',
-        :instance1 => Watir::Browser.new,
-        :instance2 => Watir::Browser.new,
+        :instance1 => browser_instance,
+        :instance2 => browser_instance,
         :instance1_username => 'master@example.com',
         :instance1_password => 'test',
         :instance2_username => 'master@example.com',
         :instance2_password => 'test',        
-        :url      => 'http://localhost:3000',
+        :url      => browser_url,
         :action   => [
           {
             :where   => :instance1,
@@ -27,7 +27,24 @@ class Chat < ActiveSupport::TestCase
             :css     => '#login',
             :result  => false,
           },
-          
+          {
+            :where   => :instance1,
+            :execute => 'click',
+            :css     => '#chat_toogle',
+          },
+          {
+            :execute => 'wait',
+            :value   => 4,
+          },
+          {
+            :where   => :instance1,
+            :execute => 'click',
+            :css     => '#chat_toogle',
+          },
+          {
+            :execute => 'wait',
+            :value   => 1,
+          },
           {
             :where   => :instance1,
             :execute => 'click',
@@ -47,7 +64,7 @@ class Chat < ActiveSupport::TestCase
           },
           {
             :execute => 'wait',
-            :value   => 3,
+            :value   => 6,
           },
           {
             :where        => :instance1,
@@ -63,10 +80,10 @@ class Chat < ActiveSupport::TestCase
             :value        => message,
             :match_result => true,
           },
-          {
-            :execute => 'wait',
-            :value   => 10,
-          },
+#          {
+#            :execute => 'wait',
+#            :value   => 1,
+#          },
         ],
       },
     ]

+ 2 - 2
test/browser/customer_ticket_create.rb → test/browser/customer_ticket_create_test.rb

@@ -1,8 +1,8 @@
 # encoding: utf-8
 require 'browser_test_helper'
 
-class CustomerTicketCreate < ActiveSupport::TestCase
-  test 'customer ticket create' do
+class CustomerTicketCreateTest < TestCase
+  def test_customer_ticket_create
     tests = [
       {
         :name     => 'customer ticket create',

+ 2 - 2
test/browser/prefereces.rb → test/browser/prefereces_test.rb

@@ -1,8 +1,8 @@
 # encoding: utf-8
 require 'browser_test_helper'
 
-class Preferences < ActiveSupport::TestCase
-  test 'preferences' do
+class PreferencesTest < TestCase
+  def test_preferences
     tests = [
       {
         :name     => 'preferences',

+ 2 - 2
test/browser/setting.rb → test/browser/setting_test.rb

@@ -1,8 +1,8 @@
 # encoding: utf-8
 require 'browser_test_helper'
 
-class TestSetting < ActiveSupport::TestCase
-  test 'setting' do
+class SettingTest < TestCase
+  def test_setting
     tests = [
       {
         :name     => 'setting',

+ 5 - 9
test/browser/signup.rb → test/browser/signup_test.rb

@@ -1,23 +1,19 @@
 # encoding: utf-8
 require 'browser_test_helper'
  
-class Signup < ActiveSupport::TestCase
-  test 'signup' do
+class SignupTest < TestCase
+  def test_signup
     signup_user_email = 'signup-test-' + rand(999999).to_s + '@example.com'
     tests = [
       {
         :name     => 'start',
-        :instance => Watir::Browser.new,
-        :url      => 'http://localhost:3000',
+        :instance => browser_instance,
+        :url      => browser_url,
         :action   => [
           {
             :execute => 'click',
             :css     => 'a[href="#signup"]',
           },
-          {
-            :execute => 'wait',
-            :value   => 1,
-          },
           {
             :execute => 'check',
             :css     => '#form-signup',
@@ -59,7 +55,7 @@ class Signup < ActiveSupport::TestCase
           },
           {
             :execute => 'wait',
-            :value   => 3,
+            :value   => 2,
           },
 
           # check action

+ 62 - 16
test/browser_test_helper.rb

@@ -1,17 +1,50 @@
 ENV["RAILS_ENV"] = "test"
 require File.expand_path('../../config/environment', __FILE__)
 require 'rails/test_help'
-require 'watir-webdriver'
+#require 'watir-webdriver'
+require 'selenium-webdriver'
 
-class ActiveSupport::TestCase
+class TestCase < Test::Unit::TestCase
+  def browser_url
+    ENV['BROWSER_URL'] || 'http://localhost:3000'
+  end
+
+  def browser_instance
+    if !@browsers
+      @browsers = []
+    end
+    if !ENV['REMOTE_URL']
+      browser = Selenium::WebDriver.for :firefox 
+      @browsers.push browser
+      return browser
+    end
+#    return Watir::Browser.new if !ENV['REMOTE_URL']
+
+    caps = Selenium::WebDriver::Remote::Capabilities.send( ENV['BROWSER'] )
+    caps.platform = ENV['BROWSER_OS'] || 'Windows 2008'
+    caps.version  = ENV['BROWSER_VERSION'] || '8'
+    Selenium::WebDriver.for(
+      :remote,
+      :url                  => ENV['REMOTE_URL'],
+      :desired_capabilities => caps,
+    )
+
+  end
+
+  def teardown
+    return if !@browsers
+    @browsers.each{ |browser|
+      browser.close
+    }
+  end
 
   # Add more helper methods to be used by all tests here...
   def browser_login(data)
     all_tests = [
       {
         :name     => 'login',
-        :instance => data[:instance] || Watir::Browser.new,
-        :url      => data[:url] || 'http://localhost:3000',
+        :instance => data[:instance] || browser_instance,
+        :url      => data[:url] || browser_url,
         :action   => [
           {
             :execute => 'wait',
@@ -99,7 +132,7 @@ class ActiveSupport::TestCase
         instance = test[:instance]
       end
       if test[:url]
-        instance.goto( test[:url] )
+        instance.get( test[:url] )
       end
       if test[:action]
         test[:action].each { |action|
@@ -119,32 +152,45 @@ class ActiveSupport::TestCase
   
   def browser_element_action(test, action, instance)
     if action[:css]
-      element = instance.element( { :css => action[:css] } )
+      begin
+        element = instance.find_element( { :css => action[:css] } )
+      rescue
+        element = nil
+      end
       if action[:result] == false
-        assert( !element.exists?, "(#{test[:name]}) Element with css '#{action[:css]}' exists" )
+        assert( !element, "(#{test[:name]}) Element with css '#{action[:css]}' exists" )
       else
-        assert( element.exists?, "(#{test[:name]}) Element with css '#{action[:css]}' doesn't exist" )
+        assert( element, "(#{test[:name]}) Element with css '#{action[:css]}' doesn't exist" )
       end
     elsif action[:element] == :url
-        if instance.url =~ /#{Regexp.quote(action[:result])}/
-          assert( true, "(#{test[:name]}) url #{instance.url} is matching #{action[:result]}" )
+        if instance.current_url =~ /#{Regexp.quote(action[:result])}/
+          assert( true, "(#{test[:name]}) url #{instance.current_url} is matching #{action[:result]}" )
         else
-          assert( false, "(#{test[:name]}) url #{instance.url} is not matching #{action[:result]}" )
+          assert( false, "(#{test[:name]}) url #{instance.current_url} is not matching #{action[:result]}" )
         end
     else
       assert( false, "(#{test[:name]}) unknow selector for '#{action[:element]}'" )
     end
     if action[:execute] == 'set'
-      element.to_subtype.set( action[:value] )
+      element.send_keys( action[:value] )
     elsif action[:execute] == 'select'
-      element.to_subtype.select( action[:value] )
+      dropdown = Selenium::WebDriver::Support::Select.new(element)
+      dropdown.select_by(:text, action[:value])
     elsif action[:execute] == 'click'
       element.click
     elsif action[:execute] == 'send_key'
       element.send_keys action[:value]
     elsif action[:execute] == 'match'
       if action[:css] =~ /select/
-        success = element.to_subtype.selected?(action[:value])
+        dropdown = Selenium::WebDriver::Support::Select.new(element)
+        success  = false
+        if dropdown.selected_options
+          dropdown.selected_options.each {|option|
+            if option.text == action[:value]
+              success = true
+            end
+          }
+        end
         if action[:match_result]
           if success
             assert( true, "(#{test[:name]}) matching '#{action[:value]}' in select list" )
@@ -159,8 +205,8 @@ class ActiveSupport::TestCase
           end
         end
       else
-        if action[:css] =~ /input|textarea/i
-          text = element.to_subtype.value
+        if action[:css] =~ /input/i
+          text = element.attribute('value')
         else
           text = element.text
         end

Some files were not shown because too many files changed in this diff