По сути, когда мы хотим иметь дело с ajax, нам нужно добавить несколько инструкций по сну, и мне это очень не нравится, даже если конечный пользователь на самом деле чего-то «ждет», я думаю, это должно быть очевидно, поскольку основы не -ajax запросы.
Мне действительно интересно, почему его еще не существует, и я написал несколько адаптаций и буду признателен за ваши отзывы перед возможным пиаром:
https://gist.github.com/lenybernard/6f6 ... a2594f923b
diff --git a/src/Behat/MinkExtension/Context/MinkContext.php b/src/Behat/MinkExtension/Context/MinkContext.php
index 90ea038..8d6537b 100644
--- a/src/Behat/MinkExtension/Context/MinkContext.php
+++ b/src/Behat/MinkExtension/Context/MinkContext.php
@@ -238,22 +238,34 @@ class MinkContext extends RawMinkContext implements TranslatableContext
/**
* Checks, that page contains specified text.
+ * @param string $text the text to check
+ * @param integer $timeout in milliseconds
*
* @Then /^(?:|I )should see "(?P(?:[^"]|\\")*)"$/
*/
- public function assertPageContainsText($text)
+ public function assertPageContainsText($text, $timeout = 10000)
{
- $this->assertSession()->pageTextContains($this->fixStepArgument($text));
+ $element = $this->findAfterAjax($this->getSession()->getPage(), $text, $timeout);
+ if (!$element) {
+ $message = sprintf('The text "%s" was not found anywhere in the text of the current page.', $text);
+ throw new \Behat\Mink\Exception\ResponseTextException($message, $this->getSession());
+ }
}
/**
- * Checks, that page doesn't contain specified text.
+ * Checks, that page does not contain specified text.
+ * @param string $text the text to check
+ * @param integer $timeout in milliseconds
*
* @Then /^(?:|I )should not see "(?P(?:[^"]|\\")*)"$/
*/
- public function assertPageNotContainsText($text)
+ public function assertPageNotContainsText($text, $timeout = 10000)
{
- $this->assertSession()->pageTextNotContains($this->fixStepArgument($text));
+ $element = $this->findAfterAjax($this->getSession()->getPage(), $text, $timeout);
+ if ($element && $element->isVisible()) {
+ $message = sprintf('The text "%s" was found in the text of the current page although it should not.', $text);
+ throw new \Behat\Mink\Exception\ResponseTextException($message, $this->getSession());
+ }
}
/**
@@ -297,16 +309,6 @@ class MinkContext extends RawMinkContext implements TranslatableContext
}
/**
- * Checks, that element with specified CSS contains specified text.
- *
- * @Then /^(?:|I )should see "(?P(?:[^"]|\\")*)" in the "(?P[^"]*)" element$/
- */
- public function assertElementContainsText($element, $text)
- {
- $this->assertSession()->elementTextContains('css', $element, $this->fixStepArgument($text));
- }
-
- /**
* Checks, that element with specified CSS doesn't contain specified text.
*
* @Then /^(?:|I )should not see "(?P(?:[^"]|\\")*)" in the "(?P[^"]*)" element$/
@@ -483,4 +485,66 @@ class MinkContext extends RawMinkContext implements TranslatableContext
{
return str_replace('\\"', '"', $argument);
}
+
+ /**
+ * Checks, that element with specified CSS contains specified text.
+ * @param string $element the element where search
+ * @param string $text the text to check
+ * @param integer $timeout in milliseconds
+ *
+ * @Then /^(?:|I )should see "(?P(?:[^"]|\\")*)" in the "(?P[^"]*)" element$/
+ *
+ * @return null|boolean
+ */
+ public function assertElementContainsText($element, $text, $timeout = 5000)
+ {
+ if ($timeout getSession());
+ }
+ $selectorType = 'css';
+
+ $node = $this->getSession()->getPage()->find($selectorType, $element);
+
+ if (is_object($node)) {
+ $item = $this->findAfterAjax($node, $text);
+ if (!$item) {
+ $this->assertElementContainsText($element, $text, 0);
+ }
+ } else {
+ $this->getSession()->wait(100);
+
+ return $this->assertElementContainsText($element, $text, $timeout - 100);
+ }
+ }
+
+ /**
+ * Try to select element, return null after 15 sec
+ * @param string $element the element where search
+ * @param string $value the value to check
+ * @param integer $timeout in milliseconds
+ *
+ * @return boolean
+ */
+ public function findAfterAjax($element, $value, $timeout = 5000)
+ {
+ if ($timeout find('xpath', '/descendant-or-self::*[contains(translate(text(), '.$alphabetUpper.', '.$alphabetLower.'), translate("'.$value.'", '.$alphabetUpper.', '.$alphabetLower.'))]');
+
+ if ($item) {
+ return $item;
+ } else {
+ $this->getSession()->wait(100);
+
+ return $this->findAfterAjax($element, $value, $timeout - 100);
+ }
+
+ }
}
Подробнее здесь: https://stackoverflow.com/questions/300 ... x-requests
Релевантны ли эти адаптации базового контекста MinkExtension для запросов ajax? ⇐ Php
Кемеровские программисты php общаются здесь
1729222177
Anonymous
По сути, когда мы хотим иметь дело с ajax, нам нужно добавить несколько инструкций по сну, и мне это очень не нравится, даже если конечный пользователь на самом деле чего-то «ждет», я думаю, это должно быть очевидно, поскольку основы не -ajax запросы.
Мне действительно интересно, почему его еще не существует, и я написал несколько адаптаций и буду признателен за ваши отзывы перед возможным пиаром:
https://gist.github.com/lenybernard/6f6c2678a9a2594f923b
diff --git a/src/Behat/MinkExtension/Context/MinkContext.php b/src/Behat/MinkExtension/Context/MinkContext.php
index 90ea038..8d6537b 100644
--- a/src/Behat/MinkExtension/Context/MinkContext.php
+++ b/src/Behat/MinkExtension/Context/MinkContext.php
@@ -238,22 +238,34 @@ class MinkContext extends RawMinkContext implements TranslatableContext
/**
* Checks, that page contains specified text.
+ * @param string $text the text to check
+ * @param integer $timeout in milliseconds
*
* @Then /^(?:|I )should see "(?P(?:[^"]|\\")*)"$/
*/
- public function assertPageContainsText($text)
+ public function assertPageContainsText($text, $timeout = 10000)
{
- $this->assertSession()->pageTextContains($this->fixStepArgument($text));
+ $element = $this->findAfterAjax($this->getSession()->getPage(), $text, $timeout);
+ if (!$element) {
+ $message = sprintf('The text "%s" was not found anywhere in the text of the current page.', $text);
+ throw new \Behat\Mink\Exception\ResponseTextException($message, $this->getSession());
+ }
}
/**
- * Checks, that page doesn't contain specified text.
+ * Checks, that page does not contain specified text.
+ * @param string $text the text to check
+ * @param integer $timeout in milliseconds
*
* @Then /^(?:|I )should not see "(?P(?:[^"]|\\")*)"$/
*/
- public function assertPageNotContainsText($text)
+ public function assertPageNotContainsText($text, $timeout = 10000)
{
- $this->assertSession()->pageTextNotContains($this->fixStepArgument($text));
+ $element = $this->findAfterAjax($this->getSession()->getPage(), $text, $timeout);
+ if ($element && $element->isVisible()) {
+ $message = sprintf('The text "%s" was found in the text of the current page although it should not.', $text);
+ throw new \Behat\Mink\Exception\ResponseTextException($message, $this->getSession());
+ }
}
/**
@@ -297,16 +309,6 @@ class MinkContext extends RawMinkContext implements TranslatableContext
}
/**
- * Checks, that element with specified CSS contains specified text.
- *
- * @Then /^(?:|I )should see "(?P(?:[^"]|\\")*)" in the "(?P[^"]*)" element$/
- */
- public function assertElementContainsText($element, $text)
- {
- $this->assertSession()->elementTextContains('css', $element, $this->fixStepArgument($text));
- }
-
- /**
* Checks, that element with specified CSS doesn't contain specified text.
*
* @Then /^(?:|I )should not see "(?P(?:[^"]|\\")*)" in the "(?P[^"]*)" element$/
@@ -483,4 +485,66 @@ class MinkContext extends RawMinkContext implements TranslatableContext
{
return str_replace('\\"', '"', $argument);
}
+
+ /**
+ * Checks, that element with specified CSS contains specified text.
+ * @param string $element the element where search
+ * @param string $text the text to check
+ * @param integer $timeout in milliseconds
+ *
+ * @Then /^(?:|I )should see "(?P(?:[^"]|\\")*)" in the "(?P[^"]*)" element$/
+ *
+ * @return null|boolean
+ */
+ public function assertElementContainsText($element, $text, $timeout = 5000)
+ {
+ if ($timeout getSession());
+ }
+ $selectorType = 'css';
+
+ $node = $this->getSession()->getPage()->find($selectorType, $element);
+
+ if (is_object($node)) {
+ $item = $this->findAfterAjax($node, $text);
+ if (!$item) {
+ $this->assertElementContainsText($element, $text, 0);
+ }
+ } else {
+ $this->getSession()->wait(100);
+
+ return $this->assertElementContainsText($element, $text, $timeout - 100);
+ }
+ }
+
+ /**
+ * Try to select element, return null after 15 sec
+ * @param string $element the element where search
+ * @param string $value the value to check
+ * @param integer $timeout in milliseconds
+ *
+ * @return boolean
+ */
+ public function findAfterAjax($element, $value, $timeout = 5000)
+ {
+ if ($timeout find('xpath', '/descendant-or-self::*[contains(translate(text(), '.$alphabetUpper.', '.$alphabetLower.'), translate("'.$value.'", '.$alphabetUpper.', '.$alphabetLower.'))]');
+
+ if ($item) {
+ return $item;
+ } else {
+ $this->getSession()->wait(100);
+
+ return $this->findAfterAjax($element, $value, $timeout - 100);
+ }
+
+ }
}
Подробнее здесь: [url]https://stackoverflow.com/questions/30020936/do-these-minkextension-base-context-adaptations-are-relevant-for-ajax-requests[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия