Fix tests to work with new css/layout.
[arvados.git] / apps / workbench / test / integration / users_test.rb
index 9ee12d80861d1609af75a51728e671570eac09b7..06d420c569c598386f59ed008cdf8fbece1700a4 100644 (file)
@@ -1,6 +1,9 @@
 require 'integration_helper'
+require 'selenium-webdriver'
+require 'headless'
 
 class UsersTest < ActionDispatch::IntegrationTest
+
   test "login as active user but not admin" do
     Capybara.current_driver = Capybara.javascript_driver
     visit page_with_token('active_trustedclient')
@@ -28,17 +31,21 @@ class UsersTest < ActionDispatch::IntegrationTest
     # go to the Attributes tab
     click_link 'Attributes'
     assert page.has_text? 'modified_by_user_uuid'
-    page.within(:xpath, '//a[@data-name="is_active"]') do
+    page.within(:xpath, '//span[@data-name="is_active"]') do
       assert_equal "true", text, "Expected user's is_active to be true"
     end
-    page.within(:xpath, '//a[@data-name="is_admin"]') do
+    page.within(:xpath, '//span[@data-name="is_admin"]') do
       assert_equal "false", text, "Expected user's is_admin to be false"
     end
 
   end
 
   test "create a new user" do
-    Capybara.current_driver = :webkit
+    headless = Headless.new
+    headless.start
+
+    Capybara.current_driver = :selenium
+
     visit page_with_token('admin_trustedclient')
 
     click_link 'Users'
@@ -61,26 +68,36 @@ class UsersTest < ActionDispatch::IntegrationTest
     # verify that the new user showed up in the users page
     assert page.has_text? 'foo@example.com'
 
-    page.within(:xpath, '//tr[@data-object-uuid][1]') do
-      assert (text.include? 'foo@example.com false'), 'Expected email'
-      new_user_uuid = text.split[0]
-
-      # go to the new user's page
-      click_link new_user_uuid
+    new_user_uuid = nil
+    all("tr").each do |elem|
+      if elem.text.include? 'foo@example.com'
+        new_user_uuid = elem.text.split[0]
+        break
+      end
     end
 
+    assert new_user_uuid, "Expected new user uuid not found"
+
+    # go to the new user's page
+    click_link new_user_uuid
+
     assert page.has_text? 'modified_by_user_uuid'
-    page.within(:xpath, '//a[@data-name="is_active"]') do
+    page.within(:xpath, '//span[@data-name="is_active"]') do
       assert_equal "false", text, "Expected new user's is_active to be false"
     end
 
     click_link 'Metadata'
     assert page.has_text? '(Repository: test_repo)'
     assert !(page.has_text? '(VirtualMachine:)')
+
+    headless.stop
   end
 
   test "setup the active user" do
-    Capybara.current_driver = :webkit
+    headless = Headless.new
+    headless.start
+
+    Capybara.current_driver = :selenium
     visit page_with_token('admin_trustedclient')
 
     click_link 'Users'
@@ -97,6 +114,7 @@ class UsersTest < ActionDispatch::IntegrationTest
     click_link 'Setup Active User'
 
     sleep(0.1)
+
     popup = page.driver.browser.window_handles.last
     page.within_window popup do
       assert has_text? 'Virtual Machine'
@@ -104,7 +122,7 @@ class UsersTest < ActionDispatch::IntegrationTest
       click_button "Submit"
     end
 
-    sleep(0.1)
+    sleep(1)
     assert page.has_text? 'modified_by_client_uuid'
 
     click_link 'Metadata'
@@ -129,10 +147,15 @@ class UsersTest < ActionDispatch::IntegrationTest
     click_link 'Metadata'
     assert page.has_text? '(Repository: second_test_repo)'
     assert page.has_text? '(VirtualMachine: testvm.shell)'
+
+    headless.stop
   end
 
   test "unsetup active user" do
-    Capybara.current_driver = :webkit
+    headless = Headless.new
+    headless.start
+
+    Capybara.current_driver = :selenium
 
     visit page_with_token('admin_trustedclient')
 
@@ -146,7 +169,7 @@ class UsersTest < ActionDispatch::IntegrationTest
     # Verify that is_active is set
     click_link 'Attributes'
     assert page.has_text? 'modified_by_user_uuid'
-    page.within(:xpath, '//a[@data-name="is_active"]') do
+    page.within(:xpath, '//span[@data-name="is_active"]') do
       assert_equal "true", text, "Expected user's is_active to be true"
     end
 
@@ -160,8 +183,9 @@ class UsersTest < ActionDispatch::IntegrationTest
     sleep(0.1)
 
     # Should now be back in the Attributes tab for the user
+    page.driver.browser.switch_to.alert.accept
     assert page.has_text? 'modified_by_user_uuid'
-    page.within(:xpath, '//a[@data-name="is_active"]') do
+    page.within(:xpath, '//span[@data-name="is_active"]') do
       assert_equal "false", text, "Expected user's is_active to be false after unsetup"
     end
 
@@ -188,6 +212,8 @@ class UsersTest < ActionDispatch::IntegrationTest
     click_link 'Metadata'
     assert page.has_text? '(Repository: second_test_repo)'
     assert page.has_text? '(VirtualMachine: testvm.shell)'
+
+    headless.stop
   end
 
 end