Groovy — различия между версиями

(expect Matcher)
Строка 32: Строка 32:
  
 
Возможные Matcher-ы:
 
Возможные Matcher-ы:
* <code>allOf(Matcher, Matcher...)</code>
+
* <code>allOf(Matcher, Matcher...)</code> - Creates a matcher that matches if the examined input matches <b>all</b> of the specified matchers.
* <code>anyOf(Matcher, Matcher...)</code>
+
* <code>anyOf(Matcher, Matcher...)</code> - Creates a matcher that matches if the examined input matches <b>any</b> of the specified matchers.
* <code>anyString()</code>
+
* <code>anyString()</code> - Creates a matcher that matches when at least one character exists in the input buffer.
* <code>contains(String)</code>
+
* <code>contains(String)</code> - Creates a matcher of <code>String</code> that matches when examined input contains the given substring.
* <code>exact(String)</code>
+
* <code>eof()</code> - Creates a matcher that matches if input reaches the end of stream (closed telnet session).
* <code>matches(String)</code>
+
* <code>exact(String)</code> - Creates a matcher that matches when the given string is equal to the input buffer contents.
* <code>matches(Pattern)</code>
+
* <code>matches(String)</code> - Creates a matcher of <code>String</code> that matches when examined input <b>fully matches</b> the given regular expression.
* <code>regexp(String)</code>
+
* <code>matches(Pattern)</code> - Creates a matcher of <code>Pattern</code> that matches when examined input <b>fully matches</b> the given regular expression.
* <code>regexp(Pattern)</code>
+
* <code>regexp(String)</code> - Creates a matcher of <code>String</code> that matches when examined input <b>contains</b> the given regular expression.
* <code>sequence(Matcher, Matcher...)</code>
+
* <code>regexp(Pattern)</code> - Creates a matcher of <code>Pattern</code> that matches when examined input <b>contains</b> the given regular expression.
* <code>startsWith(String)</code>
+
* <code>sequence(Matcher, Matcher...)</code> - Matches the given matchers one by one. Every successful matches updates the internal buffer. The consequent match operation is performed after the previous match has succeeded.
* <code>times(int, Matcher)</code>
+
* <code>startsWith(String)</code> - Creates a matcher that matches when the input buffer starts with the given string.
 +
* <code>times(int, Matcher)</code> - Creates a matcher that matches if the given <code>Matcher</code> matches the <code>number</code> of times.

Версия 12:14, 22 апреля 2016

Общие сведения

Любые строки нужно брать в кавычки, т.к. это язык программирования. В одинарных кавычках все отправляется как есть, в двойных интерполируются имена переменных с долларом (превращаются в значения).

Одни из самых часто используемых команд:

  • SendLine "something" - отправить это в телнет-сессию и

добавить в конце <LF>.

  • Send "something" - то же самое, но без <LF> в

конце.

  • expect "something" - ожидать, пока телнет выведет в

output текст "something".

Переменные вне кавычек пишутся просто без каких-либо символов вначале. т.е. port_name, prompt и т.п.


Доступные команды:

expect "string"

Ожидать, пока telnet-сессия выведет в output string.

Примеры:

  • expect "#"
  • expect prompt
  • expect "# port_$port_number sn:$onu_sn"

expect Matcher

Ожидать, пока telnet-сессия выведет в output строку, соответствующую Matcher.

Возможные Matcher-ы:

  • allOf(Matcher, Matcher...) - Creates a matcher that matches if the examined input matches all of the specified matchers.
  • anyOf(Matcher, Matcher...) - Creates a matcher that matches if the examined input matches any of the specified matchers.
  • anyString() - Creates a matcher that matches when at least one character exists in the input buffer.
  • contains(String) - Creates a matcher of String that matches when examined input contains the given substring.
  • eof() - Creates a matcher that matches if input reaches the end of stream (closed telnet session).
  • exact(String) - Creates a matcher that matches when the given string is equal to the input buffer contents.
  • matches(String) - Creates a matcher of String that matches when examined input fully matches the given regular expression.
  • matches(Pattern) - Creates a matcher of Pattern that matches when examined input fully matches the given regular expression.
  • regexp(String) - Creates a matcher of String that matches when examined input contains the given regular expression.
  • regexp(Pattern) - Creates a matcher of Pattern that matches when examined input contains the given regular expression.
  • sequence(Matcher, Matcher...) - Matches the given matchers one by one. Every successful matches updates the internal buffer. The consequent match operation is performed after the previous match has succeeded.
  • startsWith(String) - Creates a matcher that matches when the input buffer starts with the given string.
  • times(int, Matcher) - Creates a matcher that matches if the given Matcher matches the number of times.