anahorn

Selenium WebDriver Ruby: Part 11 (Test/Unit)

Jun 4th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.31 KB | None | 0 0
  1. require 'rubygems'
  2. require 'selenium-webdriver'
  3. require 'test/unit'
  4.  
  5. class ExampleTestCase < Test::Unit::TestCase
  6.  
  7. # Starting browser before each test
  8. def setup
  9.     @browser = Selenium::WebDriver.for :firefox
  10.     @browser.get "http://localhost/page8"
  11.     @wait = Selenium::WebDriver::Wait.new(:timeout => 15)
  12. end
  13.  
  14. # Closing browser after each test
  15. def teardown
  16.     @browser.quit
  17. end
  18.  
  19. # Check that the table is there
  20. def test_table_existence
  21.     assert @wait.until {
  22.         @browser.find_element(:id, "booktable").displayed?
  23.     }
  24. end
  25.  
  26. # Checking values in the table cells
  27. def test_table_values
  28.     # Waiting for the values to appear
  29.     assert @wait.until {
  30.         @browser.find_elements(:xpath => "//table[@id='booktable']/tbody/tr")[0].text.split(' ')[0] == "fraise"
  31.     }
  32.     assert @wait.until {
  33.         @browser.find_elements(:xpath => "//table[@id='booktable']/tbody/tr")[0].text.split(' ')[1] == "orange"
  34.     }
  35.     # Not waiting for the values to appear, assuming they are already visible
  36.     assert_equal(@browser.find_elements(:xpath => "//table[@id='booktable']/tbody/tr")[1].text.split(' ')[0], "vin")
  37.     assert_equal(@browser.find_elements(:xpath => "//table[@id='booktable']/tbody/tr")[1].text.split(' ')[1], "eau")
  38.     assert_not_equal(@browser.find_elements(:xpath => "//table[@id='booktable']/tbody/tr")[1].text.split(' ')[0], "fake")
  39. end
  40.  
  41. end
Advertisement
Add Comment
Please, Sign In to add comment