--- wui/src/test/functional/interface_test.rb | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/wui/src/test/functional/interface_test.rb b/wui/src/test/functional/interface_test.rb index dbee928..478e765 100644 --- a/wui/src/test/functional/interface_test.rb +++ b/wui/src/test/functional/interface_test.rb @@ -35,7 +35,7 @@ if File.exists? File.dirname(__FILE__) + '/../selenium.rb' @site_url, 15000) @browser.start - @browser.set_speed(1500) # ms delay between operations + #@browser.set_speed(1500) # ms delay between operations @browser.open(@site_url) end @@ -114,12 +114,14 @@ if File.exists? File.dirname(__FILE__) + '/../selenium.rb' "selenium.isElementPresent(\"//div[@id='vm_action_results']/div[3]/div/div[2]/a\")", 10000) @browser.click "//div[@id='vm_action_results']/div[3]/div/div[2]/a" + sleep 5 # give vm time to start @browser.click "//div[@id='side']/ul/li/ul/li[1]/span/a" @browser.wait_for_condition( - "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\")", + "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\") && " + + "selenium.getText(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\") == \"running\"", 20000) - assert_equal("running", - @browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div")) + #assert_equal("running", + #@browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div")) # stop / destroy vm @browser.click "//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[1]/div/input" @@ -128,12 +130,14 @@ if File.exists? File.dirname(__FILE__) + '/../selenium.rb' "selenium.isElementPresent(\"//div[@id='vm_action_results']/div[3]/div/div[2]/a\")", 10000) @browser.click "//div[@id='vm_action_results']/div[3]/div/div[2]/a" + sleep 5 # give vm time to stop @browser.click "//div[@id='side']/ul/li/ul/li[1]/span/a" @browser.wait_for_condition( - "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\")", + "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\") && " + + "selenium.getText(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\") == \"stopped\"", 20000) - assert_equal("stopped", - @browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div")) + #assert_equal("stopped", + #@browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div")) end -- 1.5.4.1
--- wui/src/app/models/vm.rb | 3 ++- wui/src/test/functional/vm_controller_test.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/wui/src/app/models/vm.rb b/wui/src/app/models/vm.rb index 80c7efb..9520a4c 100644 --- a/wui/src/app/models/vm.rb +++ b/wui/src/app/models/vm.rb @@ -29,7 +29,8 @@ class Vm < ActiveRecord::Base end has_and_belongs_to_many :storage_volumes validates_presence_of :uuid, :description, :num_vcpus_allocated, - :memory_allocated_in_mb, :memory_allocated, :vnic_mac_addr + :boot_device, :memory_allocated_in_mb, + :memory_allocated, :vnic_mac_addr acts_as_xapian :texts => [ :uuid, :description, :vnic_mac_addr, :state ], :terms => [ [ :search_users, 'U', "search_users" ] ] diff --git a/wui/src/test/functional/vm_controller_test.rb b/wui/src/test/functional/vm_controller_test.rb index 0817754..a626430 100644 --- a/wui/src/test/functional/vm_controller_test.rb +++ b/wui/src/test/functional/vm_controller_test.rb @@ -56,7 +56,7 @@ class VmControllerTest < Test::Unit::TestCase def test_create num_vms = Vm.count - post :create, :vm_resource_pool_name => 'foobar', :hardware_pool_id => 1, :vm => { :uuid => 'f43b298c-1e65-46fa-965f-0f6fb9ffaa10', :description => 'descript', :num_vcpus_allocated => 4, :memory_allocated => 262144, :vnic_mac_addr => 'AA:BB:CC:DD:EE:FF' } + post :create, :vm_resource_pool_name => 'foobar', :hardware_pool_id => 1, :vm => { :uuid => 'f43b298c-1e65-46fa-965f-0f6fb9ffaa10', :description => 'descript', :num_vcpus_allocated => 4, :memory_allocated => 262144, :vnic_mac_addr => 'AA:BB:CC:DD:EE:FF', :boot_device => 'foobar' } assert_response :success -- 1.5.4.1
> @@ -114,12 +114,14 @@ if File.exists? File.dirname(__FILE__) + '/../selenium.rb' > "selenium.isElementPresent(\"//div[@id='vm_action_results']/div[3]/div/div[2]/a\")", > 10000) > @browser.click "//div[@id='vm_action_results']/div[3]/div/div[2]/a" > + sleep 5 # give vm time to startWhy is sleep needed here at all if wait_for_condition below is expecting 'running' to show up? In general, using sleep for synchronization is wrong, although it might seem to work.> @browser.click "//div[@id='side']/ul/li/ul/li[1]/span/a" > @browser.wait_for_condition( > - "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\")", > + "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\") && " + > + "selenium.getText(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\") == \"running\"", > 20000) > - assert_equal("running", > - @browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div")) > + #assert_equal("running", > + #@browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div"))What happens if wait_for_condition times out? Will selenium raise an exception, failing the test or it just continues? If latter, you need to keep the assert. In general, if removing lines, just delete them instead of commenting, we have git to keep the history.> # stop / destroy vm > @browser.click "//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[1]/div/input" > @@ -128,12 +130,14 @@ if File.exists? File.dirname(__FILE__) + '/../selenium.rb' > "selenium.isElementPresent(\"//div[@id='vm_action_results']/div[3]/div/div[2]/a\")", > 10000) > @browser.click "//div[@id='vm_action_results']/div[3]/div/div[2]/a" > + sleep 5 # give vm time to stopsame questions as above> @browser.click "//div[@id='side']/ul/li/ul/li[1]/span/a" > @browser.wait_for_condition( > - "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\")", > + "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\") && " + > + "selenium.getText(\"//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div\") == \"stopped\"", > 20000) > - assert_equal("stopped", > - @browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div")) > + #assert_equal("stopped", > + #@browser.get_text("//table[@id='vms_grid']/tbody/tr[" + (num_vms.to_i + 1).to_s + "]/td[7]/div"))
Alan Pevec wrote:>> @@ -114,12 +114,14 @@ if File.exists? File.dirname(__FILE__) + >> '/../selenium.rb' >> >> "selenium.isElementPresent(\"//div[@id='vm_action_results']/div[3]/div/div[2]/a\")", >> >> 10000) >> @browser.click >> "//div[@id='vm_action_results']/div[3]/div/div[2]/a" >> + sleep 5 # give vm time to start > > Why is sleep needed here at all if wait_for_condition below is > expecting 'running' to show up? > In general, using sleep for synchronization is wrong, although it > might seem to work.As far as I can tell the vm tab doesn't get automatically updated via javascript when the state of a vm changes, thus I need to wait a little time and manually refresh the page before I check for the status. I could do an assertion on the backend, and check the actual vm table entry itself, but these are interface tests, thus assertions should be on interface components.> >> @browser.click "//div[@id='side']/ul/li/ul/li[1]/span/a" >> @browser.wait_for_condition( >> - >> "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + >> (num_vms.to_i + 1).to_s + "]/td[7]/div\")", >> + >> "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + >> (num_vms.to_i + 1).to_s + "]/td[7]/div\") && " + >> + "selenium.getText(\"//table[@id='vms_grid']/tbody/tr[" >> + (num_vms.to_i + 1).to_s + "]/td[7]/div\") == \"running\"", >> 20000) >> - assert_equal("running", >> - @browser.get_text("//table[@id='vms_grid']/tbody/tr[" + >> (num_vms.to_i + 1).to_s + "]/td[7]/div")) >> + #assert_equal("running", >> + #@browser.get_text("//table[@id='vms_grid']/tbody/tr[" + >> (num_vms.to_i + 1).to_s + "]/td[7]/div")) > > What happens if wait_for_condition times out? Will selenium raise an > exception, failing the test or it just continues? If latter, you need > to keep the assert. > In general, if removing lines, just delete them instead of commenting, > we have git to keep the history.Selenium raises an exception when wait_for_condition times out and the test fails so the assertion can be safely removed. My bad on the commenting, just code I forgot to remove, will keep it in mind in the future.> >> # stop / destroy vm >> @browser.click "//table[@id='vms_grid']/tbody/tr[" + >> (num_vms.to_i + 1).to_s + "]/td[1]/div/input" >> @@ -128,12 +130,14 @@ if File.exists? File.dirname(__FILE__) + >> '/../selenium.rb' >> >> "selenium.isElementPresent(\"//div[@id='vm_action_results']/div[3]/div/div[2]/a\")", >> >> 10000) >> @browser.click >> "//div[@id='vm_action_results']/div[3]/div/div[2]/a" >> + sleep 5 # give vm time to stop > > same questions as above > >> @browser.click "//div[@id='side']/ul/li/ul/li[1]/span/a" >> @browser.wait_for_condition( >> - >> "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + >> (num_vms.to_i + 1).to_s + "]/td[7]/div\")", >> + >> "selenium.isElementPresent(\"//table[@id='vms_grid']/tbody/tr[" + >> (num_vms.to_i + 1).to_s + "]/td[7]/div\") && " + >> + "selenium.getText(\"//table[@id='vms_grid']/tbody/tr[" >> + (num_vms.to_i + 1).to_s + "]/td[7]/div\") == \"stopped\"", >> 20000) >> - assert_equal("stopped", >> - @browser.get_text("//table[@id='vms_grid']/tbody/tr[" + >> (num_vms.to_i + 1).to_s + "]/td[7]/div")) >> + #assert_equal("stopped", >> + #@browser.get_text("//table[@id='vms_grid']/tbody/tr[" + >> (num_vms.to_i + 1).to_s + "]/td[7]/div")) >
Mohammed Morsi wrote:> --- > wui/src/app/models/vm.rb | 3 ++- > wui/src/test/functional/vm_controller_test.rb | 2 +- > 2 files changed, 3 insertions(+), 2 deletions(-) > > diff --git a/wui/src/app/models/vm.rb b/wui/src/app/models/vm.rb > index 80c7efb..9520a4c 100644 > --- a/wui/src/app/models/vm.rb > +++ b/wui/src/app/models/vm.rb > @@ -29,7 +29,8 @@ class Vm < ActiveRecord::Base > end > has_and_belongs_to_many :storage_volumes > validates_presence_of :uuid, :description, :num_vcpus_allocated, > - :memory_allocated_in_mb, :memory_allocated, :vnic_mac_addr > + :boot_device, :memory_allocated_in_mb, > + :memory_allocated, :vnic_mac_addr > > acts_as_xapian :texts => [ :uuid, :description, :vnic_mac_addr, :state ], > :terms => [ [ :search_users, 'U', "search_users" ] ] > diff --git a/wui/src/test/functional/vm_controller_test.rb b/wui/src/test/functional/vm_controller_test.rb > index 0817754..a626430 100644 > --- a/wui/src/test/functional/vm_controller_test.rb > +++ b/wui/src/test/functional/vm_controller_test.rb > @@ -56,7 +56,7 @@ class VmControllerTest < Test::Unit::TestCase > def test_create > num_vms = Vm.count > > - post :create, :vm_resource_pool_name => 'foobar', :hardware_pool_id => 1, :vm => { :uuid => 'f43b298c-1e65-46fa-965f-0f6fb9ffaa10', :description => 'descript', :num_vcpus_allocated => 4, :memory_allocated => 262144, :vnic_mac_addr => 'AA:BB:CC:DD:EE:FF' } > + post :create, :vm_resource_pool_name => 'foobar', :hardware_pool_id => 1, :vm => { :uuid => 'f43b298c-1e65-46fa-965f-0f6fb9ffaa10', :description => 'descript', :num_vcpus_allocated => 4, :memory_allocated => 262144, :vnic_mac_addr => 'AA:BB:CC:DD:EE:FF', :boot_device => 'foobar' } > > assert_response :success > >almost ACK -- you should replace 'foobar' in ":boot_device => 'foobar'" with one of the valid values -- 'network' or 'hd' or taskomatic won't know what to do with it. With that change, ACK Scott