From bd24525315e5c9f21b1345fde5c92615f8668582 Mon Sep 17 00:00:00 2001 From: ASH Date: Thu, 23 May 2019 00:15:03 +0400 Subject: [PATCH 1/2] #103 integration tests --- src/test/java/IndexTaskTest.java | 214 ++++++++++++++++++ src/test/java/students/TaskPage.java | 81 +++++++ .../java/students/TasksDashboardPage.java | 10 + src/test/java/students/TasksPage.java | 75 ++++++ 4 files changed, 380 insertions(+) create mode 100644 src/test/java/IndexTaskTest.java create mode 100644 src/test/java/students/TaskPage.java create mode 100644 src/test/java/students/TasksDashboardPage.java create mode 100644 src/test/java/students/TasksPage.java diff --git a/src/test/java/IndexTaskTest.java b/src/test/java/IndexTaskTest.java new file mode 100644 index 0000000..51b5e07 --- /dev/null +++ b/src/test/java/IndexTaskTest.java @@ -0,0 +1,214 @@ +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; +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 ru.ulstu.NgTrackerApplication; +import ru.ulstu.configuration.ApplicationProperties; +import students.TaskPage; +import students.TasksDashboardPage; +import students.TasksPage; + +import java.util.Arrays; +import java.util.Date; +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 IndexTaskTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new TasksPage(), Arrays.asList("Список задач", "/students/tasks"), + new TasksDashboardPage(), Arrays.asList("Панель управления", "/students/dashboard"), + new TaskPage(), Arrays.asList("Создать задачу", "/students/task?id=0") + ); + + private final String TAG = "ATag"; + + @Autowired + private ApplicationProperties applicationProperties; + + + @Test + public void testACreateTask() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 2); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + + TaskPage taskPage = (TaskPage) getContext().initPage(page.getKey()); + TasksPage tasksPage = (TasksPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + String taskName = "Task " + (new Date()).getTime(); + + taskPage.setName(taskName); + taskPage.addDeadlineDate("01.01.2020", 0); + taskPage.addDeadlineDescription("Description", 0); + taskPage.save(); + + Assert.assertTrue(tasksPage.findTask(taskName)); + } + + @Test + public void testBEditTaskName() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); + TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); + String taskNewName = "Task " + (new Date()).getTime(); + + tasksPage.goToFirstTask(); + taskPage.removeName(); + taskPage.setName(taskNewName); + taskPage.save(); + + Assert.assertTrue(tasksPage.findTask(taskNewName)); + } + + @Test + public void testCDeleteTask() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); + + Integer size = tasksPage.getTasks().size(); + tasksPage.deleteFirstTask(); + Thread.sleep(3000); + tasksPage.submit(); + + Assert.assertEquals(size - 1, tasksPage.getTasks().size()); + } + + @Test + public void testDAddDeadline() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); + TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); + + tasksPage.goToFirstTask(); + String taskId = taskPage.getId(); + Integer deadnum = taskPage.getDeadNum(); + + String descr = "Description"; + String date = "06.06.2019"; + String dateValue = "2019-06-06"; + + taskPage.clickAddDeadline(); + taskPage.addDeadlineDescription(descr, deadnum); + taskPage.addDeadlineDate(date, deadnum); + taskPage.save(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId)); + + Assert.assertTrue(taskPage.hasDeadline(descr, dateValue)); + } + + @Test + public void testEEditDeadline() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); + TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); + + tasksPage.goToFirstTask(); + String taskId = taskPage.getId(); + + String descr = "DescriptionTwo"; + String date = "12.12.2019"; + String dateValue = "2019-12-12"; + + taskPage.clearDeadlineDate(0); + taskPage.clearDeadlineDescription(0); + taskPage.addDeadlineDescription(descr, 0); + taskPage.addDeadlineDate(date, 0); + taskPage.save(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId)); + + Assert.assertTrue(taskPage.hasDeadline(descr, dateValue)); + } + + @Test + public void testFDeleteDeadline() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); + TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey()); + + tasksPage.goToFirstTask(); + String taskId = taskPage.getId(); + Integer deadNum = taskPage.getDeadNum(); + + taskPage.deleteDeadline(); + taskPage.save(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId)); + + Assert.assertEquals(deadNum - 1, (int) taskPage.getDeadNum()); + } + + @Test + public void testGCreateTaskWithTag() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 2); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + + TaskPage taskPage = (TaskPage) getContext().initPage(page.getKey()); + TasksPage tasksPage = (TasksPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + String taskName = "Task " + (new Date()).getTime(); + + taskPage.setName(taskName); + taskPage.setTag(TAG); + Thread.sleep(1000); + taskPage.addDeadlineDate("01.01.2020", 0); + taskPage.addDeadlineDescription("Description", 0); + taskPage.save(); + + Assert.assertTrue(tasksPage.findTaskByTag(taskName, TAG)); + } + + @Test + public void testHFindTagInFilter() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); + + + Assert.assertTrue(tasksPage.findTag(TAG)); + } + + @Test + public void testIFilterByTag() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); + tasksPage.selectTag(TAG); + + Assert.assertTrue(tasksPage.findTasksByTag(TAG)); + } + + @Test + public void testJFilterByStatus() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey()); + + tasksPage.selectStatus(); + Assert.assertTrue(tasksPage.findAllStatus()); + } + + +} diff --git a/src/test/java/students/TaskPage.java b/src/test/java/students/TaskPage.java new file mode 100644 index 0000000..c0105b2 --- /dev/null +++ b/src/test/java/students/TaskPage.java @@ -0,0 +1,81 @@ +package students; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class TaskPage extends PageObject { + + @Override + public String getSubTitle() { + return driver.findElement(By.tagName("h3")).getText(); + } + + public void setName(String name) { + driver.findElement(By.id("title")).sendKeys(name); + } + + public void save() { + driver.findElement(By.id("sendMessageButton")).click(); + } + + public void addDeadlineDate(String deadDate, Integer deadNum) { + driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(deadDate); + } + + public void addDeadlineDescription(String deadDescr, Integer deadNum) { + driver.findElement(By.id(String.format("deadlines%d.description", deadNum))).sendKeys(deadDescr); + } + + public void removeName() { + driver.findElement(By.id("title")).clear(); + } + + public String getId() { + return driver.findElement(By.id("id")).getAttribute("value"); + } + + public Integer getDeadNum() { + return driver.findElements(By.cssSelector("#task-form .form-group:nth-of-type(5) .row")).size(); + } + + public void clickAddDeadline() { + driver.findElement(By.cssSelector("#addDeadline")).click(); + } + + public List getDeadlines() { + return driver.findElements(By.cssSelector(".form-group:nth-of-type(5) .row")); + } + + public void deleteDeadline() { + driver.findElement(By.xpath("//*[@id=\"task-form\"]/div/div[1]/div[5]/div[1]/div[3]/a")).click(); + + } + + public void clearDeadlineDate(Integer deadNum) { + driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(Keys.DELETE); + } + + public void clearDeadlineDescription(Integer deadNum) { + driver.findElement(By.id(String.format("deadlines%d.description", deadNum))).clear(); + } + + public boolean hasDeadline(String deadDescr, String deadValue) { + return getDeadlines() + .stream() + .anyMatch(webElement -> { + return webElement.findElement(By.cssSelector("input[type=\"text\"]")).getAttribute("value").equals(deadDescr) + && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(deadValue); + }); + } + + public void setTag(String tag) { + driver.findElement(By.className("input-tag-name")).sendKeys(tag); + driver.findElement(By.className("input-tag-name")).sendKeys(Keys.ENTER); + } + + +} diff --git a/src/test/java/students/TasksDashboardPage.java b/src/test/java/students/TasksDashboardPage.java new file mode 100644 index 0000000..8cc6eda --- /dev/null +++ b/src/test/java/students/TasksDashboardPage.java @@ -0,0 +1,10 @@ +package students; + +import core.PageObject; + +public class TasksDashboardPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} diff --git a/src/test/java/students/TasksPage.java b/src/test/java/students/TasksPage.java new file mode 100644 index 0000000..5c5d42c --- /dev/null +++ b/src/test/java/students/TasksPage.java @@ -0,0 +1,75 @@ +package students; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class TasksPage extends PageObject { + + @Override + public String getSubTitle() { + return driver.findElement(By.tagName("h3")).getText(); + } + + public List getTasks() { + return driver.findElements(By.cssSelector("span.h6")); + } + + public List getTaskRows() { + return driver.findElements(By.className("task-row")); + } + + public void goToFirstTask() { + driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[1]/div/div/a[1]")).click(); + } + + public boolean findTask(String taskName) { + return getTasks().stream() + .anyMatch(webElement -> webElement.getText().equals(taskName)); + + } + + public void deleteFirstTask() { + js.executeScript("$('a[data-confirm]').click();"); + } + + public void submit() { + driver.findElement(By.xpath("//*[@id=\"dataConfirmOK\"]")).click(); + } + + public boolean findTag(String tag) { + driver.findElements(By.className("bootstrap-select")).get(2).findElement(By.className("btn")).click(); + driver.findElement(By.cssSelector(".bs-searchbox input")).sendKeys(tag); + return driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[2]/div/div[2]/ul")).findElement(By.className("text")).getText().equals(tag); + } + + public boolean findTaskByTag(String name, String tag) { + return getTasks().stream() + .anyMatch(webElement -> webElement.getText().equals(name) + && webElement.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[1]/div/div/a[1]/span[3]")).getText().equals(tag)); + } + + public boolean findTasksByTag(String tag) { + return getTaskRows().stream() + .allMatch(webElement -> webElement.findElement(By.cssSelector("span.text-muted")).getText().equals(tag)); + } + + public void selectTag(String tag) { + driver.findElements(By.className("bootstrap-select")).get(2).findElement(By.className("btn")).click(); + driver.findElement(By.cssSelector(".bs-searchbox input")).sendKeys(tag); + driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[2]/div/div[2]/ul/li/a")).click(); + } + + + public void selectStatus() { + driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click(); + driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[1]/div/div/ul/li[2]/a")).click(); + } + + public boolean findAllStatus() { + return getTaskRows().stream() + .allMatch(webElement -> webElement.findElement(By.cssSelector("div i.text-primary")).isDisplayed()); + } +} From 1c8359f900fef08760ad9dc30aaec1103fc867e3 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 23 May 2019 13:54:44 +0400 Subject: [PATCH 2/2] #103 modify files permissions --- src/main/resources/drivers/chromedriver | Bin src/main/resources/drivers/geckodriver | Bin 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/main/resources/drivers/chromedriver mode change 100644 => 100755 src/main/resources/drivers/geckodriver diff --git a/src/main/resources/drivers/chromedriver b/src/main/resources/drivers/chromedriver old mode 100644 new mode 100755 diff --git a/src/main/resources/drivers/geckodriver b/src/main/resources/drivers/geckodriver old mode 100644 new mode 100755