Created
May 10, 2017 09:50
-
-
Save 1010real/0c078b912c7732c0a14cad07ce41d685 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
require "selenium-webdriver" | |
gem "test-unit" | |
require "test/unit" | |
class Case1WebdriverMoto < 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_moto | |
@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") } | |
# ERROR: Caught exception [ERROR: Unsupported command [captureEntirePageScreenshot | /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