From 9388302a47c9548eb6fa4055c11f7ce6fc9cade4 Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Fri, 31 May 2019 01:08:40 +0400 Subject: [PATCH] #101 project tests --- src/main/resources/templates/index.html | 2 +- src/test/java/ProjectTest.java | 137 ++++++++++++++++++ src/test/java/project/ProjectPage.java | 52 +++++-- src/test/java/project/ProjectsPage.java | 4 +- .../project/service/ProjectServiceTest.java | 1 + 5 files changed, 184 insertions(+), 12 deletions(-) create mode 100644 src/test/java/ru/ulstu/project/service/ProjectServiceTest.java diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 6bb134e..f821549 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -40,7 +40,7 @@
- +
diff --git a/src/test/java/ProjectTest.java b/src/test/java/ProjectTest.java index 5791b07..f2c6367 100644 --- a/src/test/java/ProjectTest.java +++ b/src/test/java/ProjectTest.java @@ -1,6 +1,8 @@ import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; import core.PageObject; import core.TestTemplate; +import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,6 +17,7 @@ import ru.ulstu.NgTrackerApplication; import ru.ulstu.configuration.ApplicationProperties; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; @@ -33,5 +36,139 @@ public class ProjectTest extends TestTemplate { @Test public void testACreateNewProject() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(page.getKey()); + ProjectPage projectPage = (ProjectPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + String name = "Project " + (new Date()).getTime(); + String date = "01.01.2019"; + Integer deadNum = projectPage.getDeadlineCount(); + projectPage.setName(name); + projectPage.clickAddDeadline(); + projectPage.addDeadlineDate(date, deadNum); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testBChangeNameAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = "Project " + (new Date()).getTime(); + projectPage.clearName(); + projectPage.setName(name); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testCChangeDeadlineAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + String date = "01.01.2019"; + Integer deadNum = projectPage.getDeadlineCount(); + projectPage.addDeadlineDate(date, deadNum); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testDSetStatusAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + projectPage.setStatus(); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testEAddDescriptionAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + String description = "Description " + (new Date()).getTime(); + projectPage.addDescription(description); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testFAddLinkAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + String link = "Link " + (new Date()).getTime(); + projectPage.addLink(link); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testGAddDeadlineDescriptionAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + String deadDesc = "Description " + (new Date()).getTime(); + projectPage.addDeadlineDescription(deadDesc); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testHSetDeadlineCompletionAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + projectPage.setDeadlineCompletion(); + projectPage.clickSave(); + Assert.assertTrue(projectsPage.checkNameInList(name)); + } + + @Test + public void testIDeleteDeadline() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + projectPage.clickDeleteDeadline(); + Assert.assertTrue(projectPage.getDeadlineCount() == 0); + } + + @Test + public void testJDeleteProject() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey()); + ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + projectsPage.getFirstProject(); + String name = projectPage.getName(); + projectPage.clickSave(); + projectsPage.deleteFirst(); + projectsPage.clickConfirm(); + Assert.assertFalse(projectsPage.checkNameInList(name)); } } diff --git a/src/test/java/project/ProjectPage.java b/src/test/java/project/ProjectPage.java index b392099..1bbad67 100644 --- a/src/test/java/project/ProjectPage.java +++ b/src/test/java/project/ProjectPage.java @@ -28,14 +28,43 @@ public class ProjectPage extends PageObject { driver.findElement(By.id("title")).clear(); } - public void clickSaveBut() { - driver.findElement(By.id("send-message-button")).click(); + public void clickSave() { + driver.findElement(By.id("sendMessageButton")).click(); } - public void clickAddDeadlineBut() { + public void clickAddDeadline() { driver.findElement(By.id("addDeadline")).click(); } + public void addDeadlineDate(String deadDate, Integer deadNum) { + driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(deadDate); + } + + public void addDeadlineDescription(String description) { + driver.findElement(By.id("deadlines0.description")).sendKeys(description); + } + + public void setDeadlineCompletion() { + driver.findElement(By.id("deadlines0.done1")).click(); + } + + public void setStatus() { + driver.findElement(By.id("status")).click(); + getFirstStatus(); + } + + public void getFirstStatus() { + driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click(); + } + + public void addDescription(String description) { + driver.findElement(By.id("description")).sendKeys(description); + } + + public void addLink(String link) { + driver.findElement(By.id("repository")).sendKeys(link); + } + public List getDeadlineList() { return driver.findElements(By.className("deadline")); } @@ -44,6 +73,15 @@ public class ProjectPage extends PageObject { return driver.findElements(By.className("deadline")).size(); } + public void setExecutors() { + driver.findElement(By.id("status")).click(); + getFirstExecutor(); + } + + public void getFirstExecutor() { + driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click(); + } + public void setDeadlineDescription(String description, Integer i) { driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); } @@ -52,10 +90,6 @@ public class ProjectPage extends PageObject { driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); } - public void clickTakePartBut() { - driver.findElement(By.id("take-part")).click(); - } - public Boolean isTakePartButDisabledValueTrue() { return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true"); } @@ -64,8 +98,8 @@ public class ProjectPage extends PageObject { return driver.findElements(By.className("member")).size(); } - public void clickDeleteDeadlineBut() { - driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).click(); + public void clickDeleteDeadline() { + driver.findElement(By.className("btn-danger")).click(); } public void showAllowToAttachArticles() { diff --git a/src/test/java/project/ProjectsPage.java b/src/test/java/project/ProjectsPage.java index f0cc4a1..64c50b7 100644 --- a/src/test/java/project/ProjectsPage.java +++ b/src/test/java/project/ProjectsPage.java @@ -26,11 +26,11 @@ public class ProjectsPage extends PageObject { } public void deleteFirst() { - js.executeScript("$('input[data-confirm]').click();"); + js.executeScript("$('a[data-confirm]').click();"); } public void clickConfirm() { - driver.findElement(By.id("deleteProject")).click(); + driver.findElement(By.id("dataConfirmOK")).click(); } public boolean checkNameInList(String newProjectName) { diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java new file mode 100644 index 0000000..1f2debe --- /dev/null +++ b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java @@ -0,0 +1 @@ +package ru.ulstu.project.service; \ No newline at end of file