本文介绍了KarateDSL UI 测试 - 友好定位器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照我最近提出的另一个问题,你们能帮我找出我编写下方"友好定位器的方式有什么问题吗?提前致谢!

场景:获取 UI - 下载给定 url 'https://test01/v1/doc/env/和标题 headers1当方法得到然后状态 200* def env = response.url给定驱动程序环境然后点击('{button}Proceed')然后点击('{span}Start')然后点击('{span}必需 - GSA)然后点击('{span}Required - GSB')然后点击('{span}Required - GSC')然后点击('{span}Required - GSD')然后点击('{span}Required - GSE')然后点击('{span}Required - GSF')然后点击('{span}Required - GSG')然后点击('{span}Required - GSH')* 下面('{}必需 - GSH').input('空手道 dsl')

我有一个想要输入值的文本区域,但下方"友好的定位器对我不起作用.

javascript 评估失败:below('{}Required - GSH').input('karate dsl'),无法找到:{}Required - GSH, BELOW, INPUT

更新:这是 HTML 的片段:

我需要先选择单选按钮,以便启用/需要文本区域

<div class="doc-tab radio-tab 签名-required use-olive" id="tab-c6cfbed8-694a-4004-9294-cc0195bab1d0" data-id="c6cfbed8-694a-4004-9294-cc0195bab1d0" data-type="Radio" data-label="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd778:6"style>7f.;<div class="rb"><input type="radio" id="tab-form-element-c6cfbed8-694a-4004-9294-cc0195bab1d0" aria-invalid="false" name="FINQ1_66c4593b-7d61-43b5-985f-a22e04b1d07e-b682-cd770a1bfef8" class="rb_input main-radio-tab-input" value="tab.id" data-qa="radio-tab-c6cfbed8-694a-4004-9294-cc0195bab1d0"><label for="tab-form-element-c6cfbed8-694a-4004-9294-cc0195bab1d0" class="rb_label" data-qa="radio-tab-label-c6cfbed8-694a-4004-9294-cc0195bab1d0"<span class="tab-label" style="white-space: nowrap; width: auto;">必需 - GSG</span></label>

<div class="doc-tab radio-tab 签名签名-required use-olive" id="tab-d05ca57f-06a7-4f2f-a297-da01dc93290a" data-id="d05ca57f-06a7-4f2f-a297-da01adc93290data-type="Radio" data-label="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" style="left:61.44">px.top8:<div class="rb"><input type="radio" id="tab-form-element-d05ca57f-06a7-4f2f-a297-da01dc93290a" aria-invalid="false" name="FINQ1_66c4593b-7d61-43b5-985f-a229e4b904d-b682-cd770a1bfef8" class="rb_input main-radio-tab-input" value="tab.id" checked="" data-qa="radio-tab-d05ca57f-06a7-4f2f-a297-da01dc93290a"><label for="tab-form-element-d05ca57f-06a7-4f2f-a297-da01dc93290a" class="rb_label" data-qa="radio-tab-label-d05ca57f-06a7-4f2f-a297-gta01dc93290a"<span class="tab-label" style="white-space: nowrap; width: auto;">必需 - GSH</span></label>

<div class="doc-tab text-tab signature-required has-tab-error" id="tab-3c020567-3db9-449b-bed5-c44b32a236fa" data-id="3c020567-3db9-449b-bed5-c44b32a236fa" data-type="Text" data-label="FINQues1_1_comments_Text_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8.5"left;gt;504"

这是我想使用下方"友好定位器定位的文本区域.

<div class="doc-tab text-tab signing-required has-tab-error" id="tab-3c020567-3db9-449b-bed5-c44b32a236fa" data-id="3c020567-3db9-449b-bed5-c44b32a236fa" data-type="Text" data-label="myQues1_1_comments_Text_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-7291-4ee8-7291-4ee8-7291-4ee8-7291-4ee8-7291-82-left-style:cd706:c506:c5082018205000><div id="tab-sizer-3c020567-3db9-449b-bed5-c44b32a236fa" class="tab-form-element signature-required tab-sizer multiline" style="width: 676px; font-family: "Lucida Console",&quot;Andale Mono&quot;, Monaco, monospace; font-size: 12.16px; letter-spacing: 0.14px; color: rgb(0, 0, 0); line-height:14px; text-align: left; height: auto; min-height: auto; white-space: pre-wrap;"></div><textarea id="tab-form-element-3c020567-3db9-449b-bed5-c44b32a236fa" aria-invalid="false" title="" data-qa="text-multi-input-tab-3c020567-3db9-449b-bed5-c44b32a236fa" class="main-text-tab-input tab-form-element 签名-required " maxlength="450" style="width: 676px; font-family: &quot;Lucida Console&quot;, &quot;Andale Mono&quot;, Monaco, monospace; letter-spacing: 0.14px; color: rgb(0, 0, 0); line-height: 14px; text-align: left; font-size: 12.16px !important; 高度:98px;"></textarea><label for="tab-form-element-3c020567-3db9-449b-bed5-c44b32a236fa" class="tab-label" style="white-space: nowrap; width: auto;">必需<span class="tab-error-message" aria-live="polite"></span></label>

解决方案

猜一猜,试试这个:

* below('{}必需 - GSH').find('textarea').input('karate dsl')

如果不是默认"input,这是必需的,请参阅文档:https://github.com/intuit/karate/tree/master/karate-core#friendly-locators

以下内容适用于 0.9.6.RC2 版中的用例

 * def list = locateAll('div[data-label]')* def condition = function(x){ var label = x.script("_.getAttribute('data-label')");返回 label.startsWith('myQues1_2') }* def found = karate.filter(list, condition)* found[0].locate('textarea').input('karate dsl')

这有点棘手,但请参阅每个 API 的文档以了解发生了什么.

并且我已经打开了一个功能请求以使其更容易,请随时在那里发表评论或提出更多更改:https://github.com/intuit/karate/issues/1123

Following the other question that I raised recently, could you guys help spot what is wrong with the way how I wrote the "below" friendly locator? Thank you in advance!

Scenario: Get UI - Download
   Given url 'https://test01/v1/doc/env/
   And headers headers1
   When method get
   Then status 200
   * def env = response.url

   Given driver env
   And click('{button}Proceed')
   And click('{span}Start')
   And click('{span}Required - GSA)
   And click('{span}Required - GSB')
   And click('{span}Required - GSC')
   And click('{span}Required - GSD')
   And click('{span}Required - GSE')
   And click('{span}Required - GSF')
   And click('{span}Required - GSG')
   And click('{span}Required - GSH')
   * below('{}Required - GSH').input('karate dsl')

I have a textarea that I would like values to be entered, but the friendly locator "below" is not working for me.

javascript evaluation failed: below('{}Required - GSH').input('karate dsl'), unable to find: {}Required - GSH, BELOW, INPUT

Update:Here's the snippet of the HTML:

Radio button that I need to select first, so the text area will be enabled/required

<div class="doc-tab radio-tab  signing-required       use-olive" id="tab-c6cfbed8-694a-4004-9294-cc0195bab1d0" data-id="c6cfbed8-694a-4004-9294-cc0195bab1d0" data-type="Radio" data-label="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" style="left:61.44px; top:421.76px;">

    <div class="rb">
      <input type="radio" id="tab-form-element-c6cfbed8-694a-4004-9294-cc0195bab1d0" aria-invalid="false" name="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" class="rb_input main-radio-tab-input" value="tab.id" data-qa="radio-tab-c6cfbed8-694a-4004-9294-cc0195bab1d0">
      <label for="tab-form-element-c6cfbed8-694a-4004-9294-cc0195bab1d0" class="rb_label" data-qa="radio-tab-label-c6cfbed8-694a-4004-9294-cc0195bab1d0"><span class="tab-label" style="white-space: nowrap; width: auto;">Required - GSG</span></label>
    </div>
</div>

<div class="doc-tab radio-tab signed signing-required       use-olive" id="tab-d05ca57f-06a7-4f2f-a297-da01dc93290a" data-id="d05ca57f-06a7-4f2f-a297-da01dc93290a" data-type="Radio" data-label="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" style="left:61.44px; top:446.08px;">

    <div class="rb">
      <input type="radio" id="tab-form-element-d05ca57f-06a7-4f2f-a297-da01dc93290a" aria-invalid="false" name="FINQ1_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" class="rb_input main-radio-tab-input" value="tab.id" checked="" data-qa="radio-tab-d05ca57f-06a7-4f2f-a297-da01dc93290a">
      <label for="tab-form-element-d05ca57f-06a7-4f2f-a297-da01dc93290a" class="rb_label" data-qa="radio-tab-label-d05ca57f-06a7-4f2f-a297-da01dc93290a"><span class="tab-label" style="white-space: nowrap; width: auto;">Required - GSH</span></label>
    </div>
</div>

<div class="doc-tab text-tab  signing-required has-tab-error" id="tab-3c020567-3db9-449b-bed5-c44b32a236fa" data-id="3c020567-3db9-449b-bed5-c44b32a236fa" data-type="Text" data-label="FINQues1_1_comments_Text_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" style="left:56.32px; top:503.04px;">

Here's the text area that I would like to locate using the "below" friendly locator.

<div class="doc-tab text-tab  signing-required         has-tab-error" id="tab-3c020567-3db9-449b-bed5-c44b32a236fa" data-id="3c020567-3db9-449b-bed5-c44b32a236fa" data-type="Text" data-label="myQues1_1_comments_Text_66c4593b-7d61-43b5-985f-a22e0909d3dd_b6c1ea40-7291-4ee8-b682-cd770a1bfef8" style="left:56.32px; top:503.04px;">
 
    <div id="tab-sizer-3c020567-3db9-449b-bed5-c44b32a236fa" class="tab-form-element signing-required tab-sizer multiline" style="width: 676px; font-family: &quot;Lucida Console&quot;, &quot;Andale Mono&quot;, Monaco, monospace; font-size: 12.16px; letter-spacing: 0.14px; color: rgb(0, 0, 0); line-height: 14px; text-align: left; height: auto; min-height: auto; white-space: pre-wrap;"></div>
 
    <textarea id="tab-form-element-3c020567-3db9-449b-bed5-c44b32a236fa" aria-invalid="false" title="" data-qa="text-multi-input-tab-3c020567-3db9-449b-bed5-c44b32a236fa" class="main-text-tab-input tab-form-element signing-required " maxlength="450" style="width: 676px; font-family: &quot;Lucida Console&quot;, &quot;Andale Mono&quot;, Monaco, monospace; letter-spacing: 0.14px; color: rgb(0, 0, 0); line-height: 14px; text-align: left; font-size: 12.16px !important; height: 98px;"></textarea>
 
    <label for="tab-form-element-3c020567-3db9-449b-bed5-c44b32a236fa" class="tab-label" style="white-space: nowrap; width: auto;">Required<span class="tab-error-message" aria-live="polite"></span></label>
</div>

解决方案

Just a guess, try this:

* below('{}Required - GSH').find('textarea').input('karate dsl')

This is needed if not the "default" input, see docs: https://github.com/intuit/karate/tree/master/karate-core#friendly-locators

EDIT: the following will work for your use-case in version 0.9.6.RC2

  * def list = locateAll('div[data-label]')
  * def condition = function(x){ var label = x.script("_.getAttribute('data-label')"); return label.startsWith('myQues1_2') }
  * def found = karate.filter(list, condition)
  * found[0].locate('textarea').input('karate dsl')

It is a little tricky, but please refer to the docs for each API to understand what is going on.

And I have opened a feature request to make this even easier, feel free to comment there or propose more changes: https://github.com/intuit/karate/issues/1123

这篇关于KarateDSL UI 测试 - 友好定位器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:19