Last active
December 19, 2023 00:19
-
-
Save aevans-mms/e0f9839a68cf529b712d52dc414c8ee2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: NEJM Registration | |
Scenario: Register as Physician | |
Given I am a physician | |
When I register for NEJM | |
And I enter my email address on the registration form and click continue | |
And I select my country on the registration form and click continue | |
Then I should see the "Professional Category" field on the registration form | |
But I should not see the "Primary Specialty" field on the registration form | |
When I select professional category "Physician" | |
Then I should see the "Primary Specialty" field on the registration form | |
And I should see the "Role" field on the registration form | |
And I should see the "Place of Work or Study" field on the registration form | |
And I should see the "Name of Organization" field on the registration form | |
# TODO: fill out professional information (Step 3) | |
# TODO: fill out personal information (Step 4) | |
When I submit the registration form | |
Then I should not see any errors | |
Scenario: Register as Nurse | |
Given I am a nurse | |
When I register for NEJM | |
And I enter my email address on the registration form and click continue | |
And I select my country on the registration form and click continue | |
Then I should see the "Professional Category" field on the registration form | |
But I should not see the "Primary Specialty" field on the registration form | |
# NOTE: This should fail because of Primary Specialty, but continue the other checks | |
When I select professional category "Nurse" | |
Then I should see the "Primary Specialty" field on the registration form | |
And I should see the "Role" field on the registration form | |
And I should see the "Place of Work or Study" field on the registration form | |
And I should see the "Name of Organization" field on the registration form | |
# TODO: fill out professional information (Step 3) | |
# TODO: fill out personal information (Step 4) | |
When I submit the registration form | |
Then I should not see any errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package starter.stepdefinitions; | |
import org.assertj.core.api.SoftAssertions; | |
public class RegistrationSession { | |
String firstName; | |
String lastName; | |
String emailAddress; | |
String professionalCategory; | |
String country; | |
SoftAssertions softly = new SoftAssertions(); | |
public RegistrationSession() { | |
System.out.println("Initializing UserRegistrationSteps..."); | |
country = "Canada"; | |
} | |
public String getEmailAddress() { | |
if (emailAddress == null) { | |
emailAddress = firstName + "." + lastName + "@" + "nejmautoemail.com"; | |
} | |
return emailAddress; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package starter.stepdefinitions; | |
import io.cucumber.java.en.Given; | |
import io.cucumber.java.en.Then; | |
import io.cucumber.java.en.When; | |
import net.serenitybdd.annotations.Steps; | |
import java.util.*; | |
public class RegistrationSteps { | |
@Steps | |
RegistrationSession session; | |
List allFields = Arrays.asList( | |
"Professional Category", | |
"Primary Specialty", | |
"Role", | |
"Profession", | |
"Place of Work or Study", | |
"Name of Organization", | |
"Student Type" | |
); | |
Set visibleFields = new HashSet<>(allFields); | |
@Given("I am a physician") | |
public void i_am_a_physician() { | |
System.out.println("I am a physician"); | |
System.out.println("Create user..."); | |
session.professionalCategory = "physician"; | |
session.firstName = "Otto"; | |
session.lastName = "Tester"; | |
visibleFields.add("Primary Specialty"); | |
visibleFields.remove("Profession"); | |
visibleFields.remove("Student Type"); | |
} | |
@Given("I am a nurse") | |
public void i_am_a_nurse() { | |
System.out.println("I am a nurse"); | |
System.out.println("Create user..."); | |
session.professionalCategory = "nurse"; | |
session.firstName = "Otto"; | |
session.lastName = "Tester"; | |
visibleFields.remove("Primary Specialty"); | |
visibleFields.remove("Profession"); | |
visibleFields.remove("Student Type"); | |
} | |
@Given("I am a user with professional category {string}") | |
public void i_am_a_user_with_professional_category(String professionalCategory) { | |
} | |
@When("I register for NEJM") | |
public void i_register_for_nejm() { | |
System.out.println("I'm registering for NEJM with professional category: " + session.professionalCategory); | |
System.out.println("open NEJM home page"); | |
System.out.println("click Create Account button"); | |
} | |
@When("I select my country on the registration form and click continue") | |
public void i_select_my_country_on_the_registration_form_and_click_continue() { | |
System.out.println("select default country 'USA'"); | |
System.out.println("click Continue button"); | |
session.softly.assertThat(session.country).isEqualTo("USA"); | |
} | |
@Then("I should see the {string} field on the registration form") | |
public void i_should_see_the_field_on_the_registration_form(String fieldName) { | |
System.out.println("look for field on registration form: " + fieldName); | |
System.out.println("visible fields: " + visibleFields); | |
session.softly.assertThat(fieldName).isIn(visibleFields); | |
} | |
@Then("I should not see the {string} field on the registration form") | |
public void i_should_not_see_the_field_on_the_registration_form(String fieldName) { | |
System.out.println("look for field on registration form: " + fieldName); | |
System.out.println("visible fields: " + visibleFields); | |
session.softly.assertThat(fieldName).isNotIn(visibleFields); | |
} | |
@When("I enter my email address on the registration form and click continue") | |
public void i_enter_my_email_address_on_the_registration_form_and_click_continue() { | |
System.out.println("I'm entering my email address on the NEJM registration form: " + session.getEmailAddress()); | |
System.out.println("click Continue button"); | |
} | |
@When("I select professional category {string}") | |
public void i_select_professional_category(String professionalCategory) { | |
System.out.println("Select professional category: " + professionalCategory); | |
if (professionalCategory.equals("Physician") || professionalCategory.equals("Resident")) { | |
visibleFields.add("Primary Specialty"); | |
} | |
else { | |
visibleFields.remove("Primary Specialty"); | |
} | |
System.out.println("visible fields: " + visibleFields); | |
} | |
@When("I submit the registration form") | |
public void i_submit_the_registration_form() { | |
System.out.println("submit the registration form"); | |
} | |
@Then("I should not see any errors") | |
public void i_should_not_see_any_errors() { | |
System.out.println("there should not be any errors"); | |
session.softly.assertAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And finally in our last step we call softly.assertAll() to look for all soft assertions from previous steps that are tracked in the shared session object
in RegistrationCompleteSteps.java on line 20:
Also, that we including our RegistrationSession object in this file as well on line 8-9:
so that we can use the same shared state