def before_scenario(context, scenario):
    """Run before each scenario"""
    context.page_factory = PageFactory()
    context.executor = ioc_config.EXECUTOR.resolve('test')
    context.browser = ioc_config.CONFIG.resolve('driver').browser
    context.session_id = context.executor.get_session_id()
    # scenario.name = '%s_%s' % (scenario.name, context.browser.upper())

    if "apple_test" in scenario.tags and (context.browser not in "safari"):
        if 'iP' not in CONFIGURATION.REMOTE_DEVICE:
            scenario.skip(
                "SCENARIO SKIPPED as iOS system and Safari is required for ApplePay test"
            )
    if "visa_test" in scenario.tags and ('IE' in CONFIGURATION.REMOTE_BROWSER):
        scenario.skip(
            "SCENARIO SKIPPED as IE browser doesn't support Visa Checkout")
    if "animated_card_repo_test" in scenario.tags:
        context.is_field_in_iframe = False
    #ToDo Temporarily disabled parent-iframe test. Problem with cress-origin restriction on ios
    if "parent_iframe" in scenario.tags and ('iP'
                                             in CONFIGURATION.REMOTE_DEVICE):
        scenario.skip("Temporarily disabled test ")
    else:
        context.is_field_in_iframe = True
    if 'config_skip_jsinit' not in scenario.tags:
        stub_st_request_type("jsinit.json", RequestType.JSINIT.name)
def step_impl(context, action_code):
    context.action_code = action_code
    payment_page = context.page_factory.get_page(page_name='payment_methods')
    if action_code == "ERROR":
        stub_payment_status(MockUrl.VISA_MOCK_URI.value,
                            VisaResponse.SUCCESS.value)
        stub_st_request_type(VisaResponse.ERROR.value, RequestType.AUTH.name)
    else:
        stub_st_request_type(VisaResponse.VISA_AUTH_SUCCESS.value,
                             RequestType.AUTH.name)
        stub_payment_status(MockUrl.VISA_MOCK_URI.value,
                            VisaResponse[action_code].value)
    payment_page.choose_payment_methods(PaymentType.VISA_CHECKOUT.name)
def step_impl(context, request_type, action_code):
    payment_page = context.page_factory.get_page(page_name='payment_methods')
    if request_type == "AUTH":
        stub_st_request_type(AUTHresponse[action_code].value,
                             RequestType.AUTH.name)
    else:
        stub_st_request_type(request_type_response[request_type], request_type)

    if 'ie' in context.browser and 'config_submit_cvv_only' in context.scenario.tags:
        context.executor.wait_for_javascript()
    payment_page.choose_payment_methods(PaymentType.CARDINAL_COMMERCE.name)
    if 'config_submit_on_success_and_error_true' not in context.scenario.tags:
        payment_page.scroll_to_top()
def step_impl(context, acs_response):
    if acs_response == "OK":
        stub_payment_status(MockUrl.CC_MOCK_ACS_URI.value,
                            ACSresponse[acs_response].value)
    elif acs_response == "NOACTION":
        stub_payment_status(MockUrl.CC_MOCK_ACS_URI.value,
                            ACSresponse[acs_response].value)
        stub_st_request_type(AUTHresponse.OK.value, RequestType.AUTH.name)
    elif acs_response == "FAILURE":
        stub_payment_status(MockUrl.CC_MOCK_ACS_URI.value,
                            ACSresponse[acs_response].value)
        stub_st_request_type(AUTHresponse.MERCHANT_DECLINE.value,
                             RequestType.AUTH.name)
    elif acs_response == "ERROR":
        stub_payment_status(MockUrl.CC_MOCK_ACS_URI.value,
                            ACSresponse[acs_response].value)
def step_impl(context, action_code):
    context.action_code = action_code
    payment_page = context.page_factory.get_page(page_name='payment_methods')
    stub_st_request_type(ApplePayResponse.SUCCESS.value,
                         RequestType.WALLETVERIFY.name)
    if action_code == "SUCCESS":
        stub_payment_status(MockUrl.APPLEPAY_MOCK_URI.value,
                            ApplePayResponse[action_code].value)
        stub_st_request_type(ApplePayResponse.APPLE_AUTH_SUCCESS.value,
                             RequestType.AUTH.name)
    elif action_code == "ERROR":
        stub_payment_status(MockUrl.APPLEPAY_MOCK_URI.value,
                            ApplePayResponse.SUCCESS.value)
        stub_st_request_type_server_error(RequestType.AUTH.name)
    elif action_code == "DECLINE":
        stub_payment_status(MockUrl.APPLEPAY_MOCK_URI.value,
                            ApplePayResponse.SUCCESS.value)
        stub_st_request_type(ApplePayResponse.ERROR.value,
                             RequestType.AUTH.name)
    elif action_code == "CANCEL":
        stub_payment_status(MockUrl.APPLEPAY_MOCK_URI.value,
                            ApplePayResponse[action_code].value)
    payment_page.choose_payment_methods(PaymentType.APPLE_PAY.name)
def step_impl(context, request_type):
    stub_st_request_type(ApplePayResponse.SUCCESS.value,
                         RequestType.WALLETVERIFY.name)
    stub_payment_status(MockUrl.APPLEPAY_MOCK_URI.value,
                        ApplePayResponse.SUCCESS.value)
    stub_st_request_type(request_type_applepay[request_type], request_type)
def step_impl(context, request_type):
    stub_st_request_type(request_type_response[request_type], request_type)
def step_impl(context, tdq_response):
    stub_st_request_type(TDQresponse[tdq_response].value,
                         RequestType.THREEDQUERY.name)
    if 'ie' in context.browser and 'config_submit_cvv_only' in context.scenario.tags:
        context.executor.wait_for_javascript()
def step_impl(context, request_type, action_code):
    if request_type == "AUTH":
        stub_st_request_type(AUTHresponse[action_code].value,
                             RequestType.AUTH.name)
def step_impl(context, field):
    stub_st_request_type(InvalidFieldResponse[field].value,
                         RequestType.THREEDQUERY.name)