Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.charttest.webdriver;
- import org.junit.AfterClass;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.junit.runners.Parameterized;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.htmlunit.HtmlUnitDriver;
- import java.util.*;
- import static junit.framework.Assert.assertTrue;
- @RunWith(Parameterized.class)
- public class OfficialChartsTest_Revised
- {
- private String chartYear;
- private static WebDriver driver;
- public static String urlBase = "http://www.officialcharts.com/archive-chart/_/1/";
- @BeforeClass
- public static void createDriver() {
- driver = new HtmlUnitDriver();
- }
- public OfficialChartsTest_Revised(String chartYear) {
- this.chartYear = chartYear;
- }
- @Parameterized.Parameters(name="{0} chart archive")
- public static Collection chartYears() {
- return Arrays.asList(new Object[][] {
- {"1960"}, {"1961"}, {"1962"}, {"1963"}, {"1964"}, {"1965"}, {"1966"},{"1967"},{"1968"},{"1969"},
- {"1970"}, {"1971"}, {"1972"}, {"1973"}, {"1974"}, {"1975"}, {"1976"},{"1977"},{"1978"},{"1979"},
- {"1980"}, {"1981"}, {"1982"}, {"1983"}, {"1984"}, {"1985"}, {"1986"},{"1987"},{"1988"},{"1989"},
- {"1990"}, {"1991"}, {"1992"}, {"1993"}, {"1994"}, {"1995"}, {"1996"},{"1997"},{"1998"},{"1999"},
- {"2000"}, {"2001"}, {"2002"}, {"2003"}, {"2004"}, {"2005"}, {"2006"},{"2007"},{"2008"},{"2009"},
- {"2010"}, {"2011"}, {"2012"}, {"2013"}, {"2014"}, {"2015"}
- });
- }
- @Test
- public void GetChartsForYear()
- {
- driver.navigate().to(urlBase + chartYear);
- WebElement archiveTable = driver.findElement(By.cssSelector(".archive"));
- List<WebElement> chartLinks;
- chartLinks = archiveTable.findElements(By.cssSelector("td[class='links']"));
- Set<String> links = new HashSet<String>();
- for (WebElement e: chartLinks)
- {
- links.add(e.findElement(By.tagName("a")).getAttribute("href"));
- }
- for (String thisLink: links)
- {
- CheckChartPage(thisLink);
- }
- }
- public void CheckChartPage(String chartUrl)
- {
- driver.navigate().to(chartUrl);
- // Get last element from URL... magic numbers, could have used a split!
- String chartDate = chartUrl.substring(48,58);
- assertTrue("Chart for " + chartDate + " not found", driver.getTitle().startsWith(chartDate));
- }
- @AfterClass
- public static void quitDriver() {
- driver.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement