From 67b75a905bca62d0f7ea943f016c6f19e785e1b3 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 15 May 2017 17:24:17 -0700 Subject: [PATCH 1/6] Removed minutest/spec dependency Better test titles use single quotes --- petclinic_spec.rb | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/petclinic_spec.rb b/petclinic_spec.rb index c2000e2fe..cb6e79381 100644 --- a/petclinic_spec.rb +++ b/petclinic_spec.rb @@ -1,6 +1,5 @@ require 'headless' require 'selenium-webdriver' -require 'minitest/spec' require 'minitest/autorun' describe 'Petlinic' do @@ -10,7 +9,6 @@ describe 'Petlinic' do @driver = Selenium::WebDriver.for :firefox @driver.navigate.to 'http://tomcat:8080/petclinic' - @wait = Selenium::WebDriver::Wait.new(:timeout => 30) @driver.manage.timeouts.implicit_wait = 30 end @@ -19,38 +17,38 @@ describe 'Petlinic' do end describe 'when homepage is available' do - it 'I should see page title containing PetClinic' do + it 'should show correct page title' do sleep 3 - assert @driver.title == "PetClinic :: a Spring Framework demonstration" + assert @driver.title == 'PetClinic :: a Spring Framework demonstration' end end describe 'when homepage is available' do - it 'click the find owners link' do - @driver.find_element(:class, "icon-search").click + it 'should have Find Owners page' do + @driver.find_element(:class, 'icon-search').click sleep 3 - h2 = @driver.find_element(:tag_name, "h2") - assert h2.text == "Find Owners" + h2 = @driver.find_element(:tag_name, 'h2') + assert h2.text == 'Find Owners' end end describe 'when homepage is available' do - it 'click the veterinarians link' do - @driver.find_element(:class, "icon-th-list").click + it 'should have veterinarians page' do + @driver.find_element(:class, 'icon-th-list').click sleep 3 - h2 = @driver.find_element(:tag_name, "h2") - assert h2.text == "Veterinarians" + h2 = @driver.find_element(:tag_name, 'h2') + assert h2.text == 'Veterinarians' end end describe 'when homepage is available' do - it 'search for veterinarian' do - @driver.find_element(:class, "icon-th-list").click - search_box = @driver.find_element(:id, "vets_filter") - textBox = search_box.find_element(:tag_name, "input") - textBox.send_keys("Helen Leary") - vets = @driver.find_element(:id, "vets").text - assert vets.split("\n")[1] == "Helen Leary radiology" + it 'should have search for veterinarian feature' do + @driver.find_element(:class, 'icon-th-list').click + search_box = @driver.find_element(:id, 'vets_filter') + textBox = search_box.find_element(:tag_name, 'input') + textBox.send_keys('Helen Leary') + vets = @driver.find_element(:id, 'vets').text + assert vets.split("\n")[1] == 'Helen Leary radiology' end end From a25bf6636b55cb6c723599470e560a3958fefdd6 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 15 May 2017 17:41:35 -0700 Subject: [PATCH 2/6] accurate locators for veterinarian filter test --- petclinic_spec.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/petclinic_spec.rb b/petclinic_spec.rb index cb6e79381..4698cf92c 100644 --- a/petclinic_spec.rb +++ b/petclinic_spec.rb @@ -44,12 +44,9 @@ describe 'Petlinic' do describe 'when homepage is available' do it 'should have search for veterinarian feature' do @driver.find_element(:class, 'icon-th-list').click - search_box = @driver.find_element(:id, 'vets_filter') - textBox = search_box.find_element(:tag_name, 'input') - textBox.send_keys('Helen Leary') - vets = @driver.find_element(:id, 'vets').text - assert vets.split("\n")[1] == 'Helen Leary radiology' + @driver.find_element(:tag_name, 'input').send_keys('Helen Leary') + result = @driver.find_element(:css, 'td.sorting_1').text + assert result == 'Helen Leary' end end - end From ed6da90d64001eef2866aa5f4d6ed8a30962283f Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 15 May 2017 17:41:56 -0700 Subject: [PATCH 3/6] fixed formatting --- petclinic_spec.rb | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/petclinic_spec.rb b/petclinic_spec.rb index 4698cf92c..5ac8d2fd8 100644 --- a/petclinic_spec.rb +++ b/petclinic_spec.rb @@ -18,35 +18,35 @@ describe 'Petlinic' do describe 'when homepage is available' do it 'should show correct page title' do - sleep 3 - assert @driver.title == 'PetClinic :: a Spring Framework demonstration' + sleep 3 + assert @driver.title == 'PetClinic :: a Spring Framework demonstration' end end describe 'when homepage is available' do it 'should have Find Owners page' do - @driver.find_element(:class, 'icon-search').click - sleep 3 - h2 = @driver.find_element(:tag_name, 'h2') - assert h2.text == 'Find Owners' + @driver.find_element(:class, 'icon-search').click + sleep 3 + h2 = @driver.find_element(:tag_name, 'h2') + assert h2.text == 'Find Owners' end end describe 'when homepage is available' do - it 'should have veterinarians page' do - @driver.find_element(:class, 'icon-th-list').click - sleep 3 - h2 = @driver.find_element(:tag_name, 'h2') - assert h2.text == 'Veterinarians' - end + it 'should have veterinarians page' do + @driver.find_element(:class, 'icon-th-list').click + sleep 3 + h2 = @driver.find_element(:tag_name, 'h2') + assert h2.text == 'Veterinarians' + end end describe 'when homepage is available' do - it 'should have search for veterinarian feature' do - @driver.find_element(:class, 'icon-th-list').click - @driver.find_element(:tag_name, 'input').send_keys('Helen Leary') - result = @driver.find_element(:css, 'td.sorting_1').text - assert result == 'Helen Leary' - end + it 'should have search for veterinarian feature' do + @driver.find_element(:class, 'icon-th-list').click + @driver.find_element(:tag_name, 'input').send_keys('Helen Leary') + result = @driver.find_element(:css, 'td.sorting_1').text + assert result == 'Helen Leary' + end end end From 22df94a1f126b50f7053960e7457f4f0163b7541 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 15 May 2017 17:52:18 -0700 Subject: [PATCH 4/6] Wait for unique elements of the expected page --- petclinic_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/petclinic_spec.rb b/petclinic_spec.rb index 5ac8d2fd8..c0a3549f6 100644 --- a/petclinic_spec.rb +++ b/petclinic_spec.rb @@ -18,7 +18,6 @@ describe 'Petlinic' do describe 'when homepage is available' do it 'should show correct page title' do - sleep 3 assert @driver.title == 'PetClinic :: a Spring Framework demonstration' end end @@ -26,7 +25,7 @@ describe 'Petlinic' do describe 'when homepage is available' do it 'should have Find Owners page' do @driver.find_element(:class, 'icon-search').click - sleep 3 + @driver.find_element(:link_text, 'Add Owner') h2 = @driver.find_element(:tag_name, 'h2') assert h2.text == 'Find Owners' end @@ -35,7 +34,7 @@ describe 'Petlinic' do describe 'when homepage is available' do it 'should have veterinarians page' do @driver.find_element(:class, 'icon-th-list').click - sleep 3 + @driver.find_element(:link_text, 'View as XML') h2 = @driver.find_element(:tag_name, 'h2') assert h2.text == 'Veterinarians' end From cfae2df9aada80ee7f92f43493de4edcddaee3d2 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 15 May 2017 17:58:16 -0700 Subject: [PATCH 5/6] Better titles --- petclinic_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/petclinic_spec.rb b/petclinic_spec.rb index c0a3549f6..87a798a6c 100644 --- a/petclinic_spec.rb +++ b/petclinic_spec.rb @@ -32,7 +32,7 @@ describe 'Petlinic' do end describe 'when homepage is available' do - it 'should have veterinarians page' do + it 'should have Veterinarians page' do @driver.find_element(:class, 'icon-th-list').click @driver.find_element(:link_text, 'View as XML') h2 = @driver.find_element(:tag_name, 'h2') @@ -41,7 +41,7 @@ describe 'Petlinic' do end describe 'when homepage is available' do - it 'should have search for veterinarian feature' do + it 'should have Search for Veterinarian feature' do @driver.find_element(:class, 'icon-th-list').click @driver.find_element(:tag_name, 'input').send_keys('Helen Leary') result = @driver.find_element(:css, 'td.sorting_1').text From 8c5859572b65c625260c5819077cc4a6a9407f39 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 16 May 2017 09:00:48 -0700 Subject: [PATCH 6/6] Added comment to describe individual steps --- petclinic_spec.rb | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/petclinic_spec.rb b/petclinic_spec.rb index 87a798a6c..79702272a 100644 --- a/petclinic_spec.rb +++ b/petclinic_spec.rb @@ -22,29 +22,47 @@ describe 'Petlinic' do end end - describe 'when homepage is available' do + describe 'when site is available' do it 'should have Find Owners page' do + # click on Find Owners menu item @driver.find_element(:class, 'icon-search').click + + # wait to see Add Owner on the page that opens @driver.find_element(:link_text, 'Add Owner') - h2 = @driver.find_element(:tag_name, 'h2') - assert h2.text == 'Find Owners' + + # grab H2 content + h2 = @driver.find_element(:tag_name, 'h2').text + + assert h2 == 'Find Owners' end end - describe 'when homepage is available' do + describe 'when site is available' do it 'should have Veterinarians page' do + # click on Veterinarian menu item @driver.find_element(:class, 'icon-th-list').click + + # wait to see View as XML on the page that opens @driver.find_element(:link_text, 'View as XML') - h2 = @driver.find_element(:tag_name, 'h2') - assert h2.text == 'Veterinarians' + + # grab H2 content + h2 = @driver.find_element(:tag_name, 'h2').text + + assert h2 == 'Veterinarians' end end - describe 'when homepage is available' do + describe 'when site is available' do it 'should have Search for Veterinarian feature' do + # click on Veterinarian menu item @driver.find_element(:class, 'icon-th-list').click + + # type Veterinarian name in search box @driver.find_element(:tag_name, 'input').send_keys('Helen Leary') + + # grab first cell content in filtered results result = @driver.find_element(:css, 'td.sorting_1').text + assert result == 'Helen Leary' end end