Skip to content

Commit

Permalink
better support for data inside yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Powell committed Feb 7, 2012
1 parent 25a454c commit 6441f12
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 14 deletions.
35 changes: 31 additions & 4 deletions lib/GeneralSeleniumUtility.rb
Expand Up @@ -99,7 +99,15 @@ def load_yaml_data( file )
# Finds the given element, checks its name, and types data into
# the element
#****************
def check_element_send_keys(how, what, tag_name, to_type)
def check_element_send_keys(yaml_data_key)
check_element_send_keys_raw(
$yaml_data[yaml_data_key][0].to_sym,
$yaml_data[yaml_data_key][1],
$yaml_data[yaml_data_key][2],
$yaml_data[yaml_data_key][3]
)
end
def check_element_send_keys_raw(how, what, tag_name, to_type)
e = @driver.find_element(how, what)
e.tag_name.should == tag_name
3.times do |x|
Expand All @@ -120,7 +128,16 @@ def check_element_send_keys(how, what, tag_name, to_type)
# the URL we end up at after the click is what we expect and,
# optionally, eat an alert that comes up.
#****************
def check_element_click(how, what, tag_name, resulting_url, alert_text = nil)
def check_element_click(yaml_data_key)
check_element_click_raw(
$yaml_data[yaml_data_key][0].to_sym,
$yaml_data[yaml_data_key][1],
$yaml_data[yaml_data_key][2],
$yaml_data[yaml_data_key][3],
$yaml_data[yaml_data_key][4]
)
end
def check_element_click_raw(how, what, tag_name, resulting_url, alert_text = nil)
has_dealt_with_alert = false

e = @driver.find_element(how, what)
Expand Down Expand Up @@ -163,7 +180,14 @@ def check_element_click(how, what, tag_name, resulting_url, alert_text = nil)
# transition for these clicks, i.e. fast javascript response is
# expected.
#****************
def no_move_click(how, what, tag_name)
def no_move_click(yaml_data_key)
no_move_click_raw(
$yaml_data[yaml_data_key][0].to_sym,
$yaml_data[yaml_data_key][1],
$yaml_data[yaml_data_key][2]
)
end
def no_move_click_raw(how, what, tag_name)
e = @driver.find_element(how, what)
@debug and print "In no_move_click, e: #{e}\n"
e.tag_name.should == tag_name
Expand Down Expand Up @@ -375,7 +399,10 @@ def quiesce()
# Gives an element a while (about 5 seconds) to show up on the
# page, errors if it doesn't.
#****************
def wait_for_element(how, what)
def wait_for_element(yaml_data_key)
wait_for_element_raw($yaml_data[yaml_data_key][0], $yaml_data[yaml_data_key][1])
end
def wait_for_element_raw(how, what)
e = nil
5.times do |x|
# note that find-element auto-waits
Expand Down
2 changes: 1 addition & 1 deletion lib/GoogleUtility.rb
@@ -1,7 +1,7 @@
module GoogleUtility
def click_logo
quiesce
no_move_click(:id, 'hplogo', 'img')
no_move_click_raw(:id, 'hplogo', 'img')
quiesce
end
end
4 changes: 2 additions & 2 deletions tests/BasicSearch.rb
Expand Up @@ -8,7 +8,7 @@

it 'should take the text input' do
@debug and dump_page_source("/tmp/goog1")
check_element_send_keys(:id, 'lst-ib', 'input', 'monkeys')
check_element_send_keys('basic_search_search_monkeys')
@debug and dump_page_source("/tmp/goog2")
end

Expand All @@ -18,7 +18,7 @@

it 'should click on search and load the new page' do
@debug and dump_page_source("/tmp/goog3")
check_element_click(:name, "btnK", "input", "^#{@server_url}/.*q=monkeys.*$" )
check_element_click('basic_search_click_search')
quiesce
@debug and dump_page_source("/tmp/goog4")
end
Expand Down
4 changes: 2 additions & 2 deletions tests/Lucky.rb
Expand Up @@ -7,15 +7,15 @@
end

it 'should take the text input' do
check_element_send_keys(:id, 'lst-ib', 'input', 'monkeys')
check_element_send_keys('lucky_search_monkeys')
end

it 'should click elsewhere to close the javascripty bits' do
click_logo
end

it %q{should click on "I'm Feeling Lucky" and load the new page} do
check_element_click(:name, "btnI", "input", "^http://en.wikipedia.org/wiki/Monkey$" )
check_element_click('lucky_click_lucky')
quiesce
end
end
Expand Down
6 changes: 3 additions & 3 deletions tests/Setup.rb
Expand Up @@ -17,14 +17,14 @@
# there right now 0.o (31 Jan 2012), so we test for which to
# do
begin
no_move_click(:id, 'psyDrag', 'div')
no_move_click('setup_instant_predictions_div1')
rescue
no_move_click(:id, ':2.label', 'div')
no_move_click('setup_instant_predictions_div2')
end
end

it "should save the new setting" do
check_element_click(:xpath, "//div[text()='Save']", "div", "^#{@server_url}/$" )
check_element_click('setup_click_save')
end
end
end
4 changes: 2 additions & 2 deletions tests/Translate.rb
Expand Up @@ -7,11 +7,11 @@
end

it 'should click on the More link' do
no_move_click(:id, 'gbztms1', 'span')
no_move_click('translate_more_link')
end

it 'should click on the translate link and load the new page' do
check_element_click(:id, "gb_51", "a", "^http://translate.google.com/.hl=en.tab=wT$" )
check_element_click('translate_click_translate')
quiesce
end
end
Expand Down
11 changes: 11 additions & 0 deletions yaml/BasicSearch_000_basic.yaml
@@ -1,9 +1,20 @@
---
conditions:
-
- experiment
- basic

basic_search_click_search:
- name
- "btnK"
- "input"
- "^http://www.google.com/.*q=monkeys.*$"

basic_search_search_monkeys:
- id
- 'lst-ib'
- 'input'
- 'monkeys'

#################################################################################
# BEGIN AUTOGENERATED BY bin/yaml_generate.rb with arguments:
Expand Down
17 changes: 17 additions & 0 deletions yaml/Lucky_000_basic.yaml
@@ -0,0 +1,17 @@
---
conditions:
-
- experiment
- basic

lucky_click_lucky:
- name
- btnI
- "input"
- "^http://en.wikipedia.org/wiki/Monkey$"

lucky_search_monkeys:
- :id
- 'lst-ib'
- 'input'
- 'monkeys'
16 changes: 16 additions & 0 deletions yaml/Setup_000_basic.yaml
@@ -0,0 +1,16 @@
---
conditions:
-
- experiment
- basic

setup_instant_predictions_div1: - id
- psyDrag
- div
setup_instant_predictions_div2: - id
- ':2.label'
- div
setup_click_save: - xpath
- "//div[text()='Save']"
- "div"
- "^http://www.google.com/$"
15 changes: 15 additions & 0 deletions yaml/Translate_000_basic.yaml
@@ -0,0 +1,15 @@
---
conditions:
-
- experiment
- basic

translate_more_link: - id
- 'gbztms1'
- 'span'

translate_click_translate:
- id
- "gb_51"
- "a"
- "^http://translate.google.com/.hl=en.tab=wT$"

0 comments on commit 6441f12

Please sign in to comment.