链接在新 window 中打开 - Cheezy page-object ruby gem with selenium
links opening in new window - Cheezy page-object ruby gem with selenium
我是页面对象和 selenium 的新手,但到目前为止一切正常。我为此页面测试的最后一个元素是社交媒体 links.
为了检查 link 是否正确,我通常单击它们然后使用 selenium 的 driver.current_url 检查 window 的 url 是否是我们的d 期望 link,但这些社交媒体按钮在新的 window 中打开 links(这只是他们的静态 facebook 页面而不是登录等)导致测试失败
有没有办法:
1-强制 link 在当前 window 中打开,或者
2-从 link_element 中提取目标 url?
这是测试的样子 atm:
def test_facebook_button
assert @testpage.facebook_icon?, 'Facebook button not found'
@testpage.facebook_icon_link
sleep 5
assert @browser.current_url == '<facebookurlforsite>', 'Facebook link does not open expected URL'
end
如果不是我猜我只是使用实际的 selenium 方法作为某种例外来手动获取 link 的属性,我不希望某些元素出现在页面模型中还有一些在测试本身,但我可以看到它可能是多么必要
如果您只是检查 link 是否导航到右侧 URL,检查 link 的 href
属性将是最快的。 PageObject::Elements::Link
元素为此有一个 href
method。
假设 facebook_icon_link
是由访问器方法定义的 link,您将调用:
facebook_icon_link_element.href
换句话说,断言可以写成:
assert facebook_icon_link_element.href == '<facebookurlforsite>'
我是页面对象和 selenium 的新手,但到目前为止一切正常。我为此页面测试的最后一个元素是社交媒体 links.
为了检查 link 是否正确,我通常单击它们然后使用 selenium 的 driver.current_url 检查 window 的 url 是否是我们的d 期望 link,但这些社交媒体按钮在新的 window 中打开 links(这只是他们的静态 facebook 页面而不是登录等)导致测试失败
有没有办法:
1-强制 link 在当前 window 中打开,或者
2-从 link_element 中提取目标 url?
这是测试的样子 atm:
def test_facebook_button
assert @testpage.facebook_icon?, 'Facebook button not found'
@testpage.facebook_icon_link
sleep 5
assert @browser.current_url == '<facebookurlforsite>', 'Facebook link does not open expected URL'
end
如果不是我猜我只是使用实际的 selenium 方法作为某种例外来手动获取 link 的属性,我不希望某些元素出现在页面模型中还有一些在测试本身,但我可以看到它可能是多么必要
如果您只是检查 link 是否导航到右侧 URL,检查 link 的 href
属性将是最快的。 PageObject::Elements::Link
元素为此有一个 href
method。
假设 facebook_icon_link
是由访问器方法定义的 link,您将调用:
facebook_icon_link_element.href
换句话说,断言可以写成:
assert facebook_icon_link_element.href == '<facebookurlforsite>'