Commits

Vineet Reynolds  committed 96b458f

Added Selenium tests for editing and deletion of photos. Modified the facelet tag for displaying INFO/ERROR messages in the EditPhoto page.

  • Participants
  • Parent commits 6cb16a7

Comments (0)

Files changed (5)

File galleria-jsf/src/main/webapp/private/photo/EditPhoto.xhtml

 			    	</li>
 			    </ul>
 		    </h:form>
-		    <h:messages globalOnly="true" />
+		    <h:messages id="messages" showSummary="true" showDetail="false" infoClass="infoStyle"
+				warnClass="warnStyle" errorClass="errorStyle" />
 		</div>
 	</ui:define>
 </ui:composition>

File galleria-jsf/src/test/java/info/galleria/view/AllPagesIntegrationTest.java

 import static org.junit.Assert.*;
 
 import info.galleria.view.album.*;
-import info.galleria.view.photo.UploadPhotoPage;
+import info.galleria.view.photo.*;
 import info.galleria.view.user.*;
 
 import java.io.File;
 		String[] errorMessages = { "A duplicate photo was found in the album." };
 		assertArrayEquals(errorMessages, uploadPhotoPage.fetchErrorMessages());
 	}
+	
+	@Test
+	public void testEditPhoto() throws Exception
+	{
+		String albumName = "Album#1";
+		String albumDescription = "My first album";
+		String photoTitle = "Photo#1";
+		String photoDescription = "My first photo";
+		String newPhotoTitle = "Photo No.1";
+		String newPhotoDescription = "First photo";
+		String filePath = this.getClass().getClassLoader().getResource("TestPhoto.png").toExternalForm();
+
+		driver.get(contextPath.toString());
+		IndexPage indexPage = new IndexPage(driver, contextPath);
+		SignupPage signupPage = indexPage.chooseToSignup();
+		indexPage = signupPage.signupAs("User#1", "password");
+		String[] message = { "The new user account has been created. You may now login." };
+		assertArrayEquals(message, indexPage.fetchSuccessMessages());
+
+		LoginPage loginPage = indexPage.chooseToLogin();
+		HomePage homePage = loginPage.loginAs("User#1", "password");
+		CreateAlbumPage createAlbumPage = homePage.goToCreateAlbum();
+		homePage = createAlbumPage.createAlbumAs(albumName, albumDescription);
+		String[] messages = { "The album was created successfully." };
+		assertArrayEquals(messages, homePage.fetchSuccessMessages());
+
+		UploadPhotoPage uploadPhotoPage = homePage.goToUploadPhoto();
+		ViewAlbumPage viewAlbumPage = uploadPhotoPage.uploadAs(photoTitle, photoDescription, filePath);
+		String[] uploadMessages = { "The file was uploaded successfully." };
+		assertArrayEquals(uploadMessages, viewAlbumPage.fetchSuccessMessages());
+
+		ViewPhotoPage viewPhotoPage = viewAlbumPage.viewPhotoWith(photoTitle, photoDescription);
+		EditPhotoPage editPhotoPage = viewPhotoPage.goToEditPhoto();
+		viewPhotoPage = editPhotoPage.editPhotoAs(newPhotoTitle, newPhotoDescription);
+		String[] editMessages = { "The photo was edited successfully." };
+		assertArrayEquals(editMessages, viewPhotoPage.fetchSuccessMessages());
+	}
+	
+	@Test
+	public void testEditPhotoWithExcessiveValues() throws Exception
+	{
+		String albumName = "Album#1";
+		String albumDescription = "My first album";
+		String photoTitle = "Photo#1";
+		String photoDescription = "My first photo";
+		String newPhotoTitle = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+		String newPhotoDescription = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+		String filePath = this.getClass().getClassLoader().getResource("TestPhoto.png").toExternalForm();
+
+		driver.get(contextPath.toString());
+		IndexPage indexPage = new IndexPage(driver, contextPath);
+		SignupPage signupPage = indexPage.chooseToSignup();
+		indexPage = signupPage.signupAs("User#1", "password");
+		String[] message = { "The new user account has been created. You may now login." };
+		assertArrayEquals(message, indexPage.fetchSuccessMessages());
+
+		LoginPage loginPage = indexPage.chooseToLogin();
+		HomePage homePage = loginPage.loginAs("User#1", "password");
+		CreateAlbumPage createAlbumPage = homePage.goToCreateAlbum();
+		homePage = createAlbumPage.createAlbumAs(albumName, albumDescription);
+		String[] messages = { "The album was created successfully." };
+		assertArrayEquals(messages, homePage.fetchSuccessMessages());
+
+		UploadPhotoPage uploadPhotoPage = homePage.goToUploadPhoto();
+		ViewAlbumPage viewAlbumPage = uploadPhotoPage.uploadAs(photoTitle, photoDescription, filePath);
+		String[] uploadMessages = { "The file was uploaded successfully." };
+		assertArrayEquals(uploadMessages, viewAlbumPage.fetchSuccessMessages());
+
+		ViewPhotoPage viewPhotoPage = viewAlbumPage.viewPhotoWith(photoTitle, photoDescription);
+		EditPhotoPage editPhotoPage = viewPhotoPage.goToEditPhoto();
+		editPhotoPage = editPhotoPage.editPhotoAsExpectingError(newPhotoTitle, newPhotoDescription);
+		String[] errorMessages = { "The title should be between 0 and 255 characters in length.",
+				"The description should be between 0 and 255 characters in length." };
+		assertArrayEquals(errorMessages, editPhotoPage.fetchErrorMessages());
+	}
+	
+	@Test
+	public void testDeletePhoto() throws Exception
+	{
+		String albumName = "Album#1";
+		String albumDescription = "My first album";
+		String photoTitle = "Photo#1";
+		String photoDescription = "My first photo";
+		String filePath = this.getClass().getClassLoader().getResource("TestPhoto.png").toExternalForm();
+
+		driver.get(contextPath.toString());
+		IndexPage indexPage = new IndexPage(driver, contextPath);
+		SignupPage signupPage = indexPage.chooseToSignup();
+		indexPage = signupPage.signupAs("User#1", "password");
+		String[] message = { "The new user account has been created. You may now login." };
+		assertArrayEquals(message, indexPage.fetchSuccessMessages());
+
+		LoginPage loginPage = indexPage.chooseToLogin();
+		HomePage homePage = loginPage.loginAs("User#1", "password");
+		CreateAlbumPage createAlbumPage = homePage.goToCreateAlbum();
+		homePage = createAlbumPage.createAlbumAs(albumName, albumDescription);
+		String[] messages = { "The album was created successfully." };
+		assertArrayEquals(messages, homePage.fetchSuccessMessages());
+
+		UploadPhotoPage uploadPhotoPage = homePage.goToUploadPhoto();
+		ViewAlbumPage viewAlbumPage = uploadPhotoPage.uploadAs(photoTitle, photoDescription, filePath);
+		String[] uploadMessages = { "The file was uploaded successfully." };
+		assertArrayEquals(uploadMessages, viewAlbumPage.fetchSuccessMessages());
+
+		ViewPhotoPage viewPhotoPage = viewAlbumPage.viewPhotoWith(photoTitle, photoDescription);
+		viewAlbumPage = viewPhotoPage.deletePhoto();
+		String[] deleteMessages = { "The photo was deleted successfully." };
+		assertArrayEquals(deleteMessages, viewAlbumPage.fetchSuccessMessages());
+	}
+	
 }

File galleria-jsf/src/test/java/info/galleria/view/album/ViewAlbumPage.java

 package info.galleria.view.album;
 
 import info.galleria.view.PageUtilities;
-import info.galleria.view.photo.UploadPhotoPage;
+import info.galleria.view.photo.*;
 import info.galleria.view.user.HomePage;
 
 import java.net.URI;
 		return new UploadPhotoPage(driver, contextPath);
 	}
 
+	public ViewPhotoPage viewPhotoWith(String photoTitle, String photoDescription)
+	{
+		List<WebElement> photoWrappers = driver.findElements(By.xpath("//ul[@class='photoWrapper']"));
+		for (WebElement element : photoWrappers)
+		{
+			WebElement name = element.findElement(By.className("name"));
+			WebElement description = element.findElement(By.className("description"));
+			if (name.getText().equals(photoTitle) && description.getText().equals(photoDescription))
+			{
+				element.findElement(By.className("photolink")).click();
+				return new ViewPhotoPage(driver, contextPath);
+			}
+		}
+		return null;
+	}
+
 	public String[] fetchSuccessMessages()
 	{
 		List<String> messages = new ArrayList<String>();
 		}
 		return messages.toArray(new String[0]);
 	}
+
 }

File galleria-jsf/src/test/java/info/galleria/view/photo/EditPhotoPage.java

+package info.galleria.view.photo;
+
+import info.galleria.view.PageUtilities;
+
+import java.net.URI;
+import java.util.*;
+
+import org.openqa.selenium.*;
+import org.openqa.selenium.support.ui.*;
+
+public class EditPhotoPage
+{
+
+	private WebDriver driver;
+	private URI contextPath;
+
+	public EditPhotoPage(WebDriver driver, URI contextPath)
+	{
+		this.driver = driver;
+		this.contextPath = contextPath;
+		Wait<WebDriver> wait = new WebDriverWait(driver, 15);
+		wait.until(PageUtilities.visibilityOfElementLocated(By.id("wrapper")));
+		if (!driver.getTitle().equals("Edit a photo"))
+		{
+			throw new IllegalStateException("This is not the Edit Photo page.");
+		}
+	}
+
+	public ViewPhotoPage editPhotoAs(String photoTitle, String photoDescription)
+	{
+		driver.findElement(By.id("editPhotoForm:photoTitle")).clear();
+		driver.findElement(By.id("editPhotoForm:photoTitle")).sendKeys(photoTitle);
+		driver.findElement(By.id("editPhotoForm:photoDescription")).clear();
+		driver.findElement(By.id("editPhotoForm:photoDescription")).sendKeys(photoDescription);
+		driver.findElement(By.id("editPhotoForm:editPhotoButton")).click();
+		return new ViewPhotoPage(driver, contextPath);
+	}
+
+	public EditPhotoPage editPhotoAsExpectingError(String photoTitle, String photoDescription)
+	{
+		driver.findElement(By.id("editPhotoForm:photoTitle")).clear();
+		driver.findElement(By.id("editPhotoForm:photoTitle")).sendKeys(photoTitle);
+		driver.findElement(By.id("editPhotoForm:photoDescription")).clear();
+		driver.findElement(By.id("editPhotoForm:photoDescription")).sendKeys(photoDescription);
+		driver.findElement(By.id("editPhotoForm:editPhotoButton")).click();
+		return new EditPhotoPage(driver, contextPath);
+	}
+
+	public String[] fetchErrorMessages()
+	{
+		List<String> messages = new ArrayList<String>();
+		for (WebElement element : driver.findElements(By.xpath("//ul[@id='messages']/li[@class='errorStyle']")))
+		{
+			messages.add(element.getText());
+		}
+		return messages.toArray(new String[0]);
+	}
+
+}

File galleria-jsf/src/test/java/info/galleria/view/photo/ViewPhotoPage.java

+package info.galleria.view.photo;
+
+import info.galleria.view.PageUtilities;
+import info.galleria.view.album.ViewAlbumPage;
+
+import java.net.URI;
+import java.util.*;
+
+import org.openqa.selenium.*;
+import org.openqa.selenium.support.ui.*;
+
+public class ViewPhotoPage
+{
+
+	private WebDriver driver;
+	private URI contextPath;
+
+	public ViewPhotoPage(WebDriver driver, URI contextPath)
+	{
+		this.driver = driver;
+		this.contextPath = contextPath;
+		Wait<WebDriver> wait = new WebDriverWait(driver, 15);
+		wait.until(PageUtilities.visibilityOfElementLocated(By.id("wrapper")));
+		if (!driver.getTitle().equals("View a photo"))
+		{
+			throw new IllegalStateException("This is not the View Photo page.");
+		}
+	}
+
+	public EditPhotoPage goToEditPhoto()
+	{
+		driver.findElement(By.id("editPhotoLink")).click();
+		return new EditPhotoPage(driver, contextPath);
+	}
+
+	public ViewAlbumPage deletePhoto()
+	{
+		driver.findElement(By.id("deletePhotoForm:deletePhotoButton")).click();
+		return new ViewAlbumPage(driver, contextPath);
+	}
+
+	public String[] fetchSuccessMessages()
+	{
+		List<String> messages = new ArrayList<String>();
+		for (WebElement element : driver.findElements(By.xpath("//ul[@id='messages']/li[@class='infoStyle']")))
+		{
+			messages.add(element.getText());
+		}
+		return messages.toArray(new String[0]);
+	}
+
+}