Ruby Watir/Page对象存在方法超时
我最近升级自:Ruby Watir/Page对象存在方法超时,ruby,selenium,watir,page-object-gem,Ruby,Selenium,Watir,Page Object Gem,我最近升级自: 页面对象1.2.2 Watir Webdriver 0.9.9 Selenium WebDriver 2.53.0 火狐45.8.0 致: 页面对象2.2.0 瓦蒂尔6.3.0 Selenium Webdriver 3.4.3 火狐52.2.0 经过一点痛苦之后,我终于让我的测试开始运行了!不过有一个小问题。方法#present?,#exists?,和#visible?不返回任何内容,它们只是超时。类似地,#等待_直到,x_元素。当_出现时?,以及类似的方法都遇到了相同的
- 页面对象1.2.2
- Watir Webdriver 0.9.9
- Selenium WebDriver 2.53.0
- 火狐45.8.0
- 页面对象2.2.0
- 瓦蒂尔6.3.0
- Selenium Webdriver 3.4.3
- 火狐52.2.0
#present?
,#exists?
,和#visible?
不返回任何内容,它们只是超时。类似地,#等待_直到
,x_元素。当_出现时?
,以及类似的方法都遇到了相同的问题
这是我的页面对象:
class LoginPage < TeamConnectPage
MAX_LOGIN_ATTEMPTS = 3
button :ok, value: /^OK$/i
button :submit, value: 'Login'
button :new_session, value: 'New Session'
link :logout, id: 'LINK_default_logout'
span :error_message, class: 'texterror'
text_field :username, name: 'j_username'
text_field :password, name: 'j_password'
def login_as(username)
username = username.to_s
do_logout if logged_in?
attempts = 0
try_login(username)
while username_element.present?
fail "#{MAX_LOGIN_ATTEMPTS} logins attempted unsuccessfully for user #{username}" if (attempts+=1) == MAX_LOGIN_ATTEMPTS
try_login(username)
end
if new_session_element.present?
new_session
logout_element.when_present(10)
end
end
private
def try_login(username)
self.username = username
self.password = 'test'
submit
wait_for_login_submit
end
def wait_for_login_submit
wait_until(10) { !username_element.present? || (username_element.present? && username_element.value.empty?) }
wait_until(10) { error_message_element.present? || logout_element.present? || new_session_element.present? }
end
def do_logout
logout
end
def logged_in?
logout_element.present?
end
end
def login_role role
caps = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
@browser ||= Watir::Browser.new(:firefox, desired_capabilities: caps)
@browser.driver.manage.window.maximize
@browser.goto('http://ntdmatters-it4.nwie.net/TeamConnect/login')
@logged_in_user = User[RoleMapping[role]]
on_page(LoginPage).login_as(@logged_in_user.userid)
end
这是我的装货单:
require 'pry'
require 'active_support'
require 'active_support/core_ext'
require 'chronic'
require 'page-object'
require 'rspec'
require 'watir'
require 'selenium-webdriver'
下面是我得到的错误:
timed out after 30 seconds, waiting for #<Watir::Anchor: located: false; {
:id=>"LINK_default_logout", :tag_name=>"a"}> to be located (Watir::Exception::UnknownObjectException)
(eval):1:in `process_watir_call'
./features/support/env.src/pages/login_page.rb:48:in `do_logout'
./features/support/env.src/pages/login_page.rb:15:in `login_as'
./features/step_definitions/login_steps.rb:24:in `login_role'
./features/step_definitions/login_steps.rb:2:in `/^I login to Project
with role (.*)$/'
EDIT2:无论元素是否实际存在,都会发生这种情况 watir如何自动等待是watir webdriver对watir 6的重大更新。使用以下命令运行代码:
Selenium::WebDriver.logger.level=:info
,它将显示驱动程序看到的调用。该错误意味着元素不在那里,但在您显示的\logged\u in?
代码中没有调用该元素。如果出现异常,我希望脚本在\try\u login
方法的第一行失败。我将错误粘贴到了代码中。我会编辑它,但实际的错误是:在30秒后超时,等待找到#“LINK\u default\u logout”,:tag\u name=>“a”}>(Watir::Exception::UnknownObjectException)
。我也在帖子中添加了stracktrace。我在帖子中添加了我在日志中发现的信息。
2017-07-12 12:11:21 INFO Selenium >>> http://127.0.0.1:4444/session/8d74a28f-
d8fc-4db6-a851-4f238edf7d70/element | {"using":"css selector","value":"#LINK_def
ault_logout"}
2017-07-12 12:11:21 INFO Selenium <- {"value":{"error":"no such element","messag
e":"Unable to locate element: #LINK_default_logout","stacktrace":"stack backtrac
e:\n 0: 0x4bd56f - <no info>\n 1: 0x4bdcc9 - <no info>\n
2: 0x43dc4d - <no info>\n 3: 0x44db84 - <no info>\n 4
: 0x44a1ca - <no info>\n 5: 0x4207bc - <no info>\n 6:
0x405e47 - <no info>\n 7: 0x6db3d9 - <no info>\n 8:
0x417847 - <no info>\n 9: 0x6d56d3 - <no info>\n 10: 0x
776c59cd - BaseThreadInitThunk"}}