2014-11-26 11 views
9

के साथ बेथ 3 में सीएसएस चयनकर्ता (प्रथम-बच्चा) काम करें, मैं बस सोच रहा था कि समस्या कहां है, अगर यह बीट, सीएसएस चयनकर्ता, या साही चालक है।सही चालक

हमने अभी बेथ 3 में अपग्रेड किया है और साही ड्राइवर (सबसे हालिया ओपन सोर्स संस्करण) का उपयोग कर रहे हैं। हमने पाया है कि छद्म-तत्व first-child का उपयोग करने वाले किसी भी बीट परीक्षण को तोड़ना प्रतीत होता है।

उदाहरण:

कदम:

And I follow "#the-list tr:first-child .row-title" 

(जो उस पर वर्ग पंक्ति-शीर्षक के साथ एक एंकर तत्व होता है, देखते हैं एचटीएमएल)

त्रुटि:

Link with id|title|alt|text "#the-list tr:first-child .row-title" not found. (Behat\Mink\Exception\ElementNotFoundException)

एचटीएमएल:

<tbody id="the-list"> 
    <tr id="post-162382" class="post-162382 type-post status-publish format-standard hentry category-uncategorized alternate iedit author-other level-0"> 
     <th class="check-column" scope="row"></th> 
     <td class="post-title page-title column-title"> 
      <strong> 
       <a class="row-title" title="Edit “Post Title”" href="https://domain.com"></a> 
      </strong> 
      <div class="locked-info"></div> 
      <div class="row-actions"></div> 
      <div id="inline_162382" class="hidden"></div> 
     </td> 

CSSSelector.php क्रोम कंसोल jQuery के साथ यह उचित तत्व का चयन करता है में सीएसएस चयनकर्ता का उपयोग करते समय

/** 
* Makes all of the form field related steps allow CSS selectors. 
*/ 
class CSSSelectorContext extends MinkContext 
{ 
    /** 
    * Finds an element via CSS or fails with a given error 
    * 
    * @param $element string A CSS selector string 
    * @param $error Exception An error to throw in case the element can not be found 
    * @return object   An Element object 
    */ 
    protected function findOrFail($element, $error){ 
     $element = $this->getSession()->getPage()->find('css', $element); 
     if (!isset($element)){  
      throw $error; 
     } 
     return $element; 
    } 

    public function clickLink($link) { 
     try { 
      parent::clickLink($link); 
      return; 
     }catch (Exception $error){ 
      $link = $this->fixStepArgument($link); 
      $link = $this->findOrFail($link, $error); 
      $link->press(); 
     } 
    } 

(ओवरराइड हम हमारे पुराने Behat के साथ प्रयोग किया है, हम में इस फ़ाइल को छोड़ दिया)। मैं कोड के माध्यम से चला गया और सीएसएस -> xpath अनुवादों को देखा और फिर उस साइट पर उत्पादित एचटीएमएल के खिलाफ एक्सपैथ को सत्यापित किया जिसे हम परीक्षण कर रहे हैं और यह भी मान्य है। सीएसएस चयनकर्ता गौटे चालक के साथ भी काम करता है।

जनरेट किया XPath:

find(function(){ 
     var count = 0; 
     while (_sahi._byXPath("("+"\/\/html\/descendant-or-self::*[@id = 'the-list']\/descendant-or-self::*\/*[name() = 'tr' and (position() = 1)]\/descendant-or-self::*\/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' row-title ')]"+")["+(count+1)+"]")) count++; 
     return count; 
    })() 

descendant-or-self::*[@id = 'the-list']/descendant-or-self::*/*[name() = 'tr' and (position() = 1)]/descendant-or-self::*/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' row-title ')] 

//html/descendant-or-self::*[@id = 'the-list']/descendant-or-self::*/*[name() = 'tr' and (position() = 1)]/descendant-or-self::*/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' row-title ')] 

जब मैं करने के लिए सीएसएस बदलने के लिए:

कदम:

And I follow "#the-list tr .row-title" 

यह काम करता है क्योंकि मेरा मानना ​​है कि यह सिर्फ उनमें से एक सूची से पहले टीआर उठाता वैसे भी, लेकिन हम निश्चित रूप से पहले बच्चे का उपयोग करने में सक्षम होना चाहते हैं।

आपकी मदद के लिए धन्यवाद!

+1

[यह जिथब मुद्दा] (https://github.com/Behat/Mink/issues/268) एक ही चीज़ के बारे में बात कर रहा है। क्या यह बिल्कुल मदद करता है? –

+0

समस्या https://github.com/symfony/symfony/issues/11803 प्रासंगिक है, लेकिन यह समझ में नहीं आता है क्योंकि सिम्फनी द्वारा उत्पन्न एक्सपैथ सही लगता है। – sugarwaffle

+0

क्या आपने "# the-list tr: nth-child (1) .row-title" की कोशिश की है? –

उत्तर

0

पार्टी के लिए देर से आने के लिए क्षमा करें

यहां आपकी समस्या तथ्य यह है कि minks खुद कदम "मैं पालन"/"clickLink" निम्न को स्वीकार नहीं करता है:

  1. "#" रों आईडी के
  2. आईडी, टेक्स्ट, शीर्षक या वैकल्पिक मान के अलावा कुछ भी।

मैं "अनुसरण करें", कुछ इस तरह के बजाय कदम एक "पर क्लिक करें" उपयोग करने का सुझाव:

/** 
    * @Then /^(?:|I)click (?:|on)(?:|the)"([^"]*)"(?:|.*)$/ 
    */ 
    public 
    function iClickOn($arg1) 
    { 
     $findName = $this->getSession()->getPage()->find("css", $arg1); 
     if (!$findName) { 
      throw new Exception($arg1 . " could not be found"); 
     } else { 
      $findName->click(); 
     } 
    } 

आप सीएसएस का उपयोग कर रहे यहीं है, जो इस के लिए अनुमति देगा लिखे जाने की :

Then I click on the "#the-list tr:first-child .row-title" link

यह एक गलती मैं भी बनाया है, और इस समाधान हम तो पर फैसला किया है, और हम वापस देखने के लिए नहीं था।

संबंधित मुद्दे