我比Ruby和Capybara以及SitePrism更熟悉Java和Selenium,所以如果这个问题比较厚,我会道歉.
Selenium有一个非常有用的类来管理Select标签,Selenium :: WebDriver :: Support :: Select,它可以通过传递代表select 的Selenium Element(Selenium :: WebDriver :: Element)来创建.我想得到一个Select对象,所以我可以使用它方便的方法.
然而,使用SitePrism和Capybara,定义元素的标准方法使我能够访问由Capybara的Element类,Capybara :: Node :: Element建模的选择,我似乎无法找到提取底层Selenium元素的简单方法来自Capybara元素.
我一直在寻找替代方案,并找到了Capybara的#select方法,但这对我来说似乎非常有限,因为它看起来像是强迫你按值选择并且在页面上定义选择的参数非常窄.
有没有一种简单的方法可以从SitePrism/Capybara创建Selenium Select?或者有更好的方法完全这样做吗?谢谢!
我有一个黄瓜、红宝石、siteprism 项目,我们使用“rspec”gem 来检查期望。这包含在我们的 env.rb 中并在步骤定义中成功使用。
我现在尝试在 SitePrism 类中做出一些断言,但出现错误。你知道我如何使用这些expect()方法吗?我尝试在定义 SitePrism 类的 .rb 文件中使用require 'rspec'plus ,但仍然遇到相同的错误:include Rspec
expect(local_value).to eq(@previous_value)
=> Error: NoMethodError: undefined method `expect' for #<xxx_Object @loaded=false>
Run Code Online (Sandbox Code Playgroud)
谢谢你!
我想在多个场景的每个黄瓜功能文件中仅执行一次后台。我怎样才能在步骤文件中做到这一点?
特点:用户可以验证............
背景:给定输入特定逻辑的测试数据
场景:验证......1 当A1和B1然后C1时
场景:验证......2 当A2和B2然后C2时
场景:验证......2 当A3和B3然后C3时
您能否帮助打印在Web浏览器中生成的控制台日志,以了解Cucumber Capybara Test Automation中的任何错误?我正在使用PhantomJS webdriver如下:
Capybara :: Selenium :: Driver.new(app,:browser =>:phantomjs,desired_capabilities:{'phantomjs.cli.args'=> ['--ignore-ssl-errors = yes']
我想捕获Browser JS控制台日志并在我需要自动执行时打印它
我在SitePrism页面中定义了以下元素:
element :type, "select[id='type']"
elements :type_options, "select[id='type'] option"
Run Code Online (Sandbox Code Playgroud)
在我的黄瓜步骤定义中,我有以下代码,根据元素值从选择框中选择一个项目:
@app.new.type_options.each {|name| name.click if name.text.upcase == value.upcase}
Run Code Online (Sandbox Code Playgroud)
我真的不喜欢这个实现,但它在chrome中运行Capybara时效果很好但是当我无头运行它时失败了所以我认为必须有一个备用/更好的方法来选择下拉项目.
理想情况下,我希望能够做类似的事情@app.new_r.r_type.select 'value',但我无法解决如何在SitePrism中做到这一点.
所以,我的第一个问题是,是否有人可以推荐一种优雅的方式从下拉列表中选择一个基于SitePrism值的项目?
我的第二个问题是,任何想法为什么上面的代码在无头运行时失败了?
我正在使用SitePrism来测试我的Web应用程序.我有许多扩展的类,SitePrism::Page许多经常使用的HTML片段由匹配的类扩展表示SitePrism::Section
class Login < SitePrism::Section
element :username, "#username"
element :password, "#password"
element :sign_in, "button"
end
class Home < SitePrism::Page
section :login, Login, "div.login"
end
Run Code Online (Sandbox Code Playgroud)
问题是,我正在处理的应用程序基于CMS,其中可以通过基于预定义内容选择模板然后将任意数量的可用组件拖放到页面上来组装页面.
最初的开发人员创建了一个Page Object来镜像每个可用的Template.只要测试数量很少并且我们不得不在我们的功能文件中测试的页面变体太多,这就没问题了.
随着多个测试用例的增加,页面对象开始以惊人的速度增长.
虽然我们可以通过为CMS中可用的每个组件定义Sections并在页面对象中重用它们来轻松地减轻代码重复,但是很多属性很少被使用.
class BlogPost < SitePrism::Page
section :logo, MySite::Components::Logo, '.logo'
section :navigation, MySite::Components::Navigation, '.primary-navigation'
section :header, MySite::Components::BlogHeader, '.header'
section :introduction, MySite::Components::Text, '.text .intro'
# and so on, a lot of dynamic staff that could potentially be dropped onto the page …Run Code Online (Sandbox Code Playgroud) 通过使用site-prism gem进行集成测试,我可以通过引用id或title或link或xpath来查找页面元素,还是只能通过css进行搜索
我有以下代码:
element :header_upgrade_subscription, :xpath, "//a[text()='Upgrade subscription']"
element :header_change_subscription, :xpath, "//a[text()='Change subscription']"
if header_upgrade_subscription.visible?
change_subscription = header_upgrade_subscription
else
change_subscription = header_change_subscription
end
Run Code Online (Sandbox Code Playgroud)
问题是如果 header_upgrade_subscription 不存在,它只会失败:
Capybara::ElementNotFound Exception: Unable to find xpath "//a[text()='Upgrade subscription']"
Run Code Online (Sandbox Code Playgroud)
我知道在水豚,你可以这样做:
(rdb:1) first(:xpath, "//a[text()='Upgrade subscription']")
nil
Run Code Online (Sandbox Code Playgroud)
如果它不存在,它将返回 nil。我将如何对 SitePrism 元素使用“第一个”方法?这就是我得到的:
(rdb:1) first(header_upgrade_subscription)
Capybara::ElementNotFound Exception: Unable to find xpath "//a[text()='Upgrade subscription']"
Run Code Online (Sandbox Code Playgroud)
我喜欢使用“first”方法,因为如果元素不存在,它没有等待时间。
谢谢你的帮助!
我正在使用site_prism来实现水豚中的页面对象模型。看起来很有趣。
我如何指定一个选择器,例如“[data-id='x']”,其中x是整数?像这样的东西:
class Home < SitePrism::Page
set_url "http://www.example.com"
element :row, "[data-id='@id']"
end
Run Code Online (Sandbox Code Playgroud)
然后在我的测试中:
Then /^the home page should contain a row$/ do
@home.should have_row 1234
end
Run Code Online (Sandbox Code Playgroud)