package selenium.mtgstocks;

import io.github.bonigarcia.wdm.FirefoxDriverManager;
import org.assertj.core.api.AbstractCharSequenceAssert;
import org.assertj.core.api.Assertions;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MtgStocksTest {

	protected WebDriver driver;

	@BeforeClass
	public static void setUpClass() {
		FirefoxDriverManager.getInstance().setup();
	}

	@Before
	public void setUp() {
		driver = new FirefoxDriver();
	}

	@Test
	public void homePage() {
		driver.get("http://www.mtgstocks.com");
		assertTitle();
		assertGreetingText();
		assertNavigationBar();
	}

	private void assertTitle() {
		Assertions.assertThat(driver.getTitle()).isEqualTo("MTGStocks.com");
	}

	private void assertGreetingText() {
		Assertions.assertThat(driver.findElement(By.xpath("//div[@class='jumbotron']/p")).getText())
				.isEqualTo("Your favorite resource for daily price updates on Magic: the Gathering cards. We track prices of all cards and report the ones that have recently fluctuated the most for your Magic finance convenience!");
	}

	private void assertNavigationBar() {
		Assertions.assertThat(driver.findElement(By.id("navbar")).getText())
				.isEqualTo("Sets\nInterests\nAnalytics\nDecks\nAbout\nLogin\nSign up");
	}

	@After
	public void tearDown() {
		driver.quit();
	}
}

@@ -432,16 +432,127 @@
 xDriver;
+%0Aimport org.openqa.selenium.support.ui.ExpectedConditions;%0Aimport org.openqa.selenium.support.ui.WebDriverWait;
 %0A%0Apublic
@@ -909,24 +909,42 @@
 ationBar();%0A
+%09%09goToSetsPage();%0A
 %09%7D%0A%0A%09private
@@ -1463,42 +1463,26 @@
 hat(
-driver.findElement(By.id(%22navbar%22)
+findNavigationBar(
 ).ge
@@ -1570,16 +1570,427 @@
 %22);%0A%09%7D%0A%0A
+%09private WebElement findNavigationBar() %7B%0A%09%09return driver.findElement(By.id(%22navbar%22));%0A%09%7D%0A%0A%09private void goToSetsPage() %7B%0A%09%09findNavigationBar().findElement(By.linkText(%22Sets%22)).click();%0A%09%09WebDriverWait webDriverWait = new WebDriverWait(driver, 5);%0A%09%09webDriverWait.until(ExpectedConditions.titleIs(%22Sets - MTGStocks.com%22));%0A%09%09Assertions.assertThat(driver.getTitle())%0A%09%09%09%09.isEqualTo(%22Sets - MTGStocks.com%22);%0A%09%7D%0A%0A
 %09@After%0A

test to navigate to Sets page