Skip to content

Commit

Permalink
adding first test
Browse files Browse the repository at this point in the history
  • Loading branch information
angiejones committed Jan 9, 2019
1 parent f1d9fdb commit 795f1cb
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/main/java/pages/SearchPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package pages;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

public class SearchPage {
private WebDriver driver;
private By searchBar = By.id("searchBar");
private By visibleBooks =
By.xpath("//li[not(contains(@class, 'ui-screen-hidden'))]");
private By hiddenBooks =
By.xpath("//li[contains(@class, 'ui-screen-hidden')]");

public SearchPage(WebDriver driver){
this.driver = driver;
}

public void search(String text) {
search(text, true);
}

public void search(String text, boolean waitForHidden) {
clearSearch();
driver.findElement(searchBar).sendKeys(text);

if(waitForHidden) {
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(presenceOfElementLocated(hiddenBooks));
}
}

public void clearSearch() {
driver.findElement(searchBar).clear();
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(numberOfElementsToBe(hiddenBooks, 0));
}

public int getNumberOfVisibleBooks() {
return findVisibleBooks().size();
}

private List<WebElement> findVisibleBooks(){
return driver.findElements(visibleBooks);
}
}
12 changes: 12 additions & 0 deletions src/test/java/SearchTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import base.BaseTests;
import org.junit.Test;

public class SearchTests extends BaseTests {

@Test
public void testSearchByFullTitle(){
String title = "Agile Testing";
page.search(title);
validateWindow();
}
}
57 changes: 57 additions & 0 deletions src/test/java/base/BaseTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package base;

import com.applitools.eyes.selenium.Eyes;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import pages.SearchPage;
import pages.SortableDataTablesPage;

public class BaseTests {

protected static WebDriver driver;
protected static SearchPage page;
protected static Eyes eyes;

@BeforeClass
public static void setUp() {
Properties props = System.getProperties();
try {
props.load(new FileInputStream(new File("resources/test.properties")));
} catch(Exception e) {
e.printStackTrace();
System.exit(-1);
}

driver = new ChromeDriver();
initiateEyes();

driver.get(System.getProperty("site.url"));
page = new SearchPage(driver);
}

@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(){
eyes.open(driver, "Automation Bookstore",
Thread.currentThread().getStackTrace()[2].getMethodName());
eyes.checkWindow();
eyes.close();
}
}

0 comments on commit 795f1cb

Please sign in to comment.