diff --git a/src/AddImageAccount.java b/src/AddImageAccount.java new file mode 100644 index 0000000..5c49151 --- /dev/null +++ b/src/AddImageAccount.java @@ -0,0 +1,81 @@ +package tests; + +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.junit.*; + +import static org.junit.Assert.*; + +import org.openqa.selenium.*; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class AddImageAccount { + private WebDriver driver; + private String baseUrl; + private StringBuffer verificationErrors = new StringBuffer(); + private String imageToRemove; + + @Before + public void setUp() throws Exception { + driver = new FirefoxDriver(); + baseUrl = "http://imgur.com"; + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + login(); + } + + @Test + public void testAddImageAccount() throws Exception { + StringSelection selection = new StringSelection("http://i.imgur.com/xY3TaEV.png"); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(selection, selection); + + driver.findElement(By.className("upload-button")).click(); + WebElement textArea = driver.findElement(By.id("upload-global-link-input")); + new Actions( driver ).contextClick(textArea).sendKeys( "p" ).perform(); + driver.findElement(By.id("upload-global-start-button")).submit(); + WebElement nicetime = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("nicetime"))); + String code = driver.getCurrentUrl().substring(17); + imageToRemove = code; + driver.get("http://cs1699testing.imgur.com/all"); + List list = driver.findElements(By.id(imageToRemove)); + assertTrue(list.size() > 0); + logout(); + } + + @After + public void tearDown() throws Exception { + login(); + driver.get("http://cs1699testing.imgur.com/all/"); + WebElement hoverElement = driver.findElement(By.id(imageToRemove)); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.cssSelector("#" + imageToRemove + " > div:nth-child(3) > div:nth-child(2)")).click(); + driver.findElement(By.id("delete-button")).click(); + driver.quit(); + String verificationErrorString = verificationErrors.toString(); + if (!"".equals(verificationErrorString)) { + fail(verificationErrorString); + } + } + + private void login() { + driver.get(baseUrl + "/signin"); + driver.findElement(By.id("username")).sendKeys("cs1699testing"); + driver.findElement(By.id("password")).sendKeys("laboontesting"); + driver.findElement(By.name("submit")).click(); + } + + public void logout() { + WebElement hoverElement = driver.findElement(By.id("secondary-nav")); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@class='dropdown-footer']//a[contains(text(),'logout')]")).click(); + } +} diff --git a/src/AddToAlbum.java b/src/AddToAlbum.java new file mode 100644 index 0000000..d1b6b88 --- /dev/null +++ b/src/AddToAlbum.java @@ -0,0 +1,90 @@ +package tests; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.junit.*; + +import static org.junit.Assert.*; + +import org.openqa.selenium.*; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class AddToAlbum { + private WebDriver driver; + private String baseUrl; + private StringBuffer verificationErrors = new StringBuffer(); + + @Before + public void setUp() throws Exception { + driver = new FirefoxDriver(); + baseUrl = "http://imgur.com"; + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); + login(); + } + + + + @Test + public void testAddToAlbum() throws Exception { + // Get the album page + driver.get("http://cs1699testing.imgur.com/"); + WebElement hoverElement = driver.findElement(By.xpath("//div[@data-title='Test Album']")); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@data-title='Test Album']/div[4]")).click(); + new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(driver + .findElement(By.xpath("//div[@data-title='Test Album']//div[@class='item album-images-link']")))); + driver.findElement(By.xpath("//div[@data-title='Test Album']//div[@class='item album-images-link']")).click(); + driver.findElement(By.xpath("//div[@id='images-menu']/div[2]")).click(); + driver.findElement(By.id("MNhewWN")).click(); + driver.findElement(By.name("submit")).click(); + driver.get("http://imgur.com/a/Yexh0"); + //driver.findElement(By.xpath("//div[@data-title='Test Album']/div[@class='cover']/a")).click(); + List list = driver.findElements(By.id("MNhewWN")); + assertTrue(list.size() > 0); + logout(); + } + + @After + public void tearDown() throws Exception { + login(); + driver.get("http://cs1699testing.imgur.com/"); + WebElement hoverElement = driver.findElement(By.xpath("//div[@data-title='Test Album']")); + + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@data-title='Test Album']/div[4]")).click(); + new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(driver + .findElement(By.xpath("//div[@data-title='Test Album']//div[@class='item album-images-link']")))); + System.out.println(7); + driver.findElement(By.xpath("//div[@data-title='Test Album']//div[@class='item album-images-link']")).click(); + driver.findElement(By.xpath("//div[@id='images-menu']/div[1]")).click(); + driver.findElement(By.id("MNhewWN")).click(); + driver.findElement(By.name("submit")).click(); + driver.quit(); + String verificationErrorString = verificationErrors.toString(); + if (!"".equals(verificationErrorString)) { + fail(verificationErrorString); + } + } + + + private void login() { + driver.get(baseUrl + "/signin"); + driver.findElement(By.id("username")).sendKeys("cs1699testing"); + driver.findElement(By.id("password")).sendKeys("laboontesting"); + driver.findElement(By.name("submit")).click(); + } + + public void logout() { + WebElement hoverElement = driver.findElement(By.id("secondary-nav")); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@class='dropdown-footer']//a[contains(text(),'logout')]")).click(); + } + +} diff --git a/src/DeleteImage.java b/src/DeleteImage.java new file mode 100644 index 0000000..6b2b9d0 --- /dev/null +++ b/src/DeleteImage.java @@ -0,0 +1,80 @@ +package tests; + +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.junit.*; + +import static org.junit.Assert.*; + +import org.openqa.selenium.*; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class DeleteImage { + private WebDriver driver; + private String baseUrl; + private StringBuffer verificationErrors = new StringBuffer(); + private String imageToRemove; + + @Before + public void setUp() throws Exception { + driver = new FirefoxDriver(); + baseUrl = "http://imgur.com"; + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + login(); + StringSelection selection = new StringSelection("http://i.imgur.com/xY3TaEV.png"); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(selection, selection); + + driver.findElement(By.className("upload-button")).click(); + WebElement textArea = driver.findElement(By.id("upload-global-link-input")); + new Actions( driver ).contextClick(textArea).sendKeys( "p" ).perform(); + driver.findElement(By.id("upload-global-start-button")).submit(); + WebElement nicetime = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("nicetime"))); + String code = driver.getCurrentUrl().substring(17); + imageToRemove = code; + driver.get("http://cs1699testing.imgur.com/all"); + } + + @Test + public void testDeleteImage() throws Exception { + driver.get("http://cs1699testing.imgur.com/all/"); + WebElement hoverElement = driver.findElement(By.id(imageToRemove)); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.cssSelector("#" + imageToRemove + " > div:nth-child(3) > div:nth-child(2)")).click(); + driver.findElement(By.id("delete-button")).click(); + driver.get("http://cs1699testing.imgur.com/all/"); + List list = driver.findElements(By.id(imageToRemove)); + assertTrue(list.size() == 0); + } + + @After + public void tearDown() throws Exception { + driver.quit(); + String verificationErrorString = verificationErrors.toString(); + if (!"".equals(verificationErrorString)) { + fail(verificationErrorString); + } + } + + private void login() { + driver.get(baseUrl + "/signin"); + driver.findElement(By.id("username")).sendKeys("cs1699testing"); + driver.findElement(By.id("password")).sendKeys("laboontesting"); + driver.findElement(By.name("submit")).click(); + } + + public void logout() { + WebElement hoverElement = driver.findElement(By.id("secondary-nav")); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@class='dropdown-footer']//a[contains(text(),'logout')]")).click(); + } +} diff --git a/src/Favorites.java b/src/Favorites.java new file mode 100644 index 0000000..f7bfa12 --- /dev/null +++ b/src/Favorites.java @@ -0,0 +1,61 @@ +package tests; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.junit.*; + +import static org.junit.Assert.*; + +import org.openqa.selenium.*; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; + +public class Favorites { + private WebDriver driver; + private String baseUrl; + private StringBuffer verificationErrors = new StringBuffer(); + + @Before + public void setUp() throws Exception { + driver = new FirefoxDriver(); + baseUrl = "http://imgur.com"; + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); + } + + @Test + public void testFavorite() throws Exception { + login(); + driver.get("http://imgur.com/HegrNXq"); + driver.findElement(By.cssSelector(".favorite-image")).click(); + driver.get("https://imgur.com/user/cs1699testing/favorites"); + List list = driver.findElements(By.xpath("//a[@href='/user/cs1699testing/favorites/HegrNXq']")); + assertTrue(list.size() > 0); + logout(); + } + @After + public void tearDown() throws Exception { + login(); + driver.get("http://imgur.com/HegrNXq"); + driver.findElement(By.cssSelector(".favorite-image")).click(); + driver.quit(); + String verificationErrorString = verificationErrors.toString(); + if (!"".equals(verificationErrorString)) { + fail(verificationErrorString); + } + } + + private void login() { + driver.get(baseUrl + "/signin"); + driver.findElement(By.id("username")).sendKeys("cs1699testing"); + driver.findElement(By.id("password")).sendKeys("laboontesting"); + driver.findElement(By.name("submit")).click(); + } + + public void logout() { + WebElement hoverElement = driver.findElement(By.id("secondary-nav")); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@class='dropdown-footer']//a[contains(text(),'logout')]")).click(); + } +} diff --git a/src/LoginFirst.java b/src/LoginFirst.java new file mode 100644 index 0000000..4c64955 --- /dev/null +++ b/src/LoginFirst.java @@ -0,0 +1,91 @@ +package tests; + +import java.util.concurrent.TimeUnit; + + +import org.junit.*; + +import static org.junit.Assert.*; + +import org.openqa.selenium.*; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; + +public class LoginFirst { + private WebDriver driver; + private String baseUrl; + private StringBuffer verificationErrors = new StringBuffer(); + + @Before + public void setUp() throws Exception { + driver = new FirefoxDriver(); + baseUrl = "http://imgur.com"; + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); + login(); + } + + @Test + public void testLogout() throws Exception { + logout(); + try { + WebElement loginLink = driver.findElement(By.xpath("//li[@class='signin-link']")); + assertTrue(loginLink != null); + } + catch(NoSuchElementException nsee) { + fail("No element found: " + nsee.toString()); + } + } + + + @Test + public void testTitleChange() throws Exception { + driver.get("http://cs1699testing.imgur.com/all"); + driver.findElement(By.cssSelector("#MNhewWN > a:nth-child(1)")).click(); + driver.findElement(By.cssSelector(".js-edit-title")).click(); + driver.findElement(By.cssSelector("#title-input")).clear(); + String newTitle = "" + System.currentTimeMillis(); + driver.findElement(By.cssSelector("#title-input")).sendKeys(newTitle); + driver.findElement(By.cssSelector("#title-description-button")).click(); + driver.get("http://cs1699testing.imgur.com/all"); + driver.findElement(By.cssSelector("#MNhewWN > a:nth-child(1)")).click(); + String title = driver.findElement(By.cssSelector("#info-image-title")).getText(); + assertTrue(title.equals(newTitle)); + } + + @Test + public void testComment() throws Exception { + driver.get("http://imgur.com/gallery/eK94abP"); + String xpath_val = "//div[@class='author']//a[contains(text(),'cs1699testing')]"; + int numCommentsBefore = driver.findElements(By.xpath(xpath_val)).size(); + long currTime = System.currentTimeMillis(); + driver.findElement(By.cssSelector("#caption_textarea")).sendKeys("" + currTime); + driver.findElement(By.cssSelector(".submit-caption-button")).click(); + driver.get("http://imgur.com/gallery/eK94abP"); + int numCommentsAfter = driver.findElements(By.xpath(xpath_val)).size(); + assertTrue(numCommentsBefore < numCommentsAfter); + } + + @After + public void tearDown() throws Exception { + driver.quit(); + String verificationErrorString = verificationErrors.toString(); + if (!"".equals(verificationErrorString)) { + fail(verificationErrorString); + } + } + + + private void login() { + driver.get(baseUrl + "/signin"); + driver.findElement(By.id("username")).sendKeys("cs1699testing"); + driver.findElement(By.id("password")).sendKeys("laboontesting"); + driver.findElement(By.name("submit")).click(); + } + + public void logout() { + WebElement hoverElement = driver.findElement(By.id("secondary-nav")); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@class='dropdown-footer']//a[contains(text(),'logout')]")).click(); + } +} diff --git a/src/NewAlbum.java b/src/NewAlbum.java new file mode 100644 index 0000000..19d7f87 --- /dev/null +++ b/src/NewAlbum.java @@ -0,0 +1,83 @@ +package tests; + +import java.util.concurrent.TimeUnit; + + +import org.junit.*; + +import static org.junit.Assert.*; + +import org.openqa.selenium.*; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class NewAlbum { + private WebDriver driver; + private String baseUrl; + private StringBuffer verificationErrors = new StringBuffer(); + private String albumTitle; + + @Before + public void setUp() throws Exception { + driver = new FirefoxDriver(); + baseUrl = "http://imgur.com"; + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); + login(); + } + + + + @Test + public void testNewAlbum() throws Exception { + // Get the album page + driver.get("http://cs1699testing.imgur.com/"); + driver.findElement(By.cssSelector(".album-create-link")).click(); + String currTime = "" + System.currentTimeMillis(); + albumTitle = currTime; + driver.findElement(By.cssSelector("#album-title")).sendKeys(currTime); + driver.findElement(By.xpath("//div[@id='create-album-form']//input[@type='submit' and @class='button-medium']")).click(); + driver.get("http://cs1699testing.imgur.com/"); + WebElement newAlbum = driver.findElement(By.xpath("//div[@data-title='" + currTime + "']")); + assertTrue(newAlbum != null); + logout(); + } + + @After + public void tearDown() throws Exception { + login(); + //Clean up: Delete the album we just created + driver.get("http://cs1699testing.imgur.com/"); + WebElement hoverElement = driver.findElement(By.xpath("//div[@data-title='" + albumTitle + "']")); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@data-title='" + albumTitle + "']/div[4]")).click(); + new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(driver + .findElement(By.cssSelector("div.item.album-delete-link")))); + + driver.findElement(By.cssSelector("div.item.album-delete-link")).click(); + driver.findElement(By.id("delete-album-yes")).click(); + + driver.quit(); + String verificationErrorString = verificationErrors.toString(); + if (!"".equals(verificationErrorString)) { + fail(verificationErrorString); + } + } + + + private void login() { + driver.get(baseUrl + "/signin"); + driver.findElement(By.id("username")).sendKeys("cs1699testing"); + driver.findElement(By.id("password")).sendKeys("laboontesting"); + driver.findElement(By.name("submit")).click(); + } + + public void logout() { + WebElement hoverElement = driver.findElement(By.id("secondary-nav")); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@class='dropdown-footer']//a[contains(text(),'logout')]")).click(); + } +} diff --git a/src/webtests.java b/src/NoSetup.java similarity index 68% rename from src/webtests.java rename to src/NoSetup.java index b2029d4..7dfb534 100644 --- a/src/webtests.java +++ b/src/NoSetup.java @@ -1,3 +1,5 @@ +package tests; + import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; @@ -6,25 +8,58 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import javax.imageio.ImageIO; -import org.openqa.selenium.*; import org.junit.*; import static org.junit.Assert.*; +import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; -//Test Image -//http://i.imgur.com/xY3TaEV.png +public class NoSetup { + private WebDriver driver; + private String baseUrl; + private StringBuffer verificationErrors = new StringBuffer(); + @Before + public void setUp() throws Exception { + driver = new FirefoxDriver(); + baseUrl = "http://imgur.com"; + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); + } -public class webtests { - WebDriver driver = new FirefoxDriver(); - + @Test + public void testSearch() throws Exception { + driver.get(baseUrl + "/"); + driver.findElement(By.cssSelector("div.search-icon-container-icon")).click(); + driver.findElement(By.name("q")).clear(); + driver.findElement(By.name("q")).sendKeys("funny"); + driver.findElement(By.xpath("//form[@class=\"search-form\"]")).submit(); + driver.findElement(By.cssSelector("a.image-list-link > img")).click(); + driver.findElement(By.cssSelector("#tags-underbar > span")).click(); + List list = driver.findElements(By.xpath("//*[contains(text(),'" + "funny" + "')]")); + // Warning: verifyTextPresent may require manual changes + try { + assertTrue(list.size() > 0); + } catch (Error e) { + verificationErrors.append(e.toString()); + } + // ERROR: Caught exception [unknown command []] + } + + @Test + public void testLogin() throws Exception { + login(); + String accountName = driver.findElement(By.xpath("//a[@class='account-user-name']")).getText(); + assertTrue(accountName.equals("cs1699testing")); + } + @Test public void HomePagePictures() throws Exception { driver.get("http://imgur.com/"); @@ -32,12 +67,11 @@ public void HomePagePictures() throws Exception { List posts = driver.findElements(By.className("post")); List ids = new ArrayList(); for ( WebElement post: posts) { - System.out.println(post.getAttribute("id")); if(ids.contains(post.getAttribute("id"))){ - dups = false; + dups = false; } else{ - ids.add(post.getAttribute("id")); + ids.add(post.getAttribute("id")); } } Assert.assertTrue(dups); @@ -53,7 +87,6 @@ public void ShowSidebar() throws Exception { test.click(); test = driver.findElement(By.id("outside-tagging")); String opacity = test.getAttribute("style"); - System.out.println(opacity); Assert.assertEquals(opacity,"opacity: 1;"); driver.quit(); } @@ -66,17 +99,15 @@ public void UploadTest() throws Exception { clipboard.setContents(selection, selection); driver.get("http://imgur.com/"); driver.findElement(By.className("upload-button")).click(); - driver.findElement(By.id("upload-global-link-input")).sendKeys(Keys.COMMAND + "v"); + WebElement textArea = driver.findElement(By.id("upload-global-link-input")); + new Actions( driver ).contextClick(textArea).sendKeys( "p" ).perform(); driver.findElement(By.id("upload-global-start-button")).submit(); WebElement nicetime = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("nicetime"))); driver.getCurrentUrl(); String code = driver.getCurrentUrl().substring(17); - System.out.println(code); driver.get("http://i.imgur.com/"+code+".png"); String s = driver.findElement(By.className("shrinkToFit")).getAttribute("src"); - System.out.println(s); URL url = new URL(s); - System.out.println(url); BufferedImage link = ImageIO.read(url); BufferedImage base = ImageIO.read(new File("base.png")); Assert.assertTrue(imagesAreEqual(link,base)); @@ -91,7 +122,8 @@ public void TimeStampTest() throws Exception { clipboard.setContents(selection, selection); driver.get("http://imgur.com/"); driver.findElement(By.className("upload-button")).click(); - driver.findElement(By.id("upload-global-link-input")).sendKeys(Keys.COMMAND + "v"); + WebElement textArea = driver.findElement(By.id("upload-global-link-input")); + new Actions( driver ).contextClick(textArea).sendKeys( "p" ).perform(); driver.findElement(By.id("upload-global-start-button")).submit(); WebElement nicetime = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("nicetime"))); String time1 = nicetime.getText(); @@ -100,9 +132,7 @@ public void TimeStampTest() throws Exception { driver.get(pageurl); nicetime = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("nicetime"))); String time2 = nicetime.getText(); - System.out.println(time1); - System.out.println(time2); - Assert.assertFalse(time1.equals(time2)); + Assert.assertFalse(time1.equals(time2)); driver.quit(); } @@ -113,11 +143,9 @@ public void BrowseTest() throws Exception { WebElement test; test = driver.findElement(By.className("post")); String PostName = test.getAttribute("id"); - System.out.println(PostName); test = test.findElement(By.className("image-list-link")); test.click(); String currurl = driver.getCurrentUrl(); - System.out.println(currurl); Assert.assertEquals(currurl,"http://imgur.com/gallery/"+PostName); driver.quit(); } @@ -150,9 +178,7 @@ public void RandomTest2() throws Exception { public void ImageCheck() throws Exception { driver.get("http://i.imgur.com/FkVYvno.png"); String s = driver.findElement(By.className("shrinkToFit")).getAttribute("src"); - System.out.println(s); URL url = new URL(s); - System.out.println(url); BufferedImage link = ImageIO.read(url); BufferedImage base = ImageIO.read(new File("base.png")); Assert.assertTrue(imagesAreEqual(link,base)); @@ -175,20 +201,39 @@ public void ScrollCheck() throws Exception { WebElement test; test = driver.findElement(By.id("content")); Dimension orignal = test.getSize(); - System.out.println(orignal); Thread.sleep(3000); JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,2566)", ""); Thread.sleep(3000); test = driver.findElement(By.id("content")); Dimension scroll = test.getSize(); - System.out.println(scroll); Assert.assertTrue((orignal.getHeight()!= scroll.getHeight())&&(orignal.getWidth()==scroll.getWidth())); driver.quit(); } - - - + + @After + public void tearDown() throws Exception { + driver.quit(); + String verificationErrorString = verificationErrors.toString(); + if (!"".equals(verificationErrorString)) { + fail(verificationErrorString); + } + } + + private void login() { + driver.get(baseUrl + "/signin"); + driver.findElement(By.id("username")).sendKeys("cs1699testing"); + driver.findElement(By.id("password")).sendKeys("laboontesting"); + driver.findElement(By.name("submit")).click(); + } + + public void logout() { + WebElement hoverElement = driver.findElement(By.id("secondary-nav")); + Actions builder = new Actions(driver); + builder.moveToElement(hoverElement).perform(); + driver.findElement(By.xpath("//div[@class='dropdown-footer']//a[contains(text(),'logout')]")).click(); + } + //Helper function to compare image buffers public boolean imagesAreEqual(BufferedImage image1, BufferedImage image2) { if (image1.getWidth() != image2.getWidth() || image1.getHeight() != image2.getHeight()) { @@ -201,10 +246,6 @@ public boolean imagesAreEqual(BufferedImage image1, BufferedImage image2) { } } } - return true; + return true; } - - } - -