From 3d0f76cea0df4aa878a5ce77df5528d572b12132 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 26 Feb 2015 13:41:09 +0100 Subject: [PATCH] Improved error handling of content editable fields. --- .../agent_organization_profile_test.rb | 20 +++++++++------ test/browser/agent_user_profile_test.rb | 18 +++++++------ test/browser_test_helper.rb | 25 +++++++++++++++---- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/test/browser/agent_organization_profile_test.rb b/test/browser/agent_organization_profile_test.rb index 8dd231a91..a45796b19 100644 --- a/test/browser/agent_organization_profile_test.rb +++ b/test/browser/agent_organization_profile_test.rb @@ -5,6 +5,7 @@ class AgentOrganizationProfileTest < TestCase def test_org_profile # work in one browser window message = '1 ' + rand(99999999).to_s + note = 'some note ' + rand(99999999).to_s @browser = browser_instance login( @@ -29,10 +30,12 @@ class AgentOrganizationProfileTest < TestCase # update note set( - :css => '.active [data-name="note"]', - :value => 'some note 123' + :css => '.active .profile [data-name="note"]', + :value => note, + :contenteditable => true, ) - click( :css => '.active .profile' ) + click( :css => '#global-search' ) + sleep 2 # check and change note again in edit screen click( :css => '.active .js-action .select-arrow' ) @@ -44,7 +47,7 @@ class AgentOrganizationProfileTest < TestCase ) watch_for( :css => '.active .modal', - :value => 'some note 123', + :value => note, ) set( @@ -108,13 +111,14 @@ class AgentOrganizationProfileTest < TestCase # update note set( - :browser => browser1, - :css => '.active [data-name="note"]', - :value => message, + :browser => browser1, + :css => '.active .profile [data-name="note"]', + :value => message, + :contenteditable => true, ) click( :browser => browser1, - :css => '.active .profile', + :css => '#global-search', ) # verify diff --git a/test/browser/agent_user_profile_test.rb b/test/browser/agent_user_profile_test.rb index ae517ff25..b0469ab9e 100644 --- a/test/browser/agent_user_profile_test.rb +++ b/test/browser/agent_user_profile_test.rb @@ -27,11 +27,12 @@ class AgentUserProfileTest < TestCase # update note set( - :css => '.active [data-name="note"]', - :value => 'some note 123', - ) + :css => '.active [data-name="note"]', + :value => 'some note 123', + :contenteditable => true, - click( :css => '.active .profile' ) + ) + click( :css => '#global-search' ) sleep 2 # check and change note again in edit screen @@ -106,13 +107,14 @@ class AgentUserProfileTest < TestCase # update note set( - :browser => browser1, - :css => '.active [data-name="note"]', - :value => message, + :browser => browser1, + :css => '.active [data-name="note"]', + :value => message, + :contenteditable => true, ) click( :browser => browser1, - :css => '.active .profile', + :css => '#global-search', ) watch_for( diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index feb4e5bf0..1642bf408 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -235,11 +235,13 @@ class TestCase < Test::Unit::TestCase =begin set( - :browser => browser1, - :css => '.some_class', - :value => true, - :slow => false, - :clear => true, # todo + :browser => browser1, + :css => '.some_class', + :value => true, + :slow => false, + :blur => true, + :clear => true, # todo | default: true + :contenteditable => true ) =end @@ -247,7 +249,16 @@ class TestCase < Test::Unit::TestCase def set(params) instance = params[:browser] || @browser + # it's not working stable via selenium, use js + if params[:contenteditable] + #puts "---$('#{params[:css]}').html('#{params[:value]}')--" + instance.execute_script( "$('#{params[:css]}').focus().html('#{params[:value]}').trigger('change').blur()" ) + sleep 1 + return + end + element = instance.find_elements( { :css => params[:css] } )[0] + #element.click element.clear if !params[:slow] @@ -259,6 +270,10 @@ class TestCase < Test::Unit::TestCase instance.action.send_keys(key).perform } end + + if params[:blur] + instance.execute_script( "$('#{params[:css]}').blur()" ) + end sleep 0.5 end