From 47131f1fb777c3ecbf087dbf67bbc9dcb8948046 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 23 May 2019 13:43:18 +0400 Subject: [PATCH] #103 add tests for papers --- src/test/java/IndexGrantTest.java | 30 ++++++++++++++++++++++- src/test/java/grant/GrantPage.java | 38 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/test/java/IndexGrantTest.java b/src/test/java/IndexGrantTest.java index 064b2c7..c633cfa 100644 --- a/src/test/java/IndexGrantTest.java +++ b/src/test/java/IndexGrantTest.java @@ -81,7 +81,6 @@ public class IndexGrantTest extends TestTemplate { @Test public void deleteGrant() throws InterruptedException { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -89,4 +88,33 @@ public class IndexGrantTest extends TestTemplate { grantsPage.deleteFirst(); Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); } + + @Test + public void attachPaper() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + Integer countPapers = grantPage.getAttachedPapers().size(); + + Assert.assertEquals(countPapers + 1, grantPage.attachPaper().size()); + } + + @Test + public void deletePaper() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + Integer oldCountPapers = grantPage.getAttachedPapers().size(); + if (oldCountPapers == 0) { + oldCountPapers = grantPage.attachPaper().size(); + } + + Assert.assertEquals(oldCountPapers - 1, grantPage.deletePaper().size()); + } } diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index 1754db5..809e22f 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -5,6 +5,8 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.Select; +import java.util.List; + public class GrantPage extends PageObject { @Override public String getSubTitle() { @@ -45,4 +47,40 @@ public class GrantPage extends PageObject { } return false; } + + public List getAttachedPapers() { + try { + return driver.findElement(By.className("div-selected-papers")).findElements(By.tagName("div")); + } catch (Exception ex) { + return null; + } + } + + public List attachPaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + List selectedOptions = select.getAllSelectedOptions(); + List allOptions = select.getOptions(); + if (selectedOptions.size() >= allOptions.size()) { + for (int i = 0; i < allOptions.size(); i++) { + if (!allOptions.get(i).equals(selectedOptions.get(i))) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + return selectedOptions; + } + } + } else { + select.selectByVisibleText(allOptions.get(0).getText()); + selectedOptions.add(allOptions.get(0)); + return selectedOptions; + } + return null; + } + + public List deletePaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + select.deselectByVisibleText(select.getFirstSelectedOption().getText()); + return select.getAllSelectedOptions(); + } }