From 4498b712595a72b8ff82799f5f4dc0c737b72abd Mon Sep 17 00:00:00 2001 From: "a.vasin" Date: Thu, 30 May 2019 09:53:27 +0400 Subject: [PATCH] #101 project tests --- src/test/java/ProjectTest.java | 37 +++++++ src/test/java/project/ProjectDashboard.java | 11 ++ src/test/java/project/ProjectPage.java | 107 ++++++++++++++++++++ src/test/java/project/ProjectsPage.java | 41 ++++++++ 4 files changed, 196 insertions(+) create mode 100644 src/test/java/ProjectTest.java create mode 100644 src/test/java/project/ProjectDashboard.java create mode 100644 src/test/java/project/ProjectPage.java create mode 100644 src/test/java/project/ProjectsPage.java diff --git a/src/test/java/ProjectTest.java b/src/test/java/ProjectTest.java new file mode 100644 index 0000000..5791b07 --- /dev/null +++ b/src/test/java/ProjectTest.java @@ -0,0 +1,37 @@ +import com.google.common.collect.ImmutableMap; +import core.PageObject; +import core.TestTemplate; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import project.ProjectDashboard; +import project.ProjectPage; +import project.ProjectsPage; +import ru.ulstu.NgTrackerApplication; +import ru.ulstu.configuration.ApplicationProperties; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@RunWith(SpringRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class ProjectTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new ProjectPage(), Arrays.asList("ПРОЕКТЫ", "/projects/projects"), + new ProjectsPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ПРОЕКТА", "/projects/project?id=0"), + new ProjectDashboard(), Arrays.asList("ПРОЕКТЫ", "/projects/dashboard") + ); + + @Autowired + private ApplicationProperties applicationProperties; + + @Test + public void testACreateNewProject() { + } +} diff --git a/src/test/java/project/ProjectDashboard.java b/src/test/java/project/ProjectDashboard.java new file mode 100644 index 0000000..0b36204 --- /dev/null +++ b/src/test/java/project/ProjectDashboard.java @@ -0,0 +1,11 @@ +package project; + +import core.PageObject; +import org.openqa.selenium.By; + +public class ProjectDashboard extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h2")).getText(); + } +} diff --git a/src/test/java/project/ProjectPage.java b/src/test/java/project/ProjectPage.java new file mode 100644 index 0000000..b392099 --- /dev/null +++ b/src/test/java/project/ProjectPage.java @@ -0,0 +1,107 @@ +package project; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class ProjectPage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h3")).getText(); + } + + public String getId() { + return driver.findElement(By.id("id")).getAttribute("value"); + } + + public void setName(String name) { + driver.findElement(By.id("title")).sendKeys(name); + } + + public String getName() { + return driver.findElement(By.id("title")).getAttribute("value"); + } + + public void clearName() { + driver.findElement(By.id("title")).clear(); + } + + public void clickSaveBut() { + driver.findElement(By.id("send-message-button")).click(); + } + + public void clickAddDeadlineBut() { + driver.findElement(By.id("addDeadline")).click(); + } + + public List getDeadlineList() { + return driver.findElements(By.className("deadline")); + } + + public Integer getDeadlineCount() { + return driver.findElements(By.className("deadline")).size(); + } + + public void setDeadlineDescription(String description, Integer i) { + driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); + } + + public void setDeadlineDate(String date, Integer i) { + 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"); + } + + public Integer getMemberCount() { + return driver.findElements(By.className("member")).size(); + } + + public void clickDeleteDeadlineBut() { + driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).click(); + } + + public void showAllowToAttachArticles() { + driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click(); + } + + public void clickAddPaperBut() { + driver.findElement(By.id("add-paper")).click(); + } + + + public List getArticles() { + return driver.findElements(By.className("paper")); + } + + public Integer getArticlesCount() { + return driver.findElements(By.className("paper")).size(); + } + + public WebElement selectArticle() { + WebElement webElement = driver.findElement(By.xpath("//*[@id=\"project-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a")); + webElement.click(); + return webElement; + } + + public void clickUndockArticleBut() { + driver.findElement(By.name("removePaper")).click(); + } + + public boolean checkDeadline(String description, String dateValue) { + return getDeadlineList() + .stream() + .anyMatch(webElement -> { + return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description) + && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); + }); + } + +} \ No newline at end of file diff --git a/src/test/java/project/ProjectsPage.java b/src/test/java/project/ProjectsPage.java new file mode 100644 index 0000000..f0cc4a1 --- /dev/null +++ b/src/test/java/project/ProjectsPage.java @@ -0,0 +1,41 @@ +package project; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class ProjectsPage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h2")).getText(); + } + + public List getProjectsList() { + return driver.findElements(By.cssSelector("span.h6")); + } + + public void getFirstProject() { + driver.findElement(By.xpath("//*[@id=\"projects\"]/div/div[2]/div[1]/div[1]/div/a")).click(); + } + + public void selectMember() { + driver.findElements(By.className("bootstrap-select")).get(0).findElement(By.className("btn")).click(); + driver.findElements(By.className("bootstrap-select")).get(0).findElements(By.className("dropdown-item")).get(1).click(); + } + + public void deleteFirst() { + js.executeScript("$('input[data-confirm]').click();"); + } + + public void clickConfirm() { + driver.findElement(By.id("deleteProject")).click(); + } + + public boolean checkNameInList(String newProjectName) { + return getProjectsList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(newProjectName)); + } +} \ No newline at end of file