Skip to content

Commit

Permalink
Most of code commented
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmmay committed Jun 3, 2022
1 parent b698196 commit 5640ad7
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 4 deletions.
8 changes: 7 additions & 1 deletion ConjuringTests/BasementPageObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@ namespace ConjuringTests.Pages
{
public class BasementPageObject
{
// Instantiates a new Driver
private readonly IWebDriver _webDriver;

// Sets driver to one provided by BasementPossessionStepDefinitions.cs
public BasementPageObject(IWebDriver webDriver)
{
_webDriver = webDriver;
}

// Locates image of piano on page using its class name, "pianoImage"
private IWebElement PianoImage => _webDriver.FindElement(By.ClassName("pianoImage"));

// Moves position of the page to focus on the image of a piano
public void ScrollDown()
{
var piano = _webDriver.FindElement(By.ClassName("pianoImage"));
Actions actions = new(_webDriver); // This is just: Actions actions = new Actions(_webDriver);
Actions actions = new(_webDriver); // This is the same as: Actions actions = new Actions(_webDriver);
actions.MoveToElement(piano);
actions.Perform();
}

// Clicks on the image of a piano
public void ClickPiano()
{
PianoImage.Click();
}

// Accepts the alert that appears after clicking on the image of a piano
public void VerifyPianoAlertAppears()
{
Thread.Sleep(3000);
Expand Down
6 changes: 6 additions & 0 deletions ConjuringTests/BedroomBPageObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ namespace ConjuringTests.Pages
{
public class BedroomBPageObject
{
// Instantiates a new Driver
private readonly IWebDriver _webDriver;

// Sets driver to one provided by BedroomPossessionStepDefinitions.cs
public BedroomBPageObject(IWebDriver webDriver)
{
_webDriver = webDriver;
}

// Locates range input using it's assigned name, "wardrobeBump"
private IWebElement slider => _webDriver.FindElement(By.Name("wardrobeBump"));

// Sends arrow key inputs to the slider to raise it to 5 and lower it back down to 0
public void RaiseAndLowerSlider()
{
for(int i = 0; i < 5; i++)
Expand All @@ -26,6 +31,7 @@ public void RaiseAndLowerSlider()
}
}

// Retrieves the value (0-5) of the slider input
public String GetSliderValue()
{
return slider.GetAttribute("value");
Expand Down
18 changes: 18 additions & 0 deletions ConjuringTests/BedroomGPageObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@ namespace ConjuringTests.Pages
{
public class BedroomGPageObject
{
// Instantiates a new Driver
private readonly IWebDriver _webDriver;

// Sets driver to one provided by BedroomUnpossessedStepDefinitions.cs
public BedroomGPageObject(IWebDriver webDriver)
{
_webDriver = webDriver;
}

// Locates image of a wardrobe on page using its class name, "wardrobeImage"
private IWebElement wardrobe => _webDriver.FindElement(By.ClassName("wardrobeImage"));

// Locates a text input field using its Id, "weightFormInput"
private IWebElement weightInput => _webDriver.FindElement(By.Id("weightFormInput"));

// Locates a button for submitting the text using its Id, "weightFormButton"
private IWebElement submitButton => _webDriver.FindElement(By.Id("weightFormButton"));

// Locates a link to the BedroomG page using the linktext, "Bedroom"
private IWebElement bedroomButton => _webDriver.FindElement(By.LinkText("Bedroom"));

// Locates the results text after submitting a weight using its bootstrap class name, "text-danger"
private IWebElement resultsText => _webDriver.FindElement(By.ClassName("text-danger"));

// Clicks on the image of a Wardrobe, then confirms the alert that appears
public void ClickWardrobeAndAlert()
{
Thread.Sleep(1000);
Expand All @@ -24,6 +37,7 @@ public void ClickWardrobeAndAlert()
_webDriver.SwitchTo().Alert().Accept();
}

// Enters a weight of 80 into text input field and clicks submit button
public void EnterWeightAndSubmit(int weight)
{
weightInput.Clear();
Expand All @@ -32,6 +46,9 @@ public void EnterWeightAndSubmit(int weight)
submitButton.Click();
}

// Clicks on a link that returns the driver to the BedroomG Page
// Clicks on the image of a Wardrobe, then confirms the alert that appears
// Enters a weight of 120 into text input field and clicks submit button
public void RepeatStepsAndEnterHighWeight(int weight)
{
Thread.Sleep(1000);
Expand All @@ -46,6 +63,7 @@ public void RepeatStepsAndEnterHighWeight(int weight)
Thread.Sleep(3000);
}

// Retrieves the results text that appears after submitting a weight above 100
public String GetWeightFormResultsText()
{
return resultsText.Text;
Expand Down
23 changes: 21 additions & 2 deletions ConjuringTests/HomePageObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,67 @@ namespace ConjuringTests.Pages
{
public class HomePageObject
{
// Builds the expected URL for the testing site homepage
private string _homepageURL = CreatePath("");

// Instantiates a new Driver
private readonly IWebDriver _webDriver;

// Sets driver to one provided by multiple StepDefinitions files
public HomePageObject(IWebDriver webDriver)
{
_webDriver = webDriver;
}

// Locates a button that switches page content using its class name, "possessButton"
private IWebElement PossessionButton => _webDriver.FindElement(By.ClassName("possessButton"));

// Locates a link to the Basement page using the linktext, "Basement"
private IWebElement BasementLink => _webDriver.FindElement(By.LinkText("Basement"));

// Locates a link to the Outside page using the linktext, "Outside"
private IWebElement OutsideLink => _webDriver.FindElement(By.LinkText("Outside"));

// Locates a link to the Bedroom page using the linktext, "Bedroom"
private IWebElement BedroomLink => _webDriver.FindElement(By.LinkText("Bedroom"));

// Compares the drivers current URL with the _homepageURL built earlier
public void VerifyAtHomePage()
{
if (_webDriver.Url != HomePageUrl)
if (_webDriver.Url != _homepageURL)
{
_webDriver.Url = HomePageUrl;
// If the URLs do not match, this sets the Driver's URL to the _homepageURL built earlier
_webDriver.Url = _homepageURL;
}
}

// Clicks on the "Possession" button to switch page content
public void ClickPossessionButton()
{
PossessionButton.Click();
}

// Clicks on the Basement link to navigate to the Basement page
public void NavigateToBasement()
{
BasementLink.Click();
}

// Clicks on the Outside link to navigate to the Outside page
public void NavigateToOutside()
{
OutsideLink.Click();
}

// Clicks on the Bedroom link to navigate to the Basement page
// This method is only used when the "Possession" button HAS NOT been clicked
public void NavigateToBedroomG()
{
BedroomLink.Click();
}

// Clicks on the Bedroom link to navigate to the Basement page
// This method is only used when the "Possession" button HAS been clicked
public void NavigateToBedroomB()
{
BedroomLink.Click();
Expand Down
10 changes: 10 additions & 0 deletions ConjuringTests/OutsidePageObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,35 @@ namespace ConjuringTests.Pages
{
public class OutsidePageObject
{
// Builds the expected URL for the testing site's Outside page
private string _outsideURL = CreatePath("outside-b.html");

// Instantiates a new Driver
private readonly IWebDriver _webDriver;

// Sets driver to one provided by OutsidePossessionStepDefinitions.cs
public OutsidePageObject(IWebDriver webDriver)
{
_webDriver = webDriver;
}

// Locates image of a crow using its class name, "crow"
private IWebElement crow => _webDriver.FindElement(By.ClassName("crow"));

// Locates text on the page using its Id, "crowCounter"
private IWebElement crowCounter => _webDriver.FindElement(By.Id("crowCounter"));

// Compares the drivers current URL with the _outsideURL built earlier
public void VerifyAtOutsidePage()
{
if (_webDriver.Url != _outsideURL)
{
// If the URLs do not match, this sets the Driver's URL to the _outsideURL built earlier
_webDriver.Url = _outsideURL;
}
}

// Clicks on the image of a crow 20 times no matter where it moves to
public void Click20Crows()
{
for(int i = 1; i < 21; i++)
Expand All @@ -34,6 +43,7 @@ public void Click20Crows()
}
}

// Retrieves the crowCounter text that displays how many times the crow has been clicked
public String GetCrowCount()
{
return crowCounter.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,53 @@ namespace ConjuringTests.StepDefinitions
[Binding]
public class BasementPossessionStepDefinitions
{
// Instantiating Necessary PageObjects for test methods
private readonly HomePageObject _homePage;
private readonly BasementPageObject _basementPage;

// Retrieving PageObject methods using current Driver
public BasementPossessionStepDefinitions(BrowserDriver browserDriver)
{
_homePage = new HomePageObject(browserDriver.Current);
_basementPage = new BasementPageObject(browserDriver.Current);
}

// Verifying driver's location at test site
[Given(@"I am on conjuring site going towards Basement")]
public void GivenIAmOnConjuringSite()
{
_homePage.VerifyAtHomePage();
}

// Clicking "Possession" button to alter links
[When(@"I click possession for going to Basement")]
public void WhenIClickPossesion()
{
_homePage.ClickPossessionButton();
}

// Navigating to BasementB Page
[When(@"I click Basement")]
public void WhenIClickBasement()
{
_homePage.NavigateToBasement();
}

// Navigating down the webpage to an image
[When(@"I scroll down")]
public void WhenIScrollDown()
{
_basementPage.ScrollDown();
}

// Clicking on image to activate alert
[When(@"I click on the piano")]
public void WhenIClickOnThePiano()
{
_basementPage.ClickPiano();
}

// Confirming alert
[Then(@"the piano alert appears")]
public void ThenThePianoAlertAppears()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@ namespace ConjuringTests.StepDefinitions
[Binding]
public class BedroomPossessionStepDefinitions
{
// Instantiating Necessary PageObjects for test methods
private readonly HomePageObject _homePage;
private readonly BedroomBPageObject _bedroomBPage;

// Retrieving PageObject methods using current Driver
public BedroomPossessionStepDefinitions(BrowserDriver browserDriver)
{
_homePage = new HomePageObject(browserDriver.Current);
_bedroomBPage = new BedroomBPageObject(browserDriver.Current);
}

// Verifying driver's location at test site
[Given(@"I am on conjuring site going towards BedroomB")]
public void GivenIAmOnConjuringSite3()
{
_homePage.VerifyAtHomePage();
}

// Clicking "Possession" button to alter links
[When(@"I click possession for going to BedroomB")]
public void WhenIClickPossesion3()
{
_homePage.ClickPossessionButton();
}

// Navigating to BedroomB Page
[When(@"I click BedroomB")]
public void WhenIClickBedroomB()
{
_homePage.NavigateToBedroomB();
}

// Moving range input to maximum and back 3 times
[When(@"I raise and lower slider 3 times")]
public void WhenIRaiseAndLowerSlider3Times()
{
Expand All @@ -40,6 +46,7 @@ public void WhenIRaiseAndLowerSlider3Times()
_bedroomBPage.RaiseAndLowerSlider();
}

// Verifying the range input's value is 0
[Then(@"the slider is back at 0")]
public void ThenTheSliderIsBackAt0()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,57 @@ namespace ConjuringTests.StepDefinitions
[Binding]
public class BedroomUnpossessedStepDefinitions
{
// Instantiating Necessary PageObjects for test methods
private readonly HomePageObject _homePage;
private readonly BedroomGPageObject _bedroomGPage;

// Retrieving PageObject methods using current Driver
public BedroomUnpossessedStepDefinitions(BrowserDriver browserDriver)
{
_homePage = new HomePageObject(browserDriver.Current);
_bedroomGPage = new BedroomGPageObject(browserDriver.Current);
}

// Verifying driver's location at test site
[Given(@"I am on conjuring site going towards BedroomG")]
public void GivenIAmOnConjuringSite3()
{
_homePage.VerifyAtHomePage();
}

// This method is testing an "Unpossessed" section of the site,
// Therefore, the test doesn't click the "Possession" button to alter the links

// Navigating to BedroomG Page
[When(@"I click BedroomG")]
public void WhenIClickBedroomG()
{
_homePage.NavigateToBedroomG();
}

// Clicking on image to activate alert, then confirming alert
[When(@"I click on wardrobe and alert")]
public void WhenIClickOnWardrobeAndAlert()
{
_bedroomGPage.ClickWardrobeAndAlert();
}

// Entering a weight of 80 into input and submitting
[When(@"I enter low weight and submit")]
public void WhenIEnterLowWeightAndSubmit()
{
_bedroomGPage.EnterWeightAndSubmit(80);
}

// Returns to BedroomG Page then clicks the image, confirms the alert and
// enters a weight of 120 into input then clicks Submit button
[When(@"I repeat steps and enter high weight")]
public void WhenIRepeatStepsAndEnterHighWeight()
{
_bedroomGPage.RepeatStepsAndEnterHighWeight(120);
}

// Verifies that the correct text for a weight above 100 appears
[Then(@"I fall through the house")]
public void ThenIFallThroughTheHouse()
{
Expand Down
Loading

0 comments on commit 5640ad7

Please sign in to comment.