Zastanawiałem się, czy mógłbyś wskazać, gdzie jest problem, czy to Behat, selektor CSS, czy Sahi Driver.Ustaw CSS Selector (first-child) w Behat 3 z Sahi Driver
Właśnie zaktualizowaliśmy system do wersji Behat 3 i używamy sterownika Sahi (najnowsza wersja open source). Odkryliśmy, że każdy test Behat, który używa pseudoelementu first-child
, wydaje się teraz łamać.
przykład:
krok:
And I follow "#the-list tr:first-child .row-title"
(który zawiera element kotwiący z klasy row-tytuł na niej zobaczyć HTML)
błędu:
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 (przesłanianie użyliśmy z naszym starym Behat, zostawiliśmy ten plik)
/**
* 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();
}
}
Przy użyciu selektora CSS w konsoli Chrome z jQuery to wybiera odpowiedni element. Przeszedłem przez kod i spojrzałem na tłumaczenia css -> xpath, a następnie zweryfikowałem xpath względem html, który jest produkowany w testowanej przez nas witrynie i również wydaje się być prawidłowy. Selektor css działa również ze sterownikiem Goutte.
Generated 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 ')]
Kiedy zmienić CSS:
krok:
And I follow "#the-list tr .row-title"
To działa, ponieważ wierzę, że właśnie wybiera pierwsze tr z listy nich tak czy owak, ale oczywiście chcemy mieć możliwość korzystania z pierwszego dziecka.
Dzięki za pomoc!
[Ten problem z githubem] (https://github.com/Behat/Mink/issues/268) wydaje się mówić o tym samym. Czy to w ogóle pomaga? –
Problem https://github.com/symfony/symfony/issues/11803 jest istotny, ale nie ma to sensu, ponieważ ścieżka X wygenerowana przez Symfony wydaje się być poprawna. – sugarwaffle
Czy próbowałeś "# the-list tr: nth-child (1) .row-title"? –