用辣椒粉从表中的特定行中提取文本

发布于 2025-02-10 05:05:46 字数 3974 浏览 0 评论 0原文

朋友为我完成测试,我只需要从表的特定行中提取工具提示的文本即可。托马斯·沃尔波尔(Thomas Walpole)为我提供了很多帮助。现在,我可以阅读Excel电子表格,并将使用应用程序的每一行进行验证。

****** I read excel and get the first line *************
Spreadsheet.client_encoding = 'UTF-8'
  book = Spreadsheet.open('c:/temp/Pasta1.xls', "r")
  sheet = book.worksheet 0
  #sheet.each do |row|
  pp hydrometer = sheet.row(1)

****** reading the specific row of the table *************

I just need to extract this text save in a variable and validate with the hydrometer variable that stores the row of my excel sheet

expect(page).to have_css('tr.tvRow:nth-child(2) .tvCell:nth-child(6) img[tooltip="Invisível"]')

查看代码

<tr oncontextmenu="if(!this.cancelEvent) {sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','BtnDropDownRow#',1,'','','');return false;} delete this.cancelEvent;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','Select#',1,'','','');" onmousedown="if(event.ctrlKey) this.cancelEvent=true;" class="tvRow tvRowEven tvRoll tvRowSelected" style="cursor:pointer;">
   <td valign="center" align="left" class="tvCell">XWFMSLETMATRICOLA_E</td>
   <td valign="center" align="left" class="tvCell"> Nº Hidrômetro</td>
   <td align="left" class="tvCell" valign="center" nowrap=""></td>
   <td valign="center" align="left" class="tvCell"></td>
   <td align="left" width="1" class="tvCell" valign="center" tooltip="[AIMPMATRICOLA]">
      <button onclick="event.cancelBubble=true;sendEvent(0,event,this,searchImage(this),0,'','bdb','AUTOFILLBTN#',1,'','','','');" class="but butAct" tabindex="0" tooltip="Preenchimento automático ativado" type="BUTTON">
         <div><img src="r/std/icons/checkboxselected64.png" class="icon" draggable="false" align="absmiddle"></div>
      </button>
   </td>
   <td valign="center" align="center" class="tvCell"><img tooltip="Invisível" src="r/std/static/minus16.gif"></td>
   <td align="center" width="30" style="line-height:1px;padding:0px;" class="tvCell" valign="center">
      <div onclick="event.cancelBubble=true;sendEvent(0,event,this,searchImage(this),0,'','bdb','BtnDropDownRow#',1,'','','','');" class="but">
         <div><img src="r/std/icons/menu64.png" class="icon" draggable="false" align="absmiddle"></div>
      </div>
   </td>
</tr>
<tr oncontextmenu="if(!this.cancelEvent) {sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','BtnDropDownRow#',2,'','','');return false;} delete this.cancelEvent;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','Select#',2,'','','');" onmousedown="if(event.ctrlKey) this.cancelEvent=true;" class="tvRow tvRowOdd tvRoll" style="cursor:pointer;">
   <td valign="center" align="left" class="tvCell">XWFMSLETLETTURA_E</td>
   <td valign="center" align="left" class="tvCell"> Leitura</td>
   <td align="left" class="tvCell" valign="center" nowrap=""></td>
   <td valign="center" align="left" class="tvCell"></td>
   <td align="left" width="1" class="tvCell" valign="center" tooltip=""></td>
   <td valign="center" align="center" class="tvCell"><img tooltip="Invisível" src="r/std/static/minus16.gif"></td>
   <td align="center" width="30" style="line-height:1px;padding:0px;" class="tvCell" valign="center">
      <div onclick="event.cancelBubble=true;sendEvent(0,event,this,searchImage(this),0,'','bdb','BtnDropDownRow#',2,'','','','');" class="but">
         <div><img src="r/std/icons/menu64.png" class="icon" draggable="false" align="absmiddle"></div>
      </div>
   </td>
</tr>

enter image description hereFriends for me to finish my test and I just need to extract the text of the tooltip from the specific line of the table. Thomas Walpole has helped me a lot. Now I can read the excel spreadsheet and I will validate with each line of the application.

****** I read excel and get the first line *************
Spreadsheet.client_encoding = 'UTF-8'
  book = Spreadsheet.open('c:/temp/Pasta1.xls', "r")
  sheet = book.worksheet 0
  #sheet.each do |row|
  pp hydrometer = sheet.row(1)

****** reading the specific row of the table *************

I just need to extract this text save in a variable and validate with the hydrometer variable that stores the row of my excel sheet

expect(page).to have_css('tr.tvRow:nth-child(2) .tvCell:nth-child(6) img[tooltip="Invisível"]')

see the code

<tr oncontextmenu="if(!this.cancelEvent) {sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','BtnDropDownRow#',1,'','','');return false;} delete this.cancelEvent;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','Select#',1,'','','');" onmousedown="if(event.ctrlKey) this.cancelEvent=true;" class="tvRow tvRowEven tvRoll tvRowSelected" style="cursor:pointer;">
   <td valign="center" align="left" class="tvCell">XWFMSLETMATRICOLA_E</td>
   <td valign="center" align="left" class="tvCell"> Nº Hidrômetro</td>
   <td align="left" class="tvCell" valign="center" nowrap=""></td>
   <td valign="center" align="left" class="tvCell"></td>
   <td align="left" width="1" class="tvCell" valign="center" tooltip="[AIMPMATRICOLA]">
      <button onclick="event.cancelBubble=true;sendEvent(0,event,this,searchImage(this),0,'','bdb','AUTOFILLBTN#',1,'','','','');" class="but butAct" tabindex="0" tooltip="Preenchimento automático ativado" type="BUTTON">
         <div><img src="r/std/icons/checkboxselected64.png" class="icon" draggable="false" align="absmiddle"></div>
      </button>
   </td>
   <td valign="center" align="center" class="tvCell"><img tooltip="Invisível" src="r/std/static/minus16.gif"></td>
   <td align="center" width="30" style="line-height:1px;padding:0px;" class="tvCell" valign="center">
      <div onclick="event.cancelBubble=true;sendEvent(0,event,this,searchImage(this),0,'','bdb','BtnDropDownRow#',1,'','','','');" class="but">
         <div><img src="r/std/icons/menu64.png" class="icon" draggable="false" align="absmiddle"></div>
      </div>
   </td>
</tr>
<tr oncontextmenu="if(!this.cancelEvent) {sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','BtnDropDownRow#',2,'','','');return false;} delete this.cancelEvent;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','Select#',2,'','','');" onmousedown="if(event.ctrlKey) this.cancelEvent=true;" class="tvRow tvRowOdd tvRoll" style="cursor:pointer;">
   <td valign="center" align="left" class="tvCell">XWFMSLETLETTURA_E</td>
   <td valign="center" align="left" class="tvCell"> Leitura</td>
   <td align="left" class="tvCell" valign="center" nowrap=""></td>
   <td valign="center" align="left" class="tvCell"></td>
   <td align="left" width="1" class="tvCell" valign="center" tooltip=""></td>
   <td valign="center" align="center" class="tvCell"><img tooltip="Invisível" src="r/std/static/minus16.gif"></td>
   <td align="center" width="30" style="line-height:1px;padding:0px;" class="tvCell" valign="center">
      <div onclick="event.cancelBubble=true;sendEvent(0,event,this,searchImage(this),0,'','bdb','BtnDropDownRow#',2,'','','','');" class="but">
         <div><img src="r/std/icons/menu64.png" class="icon" draggable="false" align="absmiddle"></div>
      </div>
   </td>
</tr>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥繁 2025-02-17 05:05:46

如果比重计包含您要检查的文本,只是在您使用的CSS选择器中插值,

expect(page).to have_css("tr.tvRow:nth-child(2) .tvCell:nth-child(6) img[tooltip='#{hydrometer}']")

因为您经历了循环,您可能还想插入行号,但我不想插 则知道您会做什么变量

expect(page).to have_css("tr.tvRow:nth-child(#{row_number}) .tvCell:nth-child(6) img[tooltip='#{hydrometer}']")

知道如果您真的想获取特定行的工具提示文本,

text = find("tr.tvRow:nth-child(2) .tvCell:nth-child(6) img[tooltip]")[:tooltip] # get the tooltip attribute value from the 2nd row

,但要执行此操作,然后将其与其他字符串进行比较是不好的练习,并且会导致片状测试。最好做have_css上面显示的要好得多

If hydrometer contains the text you're checking for just interpolate it in the CSS selector you're using

expect(page).to have_css("tr.tvRow:nth-child(2) .tvCell:nth-child(6) img[tooltip='#{hydrometer}']")

Since your going through a loop you'd probably also want to interpolate the row number but I don't know what variable you have that in

expect(page).to have_css("tr.tvRow:nth-child(#{row_number}) .tvCell:nth-child(6) img[tooltip='#{hydrometer}']")

If you really want to get the tooltip text for a specific row you would do

text = find("tr.tvRow:nth-child(2) .tvCell:nth-child(6) img[tooltip]")[:tooltip] # get the tooltip attribute value from the 2nd row

but doing that and then comparing it to some other string is bad practice and will lead to flaky tests. It is much better to do the have_css shown above

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文