require 'watir-webdriver'
require 'minitest/autorun'
class Test2 < MiniTest::Unit::TestCase
def test_2
browser =Watir::Browser.new :firefox
browser.goto 'http://gw03.nextix.org/login'
accept_next_alert=true
browser.text_field(:name, "username").clear
browser.text_field(:name, "username").send_keys "hubeunice"
browser.text_field(:name, "password").clear
browser.text_field(:name, "password").send_keys "test1"
browser.text_field(:name, "login").click
browser.text_field(:name, "password").clear
browser.text_field(:name, "password").send_keys "test2"
browser.text_field(:name, "login").click
browser.text_field(:name, "username").clear
browser.text_field(:name, "username").send_keys "admin"
browser.text_field(:name, "password").clear
browser.text_field(:name, "password").send_keys "admin"
browser.text_field(:name, "login").click
browser.text_field(:link, "Dashboard").click
browser.text_field(:link, "Customers").click
browser.text_field(:css, "button.btn.btn-add").click
browser.text_field(:id, "customer_name").click
browser.text_field(:id, "customer_name").clear
browser.text_field(:id, "customer_name").send_keys "ping"
browser.text_field(:xpath, "(//button[@type='button'])[9]").click
browser.text_field(:link, "Sub-D").click
browser.text_field(:xpath, "(//button[@type='button'])[7]").click
browser.text_field(:xpath, "//form[@id='customer-form']/fieldset/div/div[2]/div/div[2]/div/div/ul/li[2]/a/span").click
browser.text_field(:id, "unit_bldg").clear
browser.text_field(:id, "unit_bldg").send_keys "123"
browser.text_field(:id, "street").clear
browser.text_field(:id, "street").send_keys "ljd"
browser.text_field(:xpath, "(//button[@type='button'])[13]").click
browser.text_field(:link, "REGION VII").click
browser.text_field(:xpath, "(//button[@type='button'])[12]").click
browser.text_field(:xpath, "//form[@id='customer-form']/fieldset/div[2]/div[4]/div/div[2]/div/div/ul/li[4]/a/span").click
browser.text_field(:xpath, "(//button[@type='button'])[14]").click
browser.text_field(:xpath, "//form[@id='customer-form']/fieldset/div[2]/div[6]/div/div[2]/div/div/ul/li[9]/a/span").click
browser.text_field(:xpath, "(//button[@type='button'])[15]").click
browser.text_field(:xpath, "//form[@id='customer-form']/fieldset/div[2]/div[7]/div/div[2]/div/div/ul/li[10]/a/span").click
browser.text_field(:id, "minimum_load_account").clear
browser.text_field(:id, "minimum_load_account").send_keys "12"
browser.text_field(:xpath, "(//button[@type='button'])[18]").click
browser.text_field(:xpath, "//form[@id='customer-form']/fieldset/div[4]/div[5]/div/div[2]/div/div/ul/li[3]/a/span").click
browser.text_field(:id, "daily_load_limit").clear
browser.text_field(:id, "daily_load_limit").send_keys "12"
browser.text_field(:id, "no_frequency").click
browser.text_field(:css, "div.col-xs-2.col-xs-offset-4 > div.form-group > div.pull-left.label-wrapper > div.checkbox > label > input[name=\"frequency_visit[]\"]").click
browser.text_field(:xpath, "(//input[@name='frequency_visit[]'])[4]").click
browser.text_field(:css, "button.btn.btn-modal-submit").click
browser.text_field(:link, "Logout").click
browser.text_field(:css, "button.btn.btn-logout-yes").click
browser.text_field(:css, "button.btn.btn-logout-yes").click
end
def element_present?(how, what)
text_field(how, what)
true
rescue Watir::Browser::Error::NoSuchElementError
false
end
def alert_present?()
switch_to.alert
true
rescue Watir::Browser::Error::NoAlertPresentError
false
end
def verify(&blk)
yield
rescue MiniTest::Unit::AssertionFailedError => ex
@verification_errors << ex
end
def close_alert_and_get_its_text(how, what)
alert = 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
init1=Test2
答案 0 :(得分:0)
您可以使用@browser.button(:name => 'login').click
而不是
@browser.text_field(:name => 'login').click
如果您怀疑要使用哪个元素,可以检查元素或尝试使用Firebug 2.0.8以使其更容易。