Skip to content

Instantly share code, notes, and snippets.

@AdrienLemaire
Last active February 25, 2019 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdrienLemaire/104824b4be9dc73ccedee89c5c546172 to your computer and use it in GitHub Desktop.
Save AdrienLemaire/104824b4be9dc73ccedee89c5c546172 to your computer and use it in GitHub Desktop.
# 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