Skip to content

Commit

Permalink
test organization
Browse files Browse the repository at this point in the history
  • Loading branch information
angiejones committed Jan 9, 2019
1 parent b55cf53 commit 73d97b1
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 43 deletions.
3 changes: 2 additions & 1 deletion resources/test.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
################
# MY APP #
################
site.bookstore.url=file:///Users/angie/workspace/test_automation_u/visual_validation_course/website/index.html
site.bookstore.url=file:///Users/angie/workspace/automated_visual_validation/website/index.html
site.largedom.url=https://the-internet.herokuapp.com/large
site.dynamic.url=https://the-internet.herokuapp.com/dynamic_content
site.frames.url=https://the-internet.herokuapp.com/nested_frames
sites.tables.url=https://the-internet.herokuapp.com/tables

################
# SELENIUM #
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/DynamicTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

public class DynamicTests extends BaseTests {

private String APP_NAME = "The Internet";

@Test
public void testDynamicContent(){
driver.get(System.getProperty("site.dynamic.url"));
eyes.setMatchLevel(MatchLevel.LAYOUT);
validateWindow(APP_NAME);
eyesManager.getEyes().setMatchLevel(MatchLevel.LAYOUT);
eyesManager.validateWindow();
}
}
5 changes: 2 additions & 3 deletions src/test/java/ScrollTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

public class ScrollTests extends BaseTests {

private String APP_NAME = "The Internet";

@Test
public void testLargeDom() {
driver.get(System.getProperty("site.largedom.url"));
validateWindow(APP_NAME);
eyesManager.getEyes().setForceFullPageScreenshot(true);
eyesManager.validateWindow();
}
}
5 changes: 2 additions & 3 deletions src/test/java/SearchTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

public class SearchTests extends BaseTests {

private String APP_NAME = "Automation Bookstore";
private SearchPage page = new SearchPage(driver);

@BeforeClass
Expand All @@ -19,14 +18,14 @@ public static void launchApp(){
public void testSearchByFullTitle(){
String title = "Agile Testing";
page.search(title);
validateWindow(APP_NAME);
eyesManager.validateWindow();
}

@Test
public void testSearchByFullTitle_Element(){
String title = "Agile Testing";
page.search(title);
validateElement(By.id("pid3"));
eyesManager.validateElement(By.id("pid3"));
Assert.assertEquals("Number of books returned",
1, page.getNumberOfVisibleBooks());
}
Expand Down
40 changes: 37 additions & 3 deletions src/test/java/TheInternetTests.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
import base.BaseTests;
import org.junit.BeforeClass;
import org.junit.Test;
import pages.SortableDataTablesPage;

public class TheInternetTests extends BaseTests {

private SortableDataTablesPage page = new SortableDataTablesPage(driver);

@BeforeClass
public static void startVisualTestSuite(){
eyesManager.setBatchName("Sort Table");
driver.get(System.getProperty("sites.tables.url"));
}

@Test
public void testSortByLastName(){
page.sortLastNameColumn();
eyesManager.validateElement(page.getTableElementLocator());
}

@Test
public void testSortByFirstName(){
page.sortFirstNameColumn();
eyesManager.validateElement(page.getTableElementLocator());
}

@Test
public void testSortByEmail(){
page.sortEmailColumn();
eyesManager.validateElement(page.getTableElementLocator());
}

@Test
public void testSortByDueDate(){
page.sortDueColumn();
eyesManager.validateElement(page.getTableElementLocator());
}

@Test
public void testBottomFrame(){
driver.get(System.getProperty("site.frames.url"));
validateFrame("frame-bottom");
public void testSortByWebsite(){
page.sortWebsiteColumn();
eyesManager.validateElement(page.getTableElementLocator());
}
}
34 changes: 5 additions & 29 deletions src/test/java/base/BaseTests.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package base;

import com.applitools.eyes.selenium.Eyes;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
Expand All @@ -15,7 +15,7 @@
public class BaseTests {

protected static WebDriver driver;
protected static Eyes eyes;
protected static EyesManager eyesManager;

@BeforeClass
public static void setUp() {
Expand All @@ -28,37 +28,13 @@ public static void setUp() {
}

driver = new ChromeDriver();
initiateEyes();
eyesManager = new EyesManager(driver, "The Internet");
}

@AfterClass
public static void tearDown() {
driver.quit();
eyes.abortIfNotClosed();
}

private static void initiateEyes(){
eyes = new Eyes();
eyes.setApiKey(System.getProperty("applitools.api.key"));
}

public void validateWindow(String appName){
eyes.open(driver, appName, Thread.currentThread().getStackTrace()[2].getMethodName());
eyes.setForceFullPageScreenshot(true);
eyes.checkWindow();
eyes.close();
}

public void validateElement(By locator){
eyes.open(driver, "Automation Bookstore", Thread.currentThread().getStackTrace()[2].getMethodName());
eyes.checkElement(locator);
eyes.close();
}

public void validateFrame(String locator){
eyes.open(driver, "The Internet", Thread.currentThread().getStackTrace()[2].getMethodName());
eyes.checkFrame(locator);
eyes.close();
eyesManager.abort();
}

}
55 changes: 55 additions & 0 deletions src/test/java/base/EyesManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package base;

import com.applitools.eyes.BatchInfo;
import com.applitools.eyes.selenium.Eyes;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class EyesManager {

private Eyes eyes;
private String appName;
private WebDriver driver;

public EyesManager(WebDriver driver, String appName){
this.driver = driver;
this.appName = appName;

eyes = new Eyes();
eyes.setApiKey(System.getProperty("applitools.api.key"));
}

public void setBatchName(String batchName){
eyes.setBatch(new BatchInfo(batchName));
}

public void setTestGroup(String group){
eyes.addProperty("Test Group", group);
}

public void validateWindow(){
eyes.open(driver, appName, Thread.currentThread().getStackTrace()[2].getMethodName());
eyes.checkWindow();
eyes.close();
}

public void validateElement(By locator){
eyes.open(driver, appName, Thread.currentThread().getStackTrace()[2].getMethodName());
eyes.checkElement(locator);
eyes.close();
}

public void validateFrame(String locator){
eyes.open(driver, appName, Thread.currentThread().getStackTrace()[2].getMethodName());
eyes.checkFrame(locator);
eyes.close();
}

public void abort(){
eyes.abortIfNotClosed();
}

public Eyes getEyes(){
return eyes;
}
}

0 comments on commit 73d97b1

Please sign in to comment.