ruby - 如何使用页面对象 gem 导航到链接?
问题描述
调用方法时如何使用页面对象 gem 导航到页面?
class SidePage
include PageObject
link(:create, text: /Create/)
def navigate_to(link)
if link == 'Test'
create
else
navigate_to "http://test.jprr.w3test/#{link}" # --> here i need to navigate on else condition.
end
end
我需要根据 #{link} 文本在 else 条件下动态导航到给定的链接。
解决方案
您不能#navigate_to
在内部调用,#navigate_to
因为它将进入无限循环。有几种方法可以解决这个问题。
最简单的方法是以不同的方式命名您的方法。部分好处是很明显,此页面#navigate_to
与其他页面不同。
def navigate_or_click(link)
if link == 'Test'
create
else
navigate_to "http://test.jprr.w3test/#{link}"
end
end
如果你想坚持使用#navigate_to
方法名,你只需要调用适当的浏览器方法:
def navigate_or_click(link)
if link == 'Test'
create
else
browser.goto "http://test.jprr.w3test/#{link}" # or platform.navigate_to
end
end
推荐阅读
- typescript - 跨组件枚举的定义
- vue.js - 在 Vue js 的 Element Ui Carousel 中添加图像和文本
- c - 将值发送到另一个函数但不作为参数
- javascript - 在对象中迭代数组后为键创建单行数组
- javascript - JavaScript 中的数字是如何用二进制表示的
- python - 我收到 AttributeError:'NoneType' 对象没有属性 'text',但在我的“HTML 代码”中找不到错误
- r - Tidymodels:在 R 中进行 10 倍交叉验证后,从 TIbble 中取消最佳拟合模型的 RMSE 和 RSQ 值
- arrays - 如何将复杂数据类型列与pyspark数据框中的其他类型列连接起来?
- python - 如何在 PyQt 中添加到标题栏右键菜单
- mongodb - 如何调用子数组中另一个集合中的属性?