
import static org.junit.Assert.*;

import java.util.concurrent.TimeUnit;

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.Select;

public class TestCode_16063222 {
	private WebDriver driver;
	private String baseUrl;
	private boolean acceptNextAlert = true;
	private StringBuffer verificationErrors = new StringBuffer();

	@Before
	public void setUp() throws Exception {
		System.setProperty("webdriver.chrome.driver", "D:/Users/owitn/documents/chromedriver.exe");
		driver = new ChromeDriver();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		driver.manage().window().setPosition(new Point(0, 0));
		driver.manage().window().setSize(new Dimension(1200, 1024));
	}

	@Test
	public void testUntitledTestCase() throws Exception {
		String target = "Computer Science";
		String tab = "STUDY";
		driver.get("https://www.leeds.ac.uk/");
		assertEquals("University of Leeds", driver.getTitle());
		try {
			assertEquals(tab, driver.findElement(By.cssSelector("#navItem1000")).getText());
		} catch (Error e) {
			verificationErrors.append(e.toString());
		}
		
		driver.findElement(By.cssSelector("a.cc-btn.cc-dismiss")).click();
		driver.findElement(By.cssSelector("#navItem1000")).click();
		
		assertTrue(isElementPresent(By.cssSelector("#navItem116000")));
		
		driver.findElement(By.cssSelector("#navItem116000")).click();
		
		assertTrue(isElementPresent(By.cssSelector(".heading")));
		try {
			assertEquals("COURSE SEARCH", driver.findElement(By.cssSelector(".btn--hollow")).getText());
		} catch (Error e) {
			verificationErrors.append(e.toString());
		}
		
		//assertTrue(isElementPresent(By.cssSelector("#navItem1000")));
		//assertTrue(isElementPresent(By.cssSelector(".btn--hollow")));
		
		/******************************************************/
		try {
			   Thread.sleep(3000);
			} catch (InterruptedException e) {
			   e.printStackTrace();
			}
		driver.findElement(By.cssSelector(".btn--hollow")).click();
		/******************************************************/
		
		assertEquals("Course Finder", driver.findElement(By.cssSelector("div.local-header-title > a")).getText());
		assertEquals("Search for courses",
				driver.findElement(By.cssSelector("h1.heading-underline.color-white")).getText());
		driver.findElement(By.cssSelector("#searchCourse")).clear();
		driver.findElement(By.cssSelector("#searchCourse")).sendKeys(target);
		assertEquals("UG", driver.findElement(By.cssSelector("#degreeType")).getAttribute("value"));
		driver.findElement(By.cssSelector(".btn-lg")).click();
		assertEquals("Search results", driver.findElement(By.cssSelector("h1.heading-underline")).getText());
		try {
			assertEquals(target, driver.findElement(By.cssSelector("input[name=\"query\"]")).getAttribute("value"));
		} catch (Error e) {
			verificationErrors.append(e.toString());
		}
		try {
			assertEquals("UG", driver.findElement(By.cssSelector("#degreeType")).getAttribute("value"));
		} catch (Error e) {
			verificationErrors.append(e.toString());
		}
		try {
			assertEquals("201920", driver.findElement(By.cssSelector("#entryYear")).getAttribute("value"));
		} catch (Error e) {
			verificationErrors.append(e.toString());
		}
		int x = 1;
		int limit = 2;
		while (limit > 0) {
			String name = driver.findElement(By.cssSelector("tr:nth-child(" + x + ") a")).getText();
			if (name.contains(target)) {
				driver.findElement(By.cssSelector("tr:nth-child(" + x + ") a")).click();
				try {
					assertTrue(isElementPresent(By.cssSelector("h1.heading-underline.h2-lg")));
				} catch (Error e) {
					verificationErrors.append(e.toString());
				}
				driver.findElement(By.id("return-to-search-results")).click();
			} else {
				limit--;
			}
			x++;
		}
	}

	@After
	public void tearDown() throws Exception {
		driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}

	private boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}
}
