我需要验证一个标签" Annuitant"及其价值" RPD"是否存在使用父类

时间:2016-08-02 14:31:41

标签: ruby capybara

<div class="col-sm-3">
    <span>Annuitant:</span>
</div>

<div class="col-sm-3">
<span id="annuitant">
RPD                 
</span>
</div>

我之前使用的Xpath代码

  findXpath=page.find('label', text: workbook.cell(j,k), :match => :prefer_exact).path 

  splitXpath=(findXpath.split("/")) #splitting xpath

 ##Xpath manipulation to get the xpath of "RPD"
      count1=splitXpath.count
      value1=splitXpath.at(count1-3)
      value=splitXpath.at(count1-2)
      labelNum=value1.match(/(\d+)/)
      i=0
      elementNum=labelNum[1].to_i+1 

      for maxnum in 1..splitXpath.count-4
        elementXpath=elementXpath + "/" + splitXpath[maxnum]
      end

      elementXpath=elementXpath + "/div[" + elementNum.to_s + "]" + "/"+ value
      elementXpath=elementXpath + "/" + splitXpath.at(count1-1)
      finalElementXpath=elementXpath.sub("label","span")# obtained the xpath of RPD
      if (workbook.cell(j+1,k) == (find(:xpath, finalElementXpath).native.text)) # verifying the value RPD is present 

我可以使用父类并验证&#34; Annuitant&#34;存在并且还要检查Annuitant值是否为&#34; RPD&#34;。请帮我在ruby capybara中为此编写代码

2 个答案:

答案 0 :(得分:1)

使用page.assert_selector('#annuitant', :text => 'RPD', :visible => true) 检查选择器是否包含所需的文本。见下文:

var wiredep = require('wiredep')(
    {
      directory: 'static/bower_components', // default: '.bowerrc'.directory || bower_components
    }).stream;
gulp.task('scripts',function(){

    return gulp
        .src('index.html') //I don´t really know what to put in the src
        .pipe(wiredep())
        .pipe($.inject(gulp.src("More  JS files if wire dep can´t handle them")))
        .pipe(minify())
        .pipe(gulp.dest('static/dist/src/app.min.js'));
});

答案 1 :(得分:0)

您可以通过在元素上调用或使用内部(元素)将Capybara的查找器/匹配器限定为任何元素......

在这种情况下,您希望将范围扩展到html文档中至少一个级别,以便您感兴趣的两个元素都包含在您确定范围内的元素中。班级&#39; col-sm-3&#39;这将是一个糟糕的选择,因为它不会是这些元素的独特之处。另外一件事是你的检查需要多严格,你真的需要检查元素的结构,还是只需要验证文本在页面上彼此相邻。如果后者像

那样
element = find('<selector for parent/grandparent of both elements>') # could also just be `page` if the text is unique
expect(element).to have_text('Annuitant: RPD')

如果你确实需要验证结构,那么事情会变得更复杂,你需要使用XPath

expect(element).to have_selector(:xpath, './/div[./span[text()="Annuitant:"]]/following-sibling::div[1][./span[normalize-space(text())="RPD"]]')