Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

api - KarateDSL UI Testing - Friendly Locators not working

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>

question from:https://stackoverflow.com/questions/65839853/does-karate-ui-framework-support-siblings-or-following

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...