我最近升级了:
要:
经过一点点痛苦之后,我终于开始跑步了!虽然有一个小小的障碍。方法#present?
,#exists?
和#visible?
不会返回任何内容,而是会超时。同样,#wait_until
,x_element.when_present?
和类似的方法都遇到了同样的问题!
这是我的页面对象:
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 (.*)$/'
会发生什么事情,脚本会点击#logged_in?
方法而只是坐在那里。然后它会超时并给我上面的错误信息。
我无法帮助并想知道这是否是某种配置问题,而且只需要正确加载或者是否存在某种更深陷的陷阱。
编辑:
当我将Selenium记录器级别更改为&#39; Info&#39;时,我重复了以下30秒:
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"}}
EDIT2:无论元素是否实际存在,都会发生这种情况。