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;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

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();
		goToSetsPage();
	}

	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(findNavigationBar().getText())
				.isEqualTo("Sets\nInterests\nAnalytics\nDecks\nAbout\nLogin\nSign up");
	}

	private WebElement findNavigationBar() {
		return driver.findElement(By.id("navbar"));
	}

	private void goToSetsPage() {
		findNavigationBar().findElement(By.linkText("Sets")).click();
		WebDriverWait webDriverWait = new WebDriverWait(driver, 5);
		webDriverWait.until(ExpectedConditions.titleIs("Sets - MTGStocks.com"));
		Assertions.assertThat(driver.getTitle())
				.isEqualTo("Sets - MTGStocks.com");
	}

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

@@ -80,64 +80,8 @@
 er;%0A
-import org.assertj.core.api.AbstractCharSequenceAssert;%0A
 impo
@@ -112,24 +112,24 @@
 Assertions;%0A
+
 import org.j
@@ -526,15 +526,13 @@
 %0A%09pr
-otec
+iva
 te
-d
  Web
@@ -860,21 +860,124 @@
 );%0A%09
-%09goToSetsPage
+%7D%0A%0A%09@Test%0A%09public void setsPage() %7B%0A%09%09driver.get(%22http://www.mtgstocks.com%22);%0A%09%09goToSetsPage();%0A%09%09assertNumberOfSets
 ();%0A
@@ -2026,16 +2026,147 @@
 %22);%0A%09%7D%0A%0A
+%09private void assertNumberOfSets() %7B%0A%09%09Assertions.assertThat(driver.findElements(By.className(%22list%22)).size()).isEqualTo(169);%0A%09%7D%0A%0A
 %09@After%0A

add test counting number of sets on the Sets page