Mi stavo chiedendo se potresti indicare dove si trova il problema, se è Behat, il selettore CSS o il Sahi Driver.Imposta CSS Selector (first-child) funziona in Behat 3 con Sahi Driver
Abbiamo appena aggiornato a Behat 3 e stiamo usando Sahi Driver (la più recente versione open source). Abbiamo scoperto che qualsiasi test Behat che utilizza lo pseudo-elemento first-child
sembra ora interrotto.
Esempio:
Passo:
And I follow "#the-list tr:first-child .row-title"
(che contiene un elemento di ancoraggio con la classe row-titolo su di essa, vedi HTML)
Errore:
Link with id|title|alt|text "#the-list tr:first-child .row-title" not found. (Behat\Mink\Exception\ElementNotFoundException)
HTML:
<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 (Override abbiamo usato con il nostro vecchio Behat, abbiamo lasciato questo file in)
/**
* 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();
}
}
Quando si utilizza il selettore CSS nella console Chrome con jQuery seleziona l'elemento appropriato. Ho passato il codice e ho guardato le traduzioni css -> xpath e poi ho convalidato xpath con l'html prodotto sul sito che stiamo testando e sembra essere valido. Il selettore css funziona anche con il driver Goutte.
XPath Generated:
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 ')]
Quando cambio il CSS a:
Passo:
And I follow "#the-list tr .row-title"
Funziona perché credo che solo raccoglie il primo tr da un elenco di loro comunque, ma vogliamo essere in grado di usare il primo figlio, naturalmente.
Grazie per il vostro aiuto!
[Questo problema github] (https://github.com/Behat/Mink/issues/268) sembra parlare della stessa cosa. Aiuta affatto? –
Il problema https://github.com/symfony/symfony/issues/11803 è pertinente, ma non ha senso perché l'Xpath generato da Symfony sembra corretto. – sugarwaffle
Hai provato "# the-list tr: nth-child (1) .row-title"? –