Ich habe mich nur gefragt, ob Sie hier zeigen könnten, wo das Problem liegt, ob es Behath, der CSS-Selektor oder Sahi-Treiber ist.Machen Sie CSS-Selektor (First-Kind) in Behat 3 mit Sahi-Treiber
Wir haben gerade auf Behat 3 aktualisiert und verwenden Sahi Driver (neueste Open-Source-Version). Wir haben festgestellt, dass jeder Behat-Test, der das Pseudo-Element first-child
verwendet, nun zu brechen scheint.
Beispiel:
Schritt:
And I follow "#the-list tr:first-child .row-title"
(die auf ihn ein Ankerelement mit der Klasse row-Titel enthält, siehe HTML)
Fehler:
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 (überschreiben wir mit unseren alten Behat verwendet, verließen wir diese Datei 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();
}
}
Wenn die CSS-Selektor in der Konsole Chrome mit jquery es das entsprechende Element auswählt. Ich ging durch den Code und schaute auf die css -> xpath Übersetzungen und validierte dann den xpath gegen den HTML, der auf der Website produziert wird, die wir testen, und es scheint auch gültig zu sein. Der CSS-Selektor funktioniert auch mit dem Goutte-Treiber.
generiert 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 ')]
Wenn ich ändern die CSS:
Schritt:
And I follow "#the-list tr .row-title"
Es funktioniert, weil ich es einfach glauben, dass die erste tr aus einer Liste von ihnen nimmt Wie auch immer, wir wollen natürlich das erste Kind benutzen können.
Danke für Ihre Hilfe!
[Dieses GitHub Problem] (https://github.com/Behat/Mink/issues/268) scheint über die gleiche Sache zu sprechen. Hilft es überhaupt? –
Das Problem https://github.com/symfony/symfony/issues/11803 ist relevant, aber es macht keinen Sinn, weil der von Symfony erzeugte Xpath korrekt ist. – sugarwaffle
Haben Sie versucht "# the-list tr: nth-child (1) .row-title"? –