Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require "json"
require "selenium-webdriver"
gem "test-unit"
require "test/unit"
class Case1Webdriver < Test::Unit::TestCase
def setup
@driver = Selenium::WebDriver.for :firefox
@base_url = "https://www.google.co.jp/"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
end
def teardown
@driver.quit
assert_equal [], @verification_errors
end
def test_case1_webdriver
@driver.get(@base_url + "/")
@driver.find_element(:id, "lst-ib").clear
@driver.find_element(:id, "lst-ib").send_keys "テスト"
@driver.find_element(:id, "lst-ib").clear
@driver.find_element(:id, "lst-ib").send_keys "テスト 英語"
@driver.find_element(:id, "lst-ib").send_keys :enter
@driver.find_element(:link, "テストの英語・英訳 - 英和辞典・和英辞典 Weblio辞書").click
verify { assert_equal "テスト", @driver.find_element(:id, "searchWord").attribute("value") }
@driver.save_screenshot('/tmp/capture.png');
end
def element_present?(how, what)
@receiver.find_element(how, what)
true
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
def alert_present?()
@receiver.switch_to.alert
true
rescue Selenium::WebDriver::Error::NoAlertPresentError
false
end
def verify(&blk)
yield
rescue Test::Unit::AssertionFailedError => ex
@verification_errors << ex
end
def close_alert_and_get_its_text(how, what)
alert = @receiver.switch_to().alert()
alert_text = alert.text
if (@accept_next_alert) then
alert.accept()
else
alert.dismiss()
end
alert_text
ensure
@accept_next_alert = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment