Skip to content

Commit

Permalink
Better specs for ajax search
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Mar 25, 2014
1 parent 6354c4a commit 0d1fbed
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 58 deletions.
68 changes: 39 additions & 29 deletions spec/interactions_spec.rb
Expand Up @@ -59,19 +59,27 @@
describe "ch.oddb.org" do

def add_one_drug_to_interactions(name)
@browser.url.should match ('/de/gcc/home_interactions/')
@browser.url.should match ('/de/gcc/home_interactions')
chooser = @browser.text_field(:id, 'interaction_chooser_searchbar')
value = nil
0.upto(10).each{ |idx|
chooser.set(name)
sleep idx*0.1
chooser.send_keys(:down)
sleep idx*0.1
chooser.send_keys(:enter)
sleep idx*0.1
value = chooser.value
break unless /#{name}/.match(value)
sleep 0.5
begin
chooser.set(name)
sleep idx*0.1
chooser.send_keys(:down)
sleep idx*0.1
chooser.send_keys(:enter)
sleep idx*0.1
value = chooser.value
break unless /#{name}/.match(value)
sleep 0.5
rescue StandardError => e
# return if e.is_a? Selenium::WebDriver::Error::StaleElementReferenceError
puts e.inspect
puts caller[0..5]
createScreenshot(@browser, "rescue_#{name}_#{__LINE__}")
return
end
}
# require 'pry'; binding.pry
chooser.set(value + "\n")
Expand Down Expand Up @@ -104,27 +112,31 @@ def check_url_with_epha_example_interaction(url)
# sleep
@browser.goto OddbUrl
end
it "should show work without a trailing slash after home_interactions" do
url = "#{OddbUrl}/de/gcc/home_interactions"
@browser.goto url
add_one_drug_to_interactions(TwoMedis.first)
end
it "should show be able to use the delete_all" do
url = "#{OddbUrl}/de/gcc/home_interactions/"
@browser.goto url
@browser.url.should match ('/de/gcc/home_interactions/')
add_one_drug_to_interactions(TwoMedis.first)
add_one_drug_to_interactions(TwoMedis.last)
url = @browser.url
url.match(RegExpTwoMedis).should_not be nil
url.should match(RegExpTwoMedis)
inhalt = @browser.text
inhalt.match(/#{TwoMedis.first}/i).should_not be nil
inhalt.match(/#{TwoMedis.last}/i).should_not be nil
inhalt.should match(/#{TwoMedis.first}/i)
inhalt.should match(/#{TwoMedis.last}/i)
@browser.link(:text => /Alle löschen/i).click
sleep(0.5)
url = @browser.url
inhalt = @browser.text
url.match(RegExpOneMedi).should be nil
url.match(RegExpTwoMedis).should be nil
inhalt.match(/#{TwoMedis.first}/i).should be nil
inhalt.match(/#{TwoMedis.last}/i).should be nil
url.should_not match(RegExpOneMedi)
url.should_not match(RegExpTwoMedis)
inhalt.should_not match(/#{TwoMedis.first}/i)
inhalt.should_not match(/#{TwoMedis.last}/i)
end

it "should show the correct url after deleting a medicament" do
url = "#{OddbUrl}/de/gcc/home_interactions/"
@browser.goto url
Expand All @@ -142,23 +154,22 @@ def check_url_with_epha_example_interaction(url)
inhalt.match(/#{name}/i).should_not be nil
}
@browser.link(:title => /Löschen/i).click
sleep(0.5)
sleep(2)
url = @browser.url
inhalt = @browser.text
inhalt.match(/#{TwoMedis.first}/i).should be nil
inhalt.match(/#{TwoMedis.last}/i).should_not be nil
url.match(RegExpTwoMedis).should be nil
url.match(RegExpOneMedi).should_not be nil
inhalt.should match(/#{TwoMedis.last}/i)
inhalt.should_not match(/#{TwoMedis.first}/i)
url.should_not match(RegExpTwoMedis)
url.should match(RegExpOneMedi)
@browser.link(:title => /Löschen/i).click
sleep(0.5)
url = @browser.url
inhalt = @browser.text
url.match(RegExpOneMedi).should be nil
url.match(RegExpTwoMedis).should be nil
inhalt.match(/#{TwoMedis.first}/i).should be nil
inhalt.match(/#{TwoMedis.last}/i).should be nil
url.should_not match(RegExpOneMedi)
url.should_not match(RegExpTwoMedis)
inhalt.should_not match(/#{TwoMedis.first}/i)
inhalt.should_not match(/#{TwoMedis.last}/i)
end

it "should should not contain Wechselwirkungen" do
url = "#{OddbUrl}/de/gcc/home_interactions/"
@browser.goto url
Expand Down Expand Up @@ -245,7 +256,6 @@ def check_url_with_epha_example_interaction(url)
@browser.text.should match (test_medi)
@browser.url.should_not match ('/,')
end

after :all do
@browser.close
end
Expand Down
79 changes: 51 additions & 28 deletions spec/rezept_and_instantsearch_spec.rb
Expand Up @@ -9,15 +9,23 @@
def add_one_drug_to_rezept(name)
chooser = @browser.text_field(:id, 'prescription_searchbar')
0.upto(10).each{ |idx|
chooser.set(name)
sleep idx*0.1
chooser.send_keys(:down)
sleep idx*0.1
chooser.send_keys(:enter)
sleep idx*0.1
value = chooser.value
break unless /#{name}/.match(value)
sleep 0.5
begin
chooser.set(name)
sleep idx*0.1
chooser.send_keys(:down)
sleep idx*0.1
chooser.send_keys(:enter)
sleep idx*0.1
value = chooser.value
break unless /#{name}/.match(value)
sleep 0.5
rescue StandardError => e
puts "in rescue"
createScreenshot(@browser, "rescue_#{name}_#{__LINE__}")
puts e.inspect
puts caller[0..5]
return
end
}
chooser.set(chooser.value + "\n")
createScreenshot(@browser, "_#{name}_#{__LINE__}")
Expand All @@ -31,6 +39,10 @@ def add_one_drug_to_rezept(name)

before :each do
@browser.goto OddbUrl
if @browser.link(:text=>'Plus').exists?
puts "Going from instant to plus"
@browser.link(:text=>'Plus').click
end
end

after :each do
Expand All @@ -43,7 +55,7 @@ def add_one_drug_to_rezept(name)
after :all do
@browser.close
end

it "should with four medicaments" do
medis = [ 'Losartan', 'Nolvadex', 'Paroxetin', 'Aspirin']
@browser.select_list(:name, "search_type").select("Markenname")
Expand All @@ -55,7 +67,7 @@ def add_one_drug_to_rezept(name)
url1 = @browser.url
sleep(0.5)
inhalt = @browser.text
inhalt.match(/#{medis[idx]}/i).should_not be nil
inhalt.should match(/#{medis[idx]}/i)
}
0.upto(3){ |idx|
@browser.link(:title => /Löschen/i).click
Expand All @@ -65,7 +77,7 @@ def add_one_drug_to_rezept(name)
inhalt = @browser.text
0.upto(3){
|idx|
inhalt.match(/#{medis[idx]}/i).should be nil
inhalt.should_not match(/#{medis[idx]}/i)
}
url2.match(RegExpTwoMedis).should be nil
url2.match(RegExpOneMedi).should be nil
Expand All @@ -83,15 +95,15 @@ def add_one_drug_to_rezept(name)
sleep(0.5)
inhalt = @browser.text
TwoMedis.each{ |name|
inhalt.match(/#{name}/i).should_not be nil
inhalt.should match(/#{name}/i)
}
url1.match(RegExpTwoMedis).should_not be nil
@browser.link(:title => /Löschen/i).click
sleep(0.5)
url2 = @browser.url
inhalt = @browser.text
inhalt.match(/#{TwoMedis.first}/i).should be nil
inhalt.match(/#{TwoMedis.last}/i).should_not be nil
inhalt.should_not match(/#{TwoMedis.first}/i) # was deleted
inhalt.should match(/#{TwoMedis.last}/i)
url2.match(RegExpTwoMedis).should be nil
url2.match(RegExpOneMedi).should be nil
endTime = Time.now
Expand All @@ -104,30 +116,41 @@ def add_one_drug_to_rezept(name)
it "should have a working instant search" do
medi = 'Nolvadex'
@browser.link(:text=>'Instant').click if @browser.link(:text=>'Instant').exists?
chooser = @browser.text_field(:id, 'searchbar')
0.upto(10).each{ |idx|
chooser.set(medi)
sleep idx*0.1
chooser.send_keys(:down)
sleep idx*0.1
value = chooser.value
res = /#{medi}/i.match(value)
sleep 0.5
break if /#{medi}/i.match(value) and value.length > medi.length
begin
chooser = @browser.text_field(:id, 'searchbar')
chooser.set(medi)
sleep idx*0.1
chooser.send_keys(:down)
sleep idx*0.1
value = chooser.value
res = medi.match(value)
sleep 0.5
break if /#{medi}/i.match(value) and value.length > medi.length
rescue StandardError => e
puts "in rescue"
createScreenshot(@browser, "rescue_#{medi}_#{__LINE__}")
puts e.inspect
puts caller[0..5]
next
end
}
@browser.send_keys("\n") # this is different to add_one_drug_to_rezept
@browser.send_keys("\n") # this is different to add_one_drug_to_rezept
idx = 0
while idx < 10
inhalt = @browser.text
break if inhalt.match(/Preisvergleich für/i)
sleep(1)
idx += 1
puts "Resending cr"
@browser.send_keys("\n") # this is different to add_one_drug_to_rezept
end
url = @browser.url
inhalt = @browser.text
inhalt.match(/Preisvergleich für/i).should_not be nil
inhalt.match(/#{medi}/i).should_not be nil
inhalt.match(/Zusammensetzung/i).should_not be nil
inhalt.match(/Filmtabletten/i).should_not be nil
inhalt.should match(/Preisvergleich für/i)
inhalt.should match(/#{medi}/i)
inhalt.should match(/Zusammensetzung/i)
inhalt.should match(/Filmtabletten/i)
end
end
4 changes: 3 additions & 1 deletion spec/smoketest_spec.rb
Expand Up @@ -59,13 +59,15 @@

it "should trigger the limitation after maximal 5 queries" do
waitForOddbToBeReady(@browser, OddbUrl)
logout
names = [ 'Aspirin', 'inderal', 'Sintrom', 'Incivo', 'Certican', 'Glucose']
res = false
saved = @idx
names.each {
|name|
@idx += 1
@browser.text_field(:name, "search_query").set("inderal")
waitForOddbToBeReady(@browser, OddbUrl)
@browser.text_field(:name, "search_query").set(name)
@browser.button(:name, "search").click
createScreenshot(@browser, '_'+@idx.to_s)
if /Abfragebeschränkung auf 5 Abfragen pro Tag/.match(@browser.text)
Expand Down
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -29,6 +29,13 @@ def login(user = 'ngiger@ywesee.com', password='ng1234')
@browser.button(:value,"Anmelden").click
end

def logout
@browser = Watir::Browser.new(browsers2test[0]) unless @browser
@browser.goto OddbUrl
return unless @browser.link(:text=>'Abmeldung').exists?
@browser.link(:text=>'Abmeldung').click
end

def waitForOddbToBeReady(browser = nil, url = OddbUrl, maxWait = 30)
unless browser
browser = Watir::Browser.new(Browser2test[0])
Expand Down

0 comments on commit 0d1fbed

Please sign in to comment.