-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1d9fdb
commit 795f1cb
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |