空手道-如何匹配深度放置的span标签中的测试

问题描述 投票:1回答:1

我正在使用空手道,并且正在寻找一种方法来在深度跨度中匹配值。

我有这种情况:

...
<form action="#">
  <div class="row">
    <div class="col-lg-12">
      <div class="card shadow mb-4">
         <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
         <div class="card-body">
            <p>...</p>
            <div class="form-group " style="display: grid; grid-template-rows: auto auto;">
               <span>
                   <label for="title">Title</label>
                   <input name="title" id="title" class="form-control" placeholder="e.g. My MacBook Key" value="">
               </span>
               <span class="invalid-feedback">Title is required</span>
            </div>
            <div class="form-group " style="display: grid; grid-template-rows: auto auto;">
               <span>
                   <label for="key">Key</label>
                   <textarea name="key" id="key" class="form-control" rows="12" placeholder="Typically starts with &quot;ssh-rsa&quot; or &quot;ssh-ed25519&quot;"></textarea> 
               </span>
               <span class="invalid-feedback">Key is required</span>

我需要检查最后一个跨度的值(使用匹配)-最后一行(如果跨度中存在“需要键”)。

我尝试了一些代码变体,但未成功。例如:

* match text('form/div/div/div/div:2/div:2/span:2') == 'Key is required'

* match text('{span:2}.invalid-feedback') == 'Key is required'

任何不使用完整xpath的想法如何解决?

谢谢。

automated-tests karate
1个回答
0
投票

有一个非常简单的方法:

* def messages = scriptAll('.invalid-feedback', '_.innerHTML')
* match messages[1] == 'Key is required'
© www.soinside.com 2019 - 2024. All rights reserved.