from nose.tools import assert_equal
# pylint: disable=no-name-in-module
from behave import then, when, given, step_matcher
from selenic.util import Result, Condition

from selenium_test.btw_util import register_sf_modal_on_context

step_matcher('re')

__sf_re = r"the document contains the fields (?P<fields>.*)"
@then(__sf_re)
@given(__sf_re)
def step_impl(context, fields):

    def check(driver):
        field_text = driver.execute_script(r"""
        var selector = arguments[0];
        var els = document.querySelectorAll(selector);
        return Array.prototype.map.call(els, function (x) {
          return x.textContent.trim().replace(/\s+/, ' ');
        });
        """, r".btw\:sf")

        combined = ", ".join('"{}"'.format(text) for text in field_text)
        return Result(combined == fields, combined)

    result = Condition(context.util, check).wait()
    assert_equal(result.payload, fields)


@step("the document does not contain any semantic fields")
예제 #2
0
    element = context.emptied_element
    util.wait(lambda *_: element.find_element(By.CLASS_NAME, "_placeholder"))


@then(u'"{text}" is in the text')
def step_impl(context, text):
    driver = context.driver
    util = context.util

    def condition(*_):
        el_text = util.get_text_excluding_children(
            context.element_to_test_for_text)
        return el_text.find(text) != -1
    util.wait(condition)

step_matcher('re')


@then(u'ESCAPE is not in the text')
def step_impl(context):
    util = context.util

    def condition(*_):
        el_text = util.get_text_excluding_children(
            context.element_to_test_for_text)
        return el_text.find(u"\u001b") == -1
    util.wait(condition)


@when(u'the user types (?P<choice>ENTER|ESCAPE|DELETE|BACKSPACE|F1)')
def step_impl(context, choice):
# -*- coding: UTF-8 -*-
"""
Nested parameter examples with "re" matcher (regular expression step matcher).
"""

# @mark.steps
# -----------------------------------------------------------------------------
# STEPS: With "re" matcher
# -----------------------------------------------------------------------------
from behave import step_matcher, when
step_matcher("re")


# -- NESTED GROUP:
@when(u'I try to match nested "(?P<foo>foo(?P<bar>bar)?)"')
def step_when_I_try_to_match_nested_foobar(context, foo, bar):
    context.foo = foo
    context.bar = bar


# -- SIMPLE GROUP: anything else
@when(u'I try to match nested "(?P<anything>.*)"')
def step_when_I_try_to_match_anything_else(context, anything):
    context.anything = anything
예제 #4
0
from urlparse import urljoin
import json
import re

import requests

from nose.tools import assert_equal  # pylint: disable=E0611
from behave import step_matcher

from selenic.util import Result, Condition


step_matcher("re")


@when('the user saves')
def step_impl(context):
    util = context.util
    util.ctrl_equivalent_x('S')

last_obj_re = re.compile('.*}{')

flip_rend_style_re = re.compile(ur'(style=".*?") (rend=".*?")')
flip_xmlns_re = re.compile(ur'(xmlns:math=".*?") (xmlns=".*?")')

_SCENARIO_TO_EXPECTED_DATA = {
    "serializes namespaces properly":
    u"""\
<TEI xmlns="http://www.tei-c.org/ns/1.0"><teiHeader><fileDesc>\
<titleStmt><title>abcd</title></titleStmt><publicationStmt><p/>\
</publicationStmt><sourceDesc><p/></sourceDesc></fileDesc></teiHeader>\
예제 #5
0
        on_index = split_text.index('on')
        spell = " ".join(split_text[:on_index])
        target_name = " ".join(split_text[on_index + 1:])
    else:
        spell = spell_and_target
        target_name = None

    if target_name:
        target = get_character(context=context, character_name=target_name)
    else:
        target = None

    make(caster, cast_spell(spell_name=spell, target=target))


step_matcher('re')


@given('(?P<caster_name>[A-Za-z]+) has no spirit left')
def impl(context, caster_name):
    caster = get_character(context, caster_name)
    caster.spirit = 0


step_matcher('parse')


@when('{caster_name} uses {item_name} for {domain_name} domain')
def step_impl(context, caster_name, item_name, domain_name):
    caster = get_character(context, caster_name)
    item = get_item(context, item_name)
예제 #6
0
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# flake8: noqa

from behave import step_matcher
from pyherc.data import is_armour, is_boots
from pyherc.test.bdd.features.helpers import (armour_list, default_context,
                                              get_character, get_item,
                                              get_location, misc_item_list,
                                              weapon_list, boots_list)
from pyherc.test.cutesy import drop, make

step_matcher('re')

@given('(?P<character_name>[A-Za-z]+) has (?P<item_name>[A-Za-z]+)')
@default_context
@weapon_list
@armour_list
@misc_item_list
@boots_list
def impl(context, character_name, item_name):
    if item_name in context.armour_list:
        item = context.armour_list[item_name]()
    elif item_name in context.weapon_list:
        item = context.weapon_list[item_name]()
    elif item_name in context.misc_item_list:
        item = context.misc_item_list[item_name]()
    elif item_name in context.boots_list:
예제 #7
0
def step(context, expected_message):
    assert_that(
        json.loads(context.response.data),
        is_(json.loads(expected_message)))


@then(u'I should get back a warning of "{expected_warning}"')
def step(context, expected_warning):
    response_object = json.loads(context.response.data)

    assert_that(
        response_object['warning'],
        is_(expected_warning)
    )

step_matcher("re")


@then('the JSON should have "(?P<n>\d+)" results?')
def step(context, n):
    response_data = json.loads(context.response.data)
    assert_that('data' in response_data, response_data.get('message', None))
    the_data = response_data['data']
    assert_that(the_data, has_length(int(n)))


step_matcher("parse")


def parse_position(nth, data):
    match = re.compile(r'\d+').match(nth)