在 Cucumber/Watir-webdriver/page-object 环境中,我需要验证常见页眉和页脚链接的存在和功能。虽然这些都应该是相同的并且有效,但我想将它们包含在所有相关页面上。
我正在尝试保持 DRY 编码,并希望最大限度地减少识别 Web 应用程序上共享的页眉/页脚元素所需的次数。
我想我可以通过在 support/ 文件夹中包含一些“common_links.rb”来做到这一点:
module CommonLinks
include PageObject
# Header links
link(:log_out_header_link, :text => "Log Out")
link(:logo, :id => "logo")
#Logged in nav links
div(:nav, :id => "globalnav_wrapper")
nav.link(:nav_activities, :href => "/activities/")
# Footer Links
link(:contact_us_footer, :text => "CONTACT US")
# Social Media Links
link(:social_twitter, :id => "soc_twitter")
link(:social_facebook, :id => "soc_fb")
link(:social_pinterest, :id => "soc_pin")
link(:social_google_plus, :id => "soc_gplus")
link(:social_youtube, :id => "soc_yt")
end
Run Code Online (Sandbox Code Playgroud)
我正在尝试将上述内容包含在support/pages/activities_page.rb. 当我尝试加载调用此功能的黄瓜功能时,出现以下错误:
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/page-object-0.8.6.1/lib/page-object/accessors.rb:1110:in `block (2 levels) …Run Code Online (Sandbox Code Playgroud) 我从一年开始使用黄瓜,而且几周之后我就在它中添加了page-object-gem.当我执行测试时,我收到消息:
DEPRECATION WARNING
您正在commentPage.rb中调用一个名为checkbox的方法:23:在`delete in delete_comment'中.
此方法在页面对象中不存在,因此它将传递给驱动程序.
此功能将在不久的将来删除.
请更改您的代码以调用正确的页面对象方法.
(我对其他案例也有同样的看法,但这个"琐碎"的例子应该更容易解释)
我试图避免这种情况,但这看起来很复杂.
对于测试,我正在检查一个页面,其中有一个表格.每行显示一行,我需要检查特定行的复选框.
我在pageObject中的代码:
table(:comment_list, :class => 'comments')
button(:delete, :text => "Delete")
def delete_comment (text)
self.comment_list_element.each do |row|
if row.text.include? "#{text}"
row.checkbox.set
self.delete
return true
end
end
false
end
Run Code Online (Sandbox Code Playgroud)
我是否需要对我的桌子进行预处理以在测试期间使用它?
在我添加测试的项目中,我有一些复杂的元素“获取”。
我的 textarea 的 html :
<div class="quote">
<div class="clearfix">
<div class="icon"></div>
<div class="text">
<span class="yui3-widget yui3-inputwidget yui3-textareawidget yui3-textareawidget-focused" style="">
<span class="yui3-textareawidget-content">
<textarea name="" placeholder=""></textarea>
</span>
</span>
</div>
<div class="author">
(...) other text_field
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
目前,我使用这一行来设置值
@browser.element(:css => ".quote textarea").send_keys "test"
Run Code Online (Sandbox Code Playgroud)
在 PageObject 中,我应该声明元素并使用它:
# declaration at the top
element(:quote_text, :css => ".quote textarea")
# use it where I need
self.quote_text = "text"
Run Code Online (Sandbox Code Playgroud)
但是当我使用时出现此错误:
undefined method `quote_text=' for #<PublishPage:0x33843c0> (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
我正在尝试使用Cheezy的页面对象gem来保持一致.但是我无法找到如何向下钻取这样的元素.这里的情况是,所有相同的标签会有多个链接,因此您必须从可识别的东西向下钻取.
@browser.p(:text => /#{app_name}/i).link(:text => 'Add').click
Run Code Online (Sandbox Code Playgroud)
我正在寻找的代码是这样的,点击段落内的链接,但它不起作用.
p(:pgraph, id: => 'some-pgraph')
link(:lnk, text: => 'add')
self.pgraph.lnk
Run Code Online (Sandbox Code Playgroud)
有没有办法用页面对象做到这一点?
谢谢,亚当
我试图理解为什么这两个东西会返回不同的值.
值是a string,而field是a text_field.
def populate_text(field, value)
self.send "user_name=", value
end
# => nil
def populate_text(value)
self.user_name = value
end
# => "value"
Run Code Online (Sandbox Code Playgroud)
为什么self和send具有不同的返回值?
如果有帮助,该类包括PageObject.
如何使用page-object从选择列表中选择随机选项?我用:
def select_random_member
lstMembers = self.sltMembers_element.options.map(&:index) # getting all members from select list
lastMember = lstMembers.last
rnmMember = rand(0..lastMember)
self.sltMembers_element.options[rnmMember].click
end
Run Code Online (Sandbox Code Playgroud)
我看到了获取每个选项的DEPRECATION WARNING lstMembers = self.sltEndDate_element.options.map(&:index)
*** DEPRECATION WARNING
*** You are calling a method named index at D:/members/lib/pages/members_page.rb:58:in `map'.
*** This method does not exist in page-object so it is being passed to the driver.
*** This feature will be removed in the near future.
*** Please change your code to call the correct page-object method.
*** If you …Run Code Online (Sandbox Code Playgroud) 我正在尝试找到一组复选框,但我需要在字段集中找到它们.html就像这样(它是一个gwt应用程序,因此产生了大量的东西:
<div id="UpdateUserView-RolesColumn">
<fieldset style="">
<legend>Primary Role</legend>
<select class="gwt-ListBox">
<option value="ROLE_GENERAL_USER">ROLE_GENERAL_USER</option>
<option value="ROLE_ADMIN">ROLE_ADMIN</option>
</select>
</fieldset>
<fieldset style="" class="createUser-otherRolesFieldset">
<legend>Other Roles / Permissions</legend>
<div style="overflow: auto; position: relative; zoom: 1; height: 250px;">
<div style="position: relative; zoom: 1;">
<div>
<span class="gwt-CheckBox">
<input type="checkbox" value="on" id="gwt-uid-760" tabindex="0" checked="">
<label for="gwt-uid-760">ROLE_BLAH1_USER</label>
</span>
<span class="gwt-CheckBox">
<input type="checkbox" value="on" id="gwt-uid-761" tabindex="0" checked="">
<label for="gwt-uid-761">ROLE_BLAH2_USER</label>
</span>
<span class="gwt-CheckBox">
<input type="checkbox" value="on" id="gwt-uid-762" tabindex="0" checked="">
<label for="gwt-uid-762">ROLE_BLAH3_USER</label>
</span>
<span class="gwt-CheckBox">
<input type="checkbox" value="on" id="gwt-uid-763" tabindex="0" checked="">
<label for="gwt-uid-763">ROLE_BLAH4_USER</label> …Run Code Online (Sandbox Code Playgroud) 如何在页面对象类中使用Rspec期望.我需要断言元素.目前我正在使用xpath,其他定位器来检查元素是否存在.我知道使用它是步骤定义.但我需要在课堂上.
class AssertTest
include PageObject
span(:success, text: "Message added successfully")
def assert_element
success_element.when_present (or) success?
# I need to use Rspec expectations instead
# continue...
end
end
Run Code Online (Sandbox Code Playgroud)
在步骤定义中,我可以像以下一样使用它:
@current_page.text.should include "message"
Run Code Online (Sandbox Code Playgroud) 所以,我有一个包含多行和多列的表.
<table>
<tr>
<th>Employee Name</th>
<th>Reg Hours</th>
<th>OT Hours</th>
</tr>
<tr>
<td>Employee 1</td>
<td>10</td>
<td>20</td>
</tr>
<tr>
<td>Employee 2</td>
<td>5</td>
<td>10</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
还有另一张表:
<table>
<tr>
<th>Employee Name</th>
<th>Revenue</th>
</tr>
<td>Employee 2</td>
<td>$10</td>
</tr>
<tr>
<td>Employee 1</td>
<td>$50</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
请注意,员工订单可能在表之间是随机的.
我如何使用nokogiri创建一个以每个员工为对象的json文件,以及他们的总小时数和收入?
目前,我只能使用一些xpath获取单个表格单元格.例如:
puts page.xpath(".//*[@id='UC255_tblSummary']/tbody/tr[2]/td[1]/text()").inner_text
Run Code Online (Sandbox Code Playgroud)
编辑:
使用页面对象gem和来自@Dave_McNulla的链接,我尝试了这段代码只是为了看看我得到了什么:
class MyPage
include PageObject
table(:report, :id => 'UC255_tblSummary')
def get_some_information
report_element[1][2].text
end
end
puts get_some_information
Run Code Online (Sandbox Code Playgroud)
然而,没有任何东西被归还.
数据:https://gist.github.com/anonymous/d8cc0524160d7d03d37b
小时表有一个副本.第一个很好.需要的另一个表是附件收入表.(我还需要激活表,但我会尝试将合并小时和附件收入表的代码合并.