Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# features/contact.feature
@fixture.browser.chrome
Feature: Contact form
Make sure that the contact form on XPC works as expected
Scenario: Company sending an email
Given a company member going to the contact form
When he fills the form
| name | value |
| lastName | Snow |
| firstName | John |
| email | king@example.com |
| phoneNumber | 00000000000 |
| companyName | The North |
| industry | IT |
| comment | How does this work ? |
| agreeTerms | true |
Then he sees a thank you message
And emails are sent
| to | subject |
| admin@gounite.com | GOuniteWebサイトからのお問合せ |
| king@example.com | GOuniteWebサイトへのお問い合わせ内容確認 |
# features/steps/contact.py
from behave import given, then, when
from django.core import mail
@given(u"a company member going to the contact form")
def step_impl(context):
context.browser.visit("https://xpc.gounite.test/contact")
context.test.assertTrue(context.browser.find_by_css(".contact-form").second.visible)
context.browser.find_by_text("Company").click()
@when(u"he fills the form") # noqa F811
def step_impl(context):
field_values = {k: v for k, v in context.table}
context.browser.fill_form(field_values, name="contact_form")
form = context.browser.find_by_tag("form").first
form.find_by_tag("button").first.click()
@then(u"he sees a thank you message") # noqa F811
def step_impl(context):
context.test.assertEqual(context.browser.url, "https://xpc.gounite.test/complete")
context.browser.is_text_present("ご連絡ありがとうございます")
@then(u"emails are sent") # noqa F811
def step_impl(context):
context.test.assertEqual(len(mail.outbox), 2)
for i, row in enumerate(context.table):
context.test.assertEqual(mail.outbox[i].to, [row["to"]])
context.test.assertEqual(mail.outbox[i].subject, row["subject"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.